Commit 659366fb authored by Bonnegent Sebastien's avatar Bonnegent Sebastien
Browse files

fix(ubiquity): group key

parent 788e789c
Pipeline #12199 passed with stages
in 20 seconds
......@@ -5,15 +5,18 @@ title: Django par la pratique 3/7
lang: fr
---
# Départ
## Lancement
https://gitlab.insa-rouen.fr/bonnegent/cours_django/-/blob/master/cours3.md
## Pour démarrer
http://bonnegent.pages.insa-rouen.fr/cours_django/
~~~bash
$ git pull
$ cd fwm3
$ python ./manage.gy migrate
$ cp fwm3 fwm3-tmp
$ cd fwm3-tmp
~~~
Ou utilisation de Ubiquity:
c7f2f4a1c13a46b80da66a8ed8274f08
## Au programme
- suite des modèles avec relations
- Parefeu
......@@ -35,7 +38,7 @@ $ python ./manage.gy migrate
- DO_NOTHING
- ...
[^on_delete]: https://docs.djangoproject.com/fr/2.2/ref/models/fields/
[^on_delete]: https://docs.djangoproject.com/fr/3.1/ref/models/fields/
# Parefeu
## À modifier
......@@ -95,8 +98,8 @@ class Regle(models.Model):
## Activation
~~~bash
$ python ./manage.py makemigrations
$ python ./manage.py migrate
$ python3 ./manage.py makemigrations
$ python3 ./manage.py migrate
~~~
# Administration
......@@ -254,6 +257,8 @@ urlpatterns = [
## Mise en forme
### Installation
Si vous n'avez pas utilisé le fichier: requirements-3.X.txt
~~~bash
$ pipenv install django-bootstrap-static fontawesome
~~~
......
......@@ -41,8 +41,10 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'webui',
'django_extensions',
# @u:start installed_apps
'bootstrap',
'fontawesome',
# @u:end installed_apps
]
MIDDLEWARE = [
......
......@@ -15,10 +15,14 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
# @u:start import_views
from webui import views
# @u:end import_views
urlpatterns = [
path('admin/', admin.site.urls),
# @u:start home
path('', views.home_v2, name='home'),
# @u:end home
path('accounts/', include('django.contrib.auth.urls')),
]
......@@ -30,7 +30,7 @@ class GroupeAdmin(admin.ModelAdmin):
admin.site.register(Groupe, GroupeAdmin)
# @u:start parefeu_admin
class ParefeuAdmin(admin.ModelAdmin):
list_display = ("nom", "modele",
"nombre_de_regles", "modification")
......@@ -38,10 +38,12 @@ class ParefeuAdmin(admin.ModelAdmin):
admin.site.register(Parefeu, ParefeuAdmin)
# @u:end parefeu_admin
# @u:start regle_admin
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
from django.contrib.auth.models import User
# @u:end import
PROTO = (('a', 'any'), ('t', 'tcp'), ('u', 'udp'), ('i', 'icmp'))
......@@ -65,7 +67,7 @@ class Groupe(AvecNom):
def liste_des_adresses(self):
return ", ".join([str(a) for a in self.adresses.all()])
# @u:start parefeu
class Parefeu(AvecNom):
# mise à jour auto à chaque save()
modification = models.DateTimeField(auto_now=True)
......@@ -75,15 +77,19 @@ class Parefeu(AvecNom):
class Meta(object):
verbose_name_plural = "parefeux"
# @u:end parefeu
# @u:start nbregles
def nombre_de_regles(self):
nb = self.regle_set.count()
if self.modele:
nb += self.modele.nombre_de_regles()
return nb
# @u:end nbregles
SENS = (("i", "Input"), ("f", "Forward"), ("o", "Output"))
# @u:start regle
SENS = (("i", "Input"), ("f", "Forward"), ("o", "Output"))
class Regle(models.Model):
priorite = models.PositiveIntegerField(default=0)
......@@ -96,10 +102,14 @@ 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
class Meta(object):
ordering = ("parefeu", "priorite", "groupe")
# @u:end regle_meta
# @u:start regle_services
def liste_des_services(self):
return ", ".join([str(s) for s in self.services.all()])
# @u:end regle_services
......@@ -7,7 +7,7 @@
<script defer src="{% static 'fontawesome/js/all.min.js' %}"></script>
</head>
<body>
<!-- @u:start menu -->
<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">
......@@ -41,6 +41,7 @@
{% 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
from django.http import HttpResponse
# @u:end httpresponse
# @u:start home_v1
def home_v1(request):
return HttpResponse('ça marche !')
# @u:end home_v1
def home_v2(request):
return render(request, 'webui/home.html', {})
Markdown is supported
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