Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bonnegent Sebastien
cours_django
Commits
659366fb
Commit
659366fb
authored
Nov 23, 2021
by
Bonnegent Sebastien
Browse files
fix(ubiquity): group key
parent
788e789c
Pipeline
#12199
passed with stages
in 20 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cours3.md
View file @
659366fb
...
...
@@ -5,15 +5,18 @@ title: Django par la pratique 3/7
lang
:
fr
---
# Départ
##
Lancement
http
s
://
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
$
c
d
fwm3
$
python ./manage.gy migrate
$
c
p
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
$
python
3
./manage.py makemigrations
$
python
3
./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
~~~
...
...
fwm4/conf/settings.py
View file @
659366fb
...
...
@@ -41,8 +41,10 @@ INSTALLED_APPS = [
'django.contrib.staticfiles'
,
'webui'
,
'django_extensions'
,
# @u:start installed_apps
'bootstrap'
,
'fontawesome'
,
# @u:end installed_apps
]
MIDDLEWARE
=
[
...
...
fwm4/conf/urls.py
View file @
659366fb
...
...
@@ -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'
)),
]
fwm4/webui/admin.py
View file @
659366fb
...
...
@@ -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
fwm4/webui/models.py
View file @
659366fb
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
fwm4/webui/templates/webui/home.html
View file @
659366fb
...
...
@@ -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>
...
...
fwm4/webui/views.py
View file @
659366fb
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'
,
{})
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment