Use UUID for teacher creation
This commit is contained in:
parent
63b67e9a9a
commit
2d14beb303
13 changed files with 82 additions and 165 deletions
1
Pipfile
1
Pipfile
|
@ -14,6 +14,7 @@ dj-database-url = "*"
|
||||||
"psycopg2-binary" = "*"
|
"psycopg2-binary" = "*"
|
||||||
django-dotenv = "*"
|
django-dotenv = "*"
|
||||||
django-mailgun = "*"
|
django-mailgun = "*"
|
||||||
|
uuid = "*"
|
||||||
|
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
9
Pipfile.lock
generated
9
Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "71138c05585bbfa9cc69ef80bb089989c24abf0c550ba909ce2ef8b7fbe5d0f2"
|
"sha256": "43a1e1084af30da4a5ce423a0086c023152fb78a989cf7425035ea6d2a02fd0e"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -143,6 +143,13 @@
|
||||||
"sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f"
|
"sha256:cc44da8e1145637334317feebd728bd869a35285b93cbb4cca2577da7e62db4f"
|
||||||
],
|
],
|
||||||
"version": "==1.22"
|
"version": "==1.22"
|
||||||
|
},
|
||||||
|
"uuid": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:1f87cc004ac5120466f36c5beae48b4c48cc411968eed0eaecd3da82aa96193f"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==1.30"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"develop": {
|
"develop": {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 19:16
|
# Generated by Django 2.0.5 on 2018-05-21 21:21
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import manuels.models
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
@ -12,12 +15,56 @@ class Migration(migrations.Migration):
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='Teacher',
|
name='Book',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
('first_name', models.CharField(max_length=100)),
|
('field', models.CharField(max_length=100, verbose_name='matière')),
|
||||||
('last_name', models.CharField(max_length=100)),
|
('title', models.TextField(verbose_name='titre')),
|
||||||
('phone_number', models.CharField(max_length=10)),
|
('authors', models.TextField(verbose_name='auteurs')),
|
||||||
|
('editor', models.CharField(max_length=200, verbose_name='éditeur')),
|
||||||
|
('collection', models.CharField(blank=True, max_length=200, verbose_name='collection')),
|
||||||
|
('publication_year', models.PositiveIntegerField(verbose_name='année de publication')),
|
||||||
|
('isbn', models.CharField(max_length=20, validators=[manuels.models.isbn_validator], verbose_name='ISBN/EAN')),
|
||||||
|
('price', models.PositiveIntegerField(verbose_name='prix')),
|
||||||
|
('previously_acquired', models.BooleanField(choices=[(True, 'Oui'), (False, 'Non')], verbose_name="manuel acquis précédemment par l'élève")),
|
||||||
],
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'livre',
|
||||||
|
'verbose_name_plural': 'livres',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Level',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=10, verbose_name='nom')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'classe',
|
||||||
|
'verbose_name_plural': 'classes',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Teacher',
|
||||||
|
fields=[
|
||||||
|
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||||
|
('first_name', models.CharField(max_length=100, verbose_name='prénom')),
|
||||||
|
('last_name', models.CharField(max_length=100, verbose_name='nom')),
|
||||||
|
('phone_number', models.CharField(max_length=10, verbose_name='numéro de téléphone')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'enseignant',
|
||||||
|
'verbose_name_plural': 'enseignants',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='book',
|
||||||
|
name='level',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Level', verbose_name='classe'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='book',
|
||||||
|
name='teacher',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Teacher', verbose_name='enseignant'),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 19:54
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
import manuels.models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('manuels', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Book',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('field', models.CharField(max_length=100, verbose_name='matière')),
|
|
||||||
('title', models.TextField(verbose_name='titre')),
|
|
||||||
('authors', models.TextField(verbose_name='auteurs')),
|
|
||||||
('editor', models.CharField(max_length=200, verbose_name='éditeur')),
|
|
||||||
('collection', models.CharField(blank=True, max_length=200, verbose_name='collection')),
|
|
||||||
('publication_year', models.PositiveIntegerField(verbose_name='année de publication')),
|
|
||||||
('isbn', models.TextField(validators=[manuels.models.isbn_validator], verbose_name='ISBN/EAN')),
|
|
||||||
('price', models.PositiveIntegerField(verbose_name='prix')),
|
|
||||||
('previously_acquired', models.BooleanField(verbose_name="manuel acquis précédemment par l'élève")),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'livre',
|
|
||||||
'verbose_name_plural': 'livres',
|
|
||||||
},
|
|
||||||
),
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Level',
|
|
||||||
fields=[
|
|
||||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('name', models.CharField(max_length=10, verbose_name='nom')),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
'verbose_name': 'classe',
|
|
||||||
'verbose_name_plural': 'classe',
|
|
||||||
},
|
|
||||||
),
|
|
||||||
migrations.AlterModelOptions(
|
|
||||||
name='teacher',
|
|
||||||
options={'verbose_name': 'enseignant', 'verbose_name_plural': 'enseignants'},
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='teacher',
|
|
||||||
name='first_name',
|
|
||||||
field=models.CharField(max_length=100, verbose_name='prénom'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='teacher',
|
|
||||||
name='last_name',
|
|
||||||
field=models.CharField(max_length=100, verbose_name='nom'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='teacher',
|
|
||||||
name='phone_number',
|
|
||||||
field=models.CharField(max_length=10, verbose_name='numéro de téléphone'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='book',
|
|
||||||
name='level',
|
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Level'),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='book',
|
|
||||||
name='teacher',
|
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Teacher'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,24 +0,0 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 20:25
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('manuels', '0002_auto_20180521_2154'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='book',
|
|
||||||
name='level',
|
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Level', verbose_name='classe'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='book',
|
|
||||||
name='teacher',
|
|
||||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='manuels.Teacher', verbose_name='enseignant'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,19 +0,0 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 20:26
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import manuels.models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('manuels', '0003_auto_20180521_2225'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='book',
|
|
||||||
name='isbn',
|
|
||||||
field=models.CharField(max_length=20, validators=[manuels.models.isbn_validator], verbose_name='ISBN/EAN'),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,17 +0,0 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 20:30
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('manuels', '0004_auto_20180521_2226'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterModelOptions(
|
|
||||||
name='level',
|
|
||||||
options={'verbose_name': 'classe', 'verbose_name_plural': 'classes'},
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 2.0.5 on 2018-05-21 21:07
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('manuels', '0005_auto_20180521_2230'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='book',
|
|
||||||
name='previously_acquired',
|
|
||||||
field=models.BooleanField(choices=[(True, 'Oui'), (False, 'Non')], verbose_name="manuel acquis précédemment par l'élève"),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,5 +1,6 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import uuid as uuid
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
@ -8,13 +9,14 @@ class Teacher(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = 'enseignant'
|
verbose_name = 'enseignant'
|
||||||
verbose_name_plural = 'enseignants'
|
verbose_name_plural = 'enseignants'
|
||||||
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
first_name = models.CharField('prénom', max_length=100)
|
first_name = models.CharField('prénom', max_length=100)
|
||||||
last_name = models.CharField('nom', max_length=100)
|
last_name = models.CharField('nom', max_length=100)
|
||||||
phone_number = models.CharField('numéro de téléphone', max_length=10)
|
phone_number = models.CharField('numéro de téléphone', max_length=10)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
return reverse('add_book', args=[str(self.id)])
|
return reverse('add_book', args=[str(self.pk)])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def full_name(self):
|
def full_name(self):
|
||||||
|
|
|
@ -5,6 +5,18 @@
|
||||||
{% block title %}Accueil{% endblock %}
|
{% block title %}Accueil{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12">
|
||||||
|
<h1>Bienvenue !</h1>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="alert alert-info" role="alert">
|
||||||
|
<h4 class="alert-heading">Bienvenue</h4>
|
||||||
|
<p>Si c'est la première fois que vous visitez ce site, remplissez le formulaire suivant
|
||||||
|
afin de créer votre espace.</p>
|
||||||
|
<p class="mb-0">Sinon, <strong>utilisez le lien qui vous a été fourni</strong> pour voir votre liste
|
||||||
|
et y rajouter des livres.</p>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<form action="" method="post" class="form">
|
<form action="" method="post" class="form">
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<h1>Bienvenue {{ teacher.full_name }}</h1>
|
<h1>Bienvenue {{ teacher.full_name }}</h1>
|
||||||
<h2>{% block title %}Liste des livres demandés{% endblock %}</h2>
|
<h2>{% block title %}Liste des livres demandés{% endblock %}</h2>
|
||||||
<a href="{% url 'add_book' id=teacher.pk %}" class="btn btn-primary">Ajouter un livre</a>
|
<a href="{% url 'add_book' pk=teacher.pk %}" class="btn btn-primary">Ajouter un livre</a>
|
||||||
<table class="table table-hover table-sm">
|
<table class="table table-hover table-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -3,6 +3,6 @@ from django.urls import path
|
||||||
from manuels.views import AddBookView, ListBooksView
|
from manuels.views import AddBookView, ListBooksView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('teacher/<int:id>/add', AddBookView.as_view(), name='add_book'),
|
path('teacher/<uuid:pk>/add', AddBookView.as_view(), name='add_book'),
|
||||||
path('teacher/<int:id>/', ListBooksView.as_view(), name='list_books'),
|
path('teacher/<uuid:pk>/', ListBooksView.as_view(), name='list_books'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,7 +17,7 @@ class BaseTeacherView:
|
||||||
teacher = None
|
teacher = None
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
self.teacher = get_object_or_404(Teacher, pk=self.kwargs['id'])
|
self.teacher = get_object_or_404(Teacher, pk=self.kwargs['pk'])
|
||||||
return super().dispatch(request, *args, **kwargs)
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -59,6 +59,6 @@ class AddBookView(BaseTeacherView, CreateView):
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
messages.success(self.request, f'"{self.object}" a été ajouté.')
|
messages.success(self.request, f'"{self.object}" a été ajouté.')
|
||||||
if self.add_another:
|
if self.add_another:
|
||||||
return reverse('add_book', args=[str(self.teacher.id)])
|
return reverse('add_book', args=[str(self.teacher.pk)])
|
||||||
else:
|
else:
|
||||||
return reverse('list_books', args=[str(self.teacher.id)])
|
return reverse('list_books', args=[str(self.teacher.pk)])
|
||||||
|
|
Loading…
Reference in a new issue