Commit 090afa96 authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

cours 4 ok

parent a0bb980c
Pipeline #12458 passed with stages
in 19 seconds
......@@ -5,3 +5,4 @@ fwm?/Pipfile
fwm?/Pipfile.lock
fwm?-tmp/
env
__pycache__
......@@ -11,11 +11,11 @@ http://bonnegent.pages.insa-rouen.fr/cours_django/
~~~bash
$ git pull
$ cp fwm3 fwm3-tmp
$ cd fwm3-tmp
$ cd !$
~~~
Ou utilisation de Ubiquity:
f2e1283f64f5af62f3fee736726c3577
ce2afbcb398671f19c2d1738cb9e92a3
## Au programme
- suite des modèles avec relations
......
......@@ -5,15 +5,18 @@ title: Django par la pratique 4/7
lang: fr
---
# Départ
## Lancement
https://gitlab.insa-rouen.fr/bonnegent/cours_django/-/blob/master/cours4.md
## Pour démarrer
http://bonnegent.pages.insa-rouen.fr/cours_django/
~~~bash
$ git pull
$ cd fwm4
$ python ./manage.py migrate
$ cp fwm4 fwm4-tmp
$ cd !$
~~~
Ou utilisation de Ubiquity:
e96c8189bcd92ea269282d9c64f21f3a
## Au programme
- rappel sur les fichiers
- authentification, limitation d'accès
......@@ -237,8 +240,8 @@ SERVER_EMAIL = 'noreply@insa-rouen.fr'
### un faux serveur smtp
~~~bash
$ python ./manage.py help mail_debug
$ python ./manage.py mail_debug --use-settings
$ python3 ./manage.py help mail_debug
$ python3 ./manage.py mail_debug --use-settings
~~~
# Formulaire simple
......
......@@ -41,11 +41,8 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'webui',
'django_extensions',
# @u:start installed_apps
# @u:Keywords bootstrap fontawesome
'bootstrap',
'fontawesome',
# @u:end installed_apps
]
MIDDLEWARE = [
......
......@@ -15,16 +15,10 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
# @u:start import_views
# @u:Keywords webui views
from webui import views
# @u:end import_views
urlpatterns = [
path('admin/', admin.site.urls),
# @u:start home
# @u:Keywords home home_v2
path('', views.home_v2, name='home'),
# @u:end home
path('accounts/', include('django.contrib.auth.urls')),
]
from django.contrib import admin
from .models import Adresse, Port, Service, Groupe
# @u:start import
# @u:Keywords Parefeu Regle
from .models import Parefeu, Regle
# @u:end import
class AdresseAdmin(admin.ModelAdmin):
......@@ -34,8 +31,6 @@ class GroupeAdmin(admin.ModelAdmin):
admin.site.register(Groupe, GroupeAdmin)
# @u:start parefeu_admin
# @u:Keywords ParefeuAdmin list_display date_hierarchy nombre_de_regles
class ParefeuAdmin(admin.ModelAdmin):
list_display = ("nom", "modele",
"nombre_de_regles", "modification")
......@@ -43,13 +38,9 @@ class ParefeuAdmin(admin.ModelAdmin):
admin.site.register(Parefeu, ParefeuAdmin)
# @u:end parefeu_admin
# @u:start regle_admin
# @u:Keywords RegleAdmin list_display liste_des_services
class RegleAdmin(admin.ModelAdmin):
list_display = ("parefeu", "priorite", "groupe", "liste_des_services", "interface", "sens", "actif")
admin.site.register(Regle, RegleAdmin)
# @u:end regle_admin
\ No newline at end of file
from django.db import models
# @u:start import
# @u:Keywords User
from django.contrib.auth.models import User
# @u:end import
PROTO = (('a', 'any'), ('t', 'tcp'), ('u', 'udp'), ('i', 'icmp'))
......@@ -68,9 +65,6 @@ class Groupe(AvecNom):
def liste_des_adresses(self):
return ", ".join([str(a) for a in self.adresses.all()])
# @u:start parefeu
# @u:Keywords Parefeu AvecNom modification modele admin
# @u:KeywordsNotIn nom
class Parefeu(AvecNom):
# mise à jour auto à chaque save()
modification = models.DateTimeField(auto_now=True)
......@@ -80,20 +74,14 @@ class Parefeu(AvecNom):
class Meta(object):
verbose_name_plural = "parefeux"
# @u:end parefeu
# @u:start nbregles
# @u:Keywords nombre_de_regles self.modele.nombre_de_regles count
def nombre_de_regles(self):
nb = self.regle_set.count()
if self.modele:
nb += self.modele.nombre_de_regles()
return nb
# @u:end nbregles
# @u:start regle
# @u:Keywords SENS Regle priorite groupe services interface actif sens parefeu PositiveIntegerField ForeignKey ManyToManyField
SENS = (("i", "Input"), ("f", "Forward"), ("o", "Output"))
class Regle(models.Model):
......@@ -107,16 +95,9 @@ class Regle(models.Model):
sens = models.CharField(max_length=1, choices=SENS,
default="i")
parefeu = models.ForeignKey(Parefeu, on_delete=models.CASCADE)
# @u:end regle
# @u:start regle_meta
# @u:Keywords Meta ordering parefeu priorite
class Meta(object):
ordering = ("parefeu", "priorite", "groupe")
# @u:end regle_meta
# @u:start regle_services
# @u:Keywords liste_des_services self.services.all
def liste_des_services(self):
return ", ".join([str(s) for s in self.services.all()])
# @u:end regle_services
......@@ -7,8 +7,6 @@
<script defer src="{% static 'fontawesome/js/all.min.js' %}"></script>
</head>
<body>
<!-- @u:start menu -->
<!-- @u:Keywords navbar ul Admin Parefeux Services Ports -->
<nav class="navbar navbar-expand-md navbar-dark bg-dark mb-4">
<a class="navbar-brand" href="{% url 'home' %}">WebUI</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
......@@ -42,7 +40,6 @@
{% endif %}
</div>
</nav>
<!-- @u:end menu -->
{% block content %}<p>Bienvenue !</p>{% endblock %}
<script src="{% static 'bootstrap/js/jquery.min.js' %}"></script>
......
from django.shortcuts import render
# @u:start httpresponse
# @u:Keywords HttpResponse
from django.http import HttpResponse
# @u:end httpresponse
# @u:start home_v1
# @u:Keywords home_v1 HttpResponse
def home_v1(request):
return HttpResponse('ça marche !')
# @u:end home_v1
# @u:start home_v2
# @u:Keywords home_v2 render request home.html
def home_v2(request):
return render(request, 'webui/home.html', {})
# @u:end home_v2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment