/edit',
EditCategory.as_view(),
name='category-edit',
),
diff --git a/content/views.py b/content/views.py
index 0548aef..6cee7dd 100644
--- a/content/views.py
+++ b/content/views.py
@@ -8,24 +8,11 @@ from .models import Content, Category
from settings.models import SiteSettings
-class ContentCategoryList(generic.ListView):
- """Affiche les contenus d'une catégorie."""
- model = Content
- context_object_name = "contents"
+class ViewCategory(generic.DetailView):
+ """Affiche une catégorie."""
+ model = Category
template_name = "content/content_list.html"
- def get_queryset(self):
- pk = self.kwargs['pk']
- category = get_object_or_404(Category, pk=pk)
- return Content.objects.filter(category=category)
-
- def get_context_data(self, **kwargs):
- context = super(generic.ListView, self).get_context_data(**kwargs)
- pk = self.kwargs['pk']
- category = get_object_or_404(Category, pk=pk)
- context['category'] = category
- return context
-
class CreateCategory(PermissionRequiredMixin, generic.CreateView):
"""Création de catégorie."""
diff --git a/settings/templates/settings/settings.html b/settings/templates/settings/settings.html
index 4c24c22..06e86d0 100644
--- a/settings/templates/settings/settings.html
+++ b/settings/templates/settings/settings.html
@@ -24,7 +24,7 @@
{{admin.last_name}} |
{{admin.username}} |
-
+
Enlever le privilège Administrateur
@@ -76,26 +76,28 @@
Nom |
- Nombre de membres |
Nombre de contenus |
Nombre de catégories |
Numéro de téléphone |
- |
+ Inscription |
{% for school in schools %}
- {{school.group.name}} |
- {{school.group.user_set.count}} |
+ {{school.name}} |
{{school.content_set.count}} |
{{school.number_of_categories}} |
{{school.phone}} |
-
-
- Éditer
-
-
-
- Supprimer
-
+ |
+ {% if school.validated %}
+
+
+ Inscription validée
+
+ {% else %}
+
+
+ Inscription non validée
+
+ {% endif %}
|
{% endfor %}
@@ -142,9 +144,5 @@
{% endif %}
-
- Nombre minimal de catégories |
- {{ site_settings.min_number_of_categories }} |
-
{% endblock %}
diff --git a/settings/views.py b/settings/views.py
index 6fdfd7c..ab09c6a 100644
--- a/settings/views.py
+++ b/settings/views.py
@@ -1,7 +1,7 @@
from django.views.generic import TemplateView, UpdateView
from django.urls import reverse_lazy, reverse
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
-from django.contrib.auth.decorators import permission_required
+from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.models import Group, User
from django.shortcuts import get_object_or_404, redirect, render
from django.contrib import messages
@@ -22,7 +22,7 @@ class SettingsView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView):
context['site_settings'], _ = SiteSettings.objects.get_or_create()
context['schools'] = School.objects.all()
context['settings'] = True
- context['administrators'] = Group.objects.get(name='admins').user_set.all()
+ context['administrators'] = User.objects.filter(is_staff=True)
return context
class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
@@ -42,24 +42,22 @@ class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateVi
return context
-@permission_required('auth.change_user')
+@staff_member_required
def degrade_user(request, pk):
user = get_object_or_404(User, pk=pk)
- admins,_ = Group.objects.get_or_create(name='admins')
- user.groups.remove(admins)
+ user.is_staff = False
user.save()
messages.success(request, user.username + ' a été enlevé des administrateurs du site')
return redirect(reverse('settings:index'))
-@permission_required('auth.change_user')
+@staff_member_required
def promote_user(request):
user_form = SelectUserForm(request.POST or None)
user_form.populate()
if user_form.is_valid():
user=user_form.get_user()
- admins,_ = Group.objects.get_or_create(name='admins')
- user.groups.add(admins)
+ user.is_staff = True
user.save()
messages.success(request, user.username + ' a été ajouté des administrateurs du site')
return redirect(reverse('settings:index'))
diff --git a/templates/nav_bar.html b/templates/nav_bar.html
index 424cd60..8461033 100644
--- a/templates/nav_bar.html
+++ b/templates/nav_bar.html
@@ -17,14 +17,14 @@
{% for c in categories %}
- {{c.name}}
+ {{c.name}}
{% endfor %}
- {% if request.user.userprofile.school %}
- - Mon école
+ {% if request.user.school %}
+ - Mon école
{% endif %}
- Administration
{% if request.user.is_authenticated %}
@@ -33,7 +33,6 @@
{{request.user}}
diff --git a/users/admin.py b/users/admin.py
index e69de29..109a29e 100644
--- a/users/admin.py
+++ b/users/admin.py
@@ -0,0 +1,6 @@
+from django.contrib import admin
+from .models import School
+
+class SchoolAdmin(admin.ModelAdmin):
+ pass
+admin.site.register(School, SchoolAdmin)
diff --git a/users/forms.py b/users/forms.py
index 8d42501..ac12e8a 100644
--- a/users/forms.py
+++ b/users/forms.py
@@ -6,8 +6,14 @@ from .models import School
class CreateSchool(forms.ModelForm):
class Meta:
- model = User
- fields = '__all__'
+ model = School
+ fields = ['name', 'admin']
+
+
+class EditName(forms.ModelForm):
+ class Meta:
+ model = School
+ fields = ['name']
class CreateUser(forms.ModelForm):
diff --git a/users/migrations/0002_school_validated.py b/users/migrations/0002_school_validated.py
new file mode 100644
index 0000000..afb9316
--- /dev/null
+++ b/users/migrations/0002_school_validated.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.0.1 on 2018-03-09 08:55
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('users', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='school',
+ name='validated',
+ field=models.BooleanField(default=False, verbose_name='Inscription validé.'),
+ ),
+ ]
diff --git a/users/migrations/0003_school_name.py b/users/migrations/0003_school_name.py
new file mode 100644
index 0000000..2015d1f
--- /dev/null
+++ b/users/migrations/0003_school_name.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.0.1 on 2018-03-09 09:07
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('users', '0002_school_validated'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='school',
+ name='name',
+ field=models.CharField(default='', max_length=255, verbose_name="Nom de l'école"),
+ ),
+ ]
diff --git a/users/models.py b/users/models.py
index 253225c..9bc6c4f 100644
--- a/users/models.py
+++ b/users/models.py
@@ -13,6 +13,11 @@ def get_upload_to(instance, filename):
class School(models.Model):
"""Ajoute un champ pour distinguer les groupes écoles des autres."""
+ name = models.CharField(
+ verbose_name="Nom de l'école",
+ max_length=255,
+ default=""
+ )
admin = models.OneToOneField(
User,
verbose_name="Administrateur de l'école",
@@ -83,10 +88,10 @@ class School(models.Model):
def __str__(self):
- return self.group.name
+ return self.name
def get_absolute_url(self):
- return reverse("users:school", kwargs={'pk':self.group.pk})
+ return reverse("users:school", kwargs={'pk':self.pk})
def number_of_categories(self):
return self.content_set.values('category').distinct().count()
diff --git a/users/templates/users/school.html b/users/templates/users/school.html
index 1a3de49..c1ea193 100644
--- a/users/templates/users/school.html
+++ b/users/templates/users/school.html
@@ -2,24 +2,155 @@
{% load bootstrap4 %}
{% block content %}
-{{school.name}}
-{% if manager_right in perms %}
-Numéro de téléphone :
-{% if school.phone %}{{school.phone}}
-{%else%}
-Non indiqué{%endif%}
-{%endif%}
-
+{% if school.validated %}
+
+
+Inscription validée
+
+{% endif %}
+
+ {{school.name}}
+
+
Éditer
+
+
+
+ Numéro de téléphone
+ |
+
+ {% if school.phone %}{{school.phone}}{%else%}
+ Non indiqué{%endif%}
+ |
+
+
+
+ Éditer
+
+ |
+
+
+
+ Email
+ |
+
+ {{school.admin.email}}
+ |
+
+
+
+ Éditer
+
+ |
+
+
+
+ Juré n°1
+ |
+
+
+
+
+ Nom
+ |
+
+ {{school.last_name_j1}}
+ |
+
+
+
+ Prénom
+ |
+
+ {{school.first_name_j1}}
+ |
+
+
+
+ Email
+ |
+
+ {{school.mail_j1}}
+ |
+
+
+
+ N° de téléphone
+ |
+
+ {{school.phone_j1}}
+ |
+
+
+ |
+
+
+
+ Éditer
+
+ |
+
+
+
+ Juré n°2
+ |
+
+
+
+
+ Nom
+ |
+
+ {{school.last_name_j2}}
+ |
+
+
+
+ Prénom
+ |
+
+ {{school.first_name_j2}}
+ |
+
+
+
+ Email
+ |
+
+ {{school.mail_j2}}
+ |
+
+
+
+ N° de téléphone
+ |
+
+ {{school.phone_j2}}
+ |
+
+
+ |
+
+
+
+ Éditer
+
+ |
+
+
+
+
+
+ Valider mon inscription
+
+
Contenus
-{% if manager_right in perms %}
Ajouter un contenu
-{% endif %}
diff --git a/users/urls.py b/users/urls.py
index 2fcf4f3..26563ae 100644
--- a/users/urls.py
+++ b/users/urls.py
@@ -21,12 +21,17 @@ urlpatterns = [
'school/',
views.school,
name='school',
- )
+ ),
path(
'school//edit_phone',
views.edit_phone,
name='edit-school-phone'
),
+ path(
+ 'school//edit_name',
+ views.edit_name,
+ name='edit-school-name'
+ ),
path(
'school//edit_mail',
views.edit_mail,
@@ -42,4 +47,9 @@ urlpatterns = [
views.edit_jury_2,
name='edit-jury-2'
),
+ path(
+ 'school//validate',
+ views.validate,
+ name='validate',
+ )
]
diff --git a/users/views.py b/users/views.py
index ffe6d23..87f3eb5 100644
--- a/users/views.py
+++ b/users/views.py
@@ -30,7 +30,7 @@ def create_school(request):
if school_form.is_valid():
s = school_form.save()
messages.success(request, "L'école {} a bien été créée.".format(s.name))
- return redirect(redirect('settings:index'))
+ return redirect(reverse('settings:index'))
return render(request, 'edit.html', {
'form': school_form,
'title': "Création d'une école",
@@ -52,12 +52,12 @@ def edit_phone(request, pk):
can = request.user.is_staff or request.user == school.admin
if not can:
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
- return redirect(reverse('settings:index'))
+ return redirect(reverse('home'))
school_form = forms.EditPhone(request.POST or None, instance=school)
if school_form.is_valid():
s = school_form.save()
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
- return redirect(redirect('settings:index'))
+ return redirect(s.get_absolute_url())
return render(request, 'edit.html', {
'form': school_form,
'title': "Édition du numéro de téléphone",
@@ -70,12 +70,12 @@ def edit_logo(request, pk):
can = request.user.is_staff or request.user == school.admin
if not can:
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
- return redirect(reverse('settings:index'))
+ return redirect(reverse('home'))
school_form = forms.EditLogo(request.POST or None, instance=school)
if school_form.is_valid():
s = school_form.save()
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
- return redirect(redirect('settings:index'))
+ return redirect(s.get_absolute_url())
return render(request, 'edit.html', {
'form': school_form,
'title': "Édition du logo",
@@ -88,12 +88,12 @@ def edit_mail(request, pk):
can = request.user.is_staff or request.user == school.admin
if not can:
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
- return redirect(reverse('settings:index'))
+ return redirect(reverse('home'))
user_form = forms.EditMail(request.POST or None, instance=school.admin)
if user_form.is_valid():
s = user_form.save()
- messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
- return redirect(redirect('settings:index'))
+ messages.success(request, "L'école {} a bien été modifiée.".format(s.school.name))
+ return redirect(s.school.get_absolute_url())
return render(request, 'edit.html', {
'form': user_form,
'title': "Édition du numéro du mail",
@@ -106,12 +106,12 @@ def edit_jury_1(request, pk):
can = request.user.is_staff or request.user == school.admin
if not can:
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
- return redirect(reverse('settings:index'))
+ return redirect(reverse('home'))
school_form = forms.EditJury1(request.POST or None, instance=school)
if school_form.is_valid():
s = school_form.save()
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
- return redirect(redirect('settings:index'))
+ return redirect(s.get_absolute_url())
return render(request, 'edit.html', {
'form': school_form,
'title': "Édition du jury 1",
@@ -124,12 +124,12 @@ def edit_jury_2(request, pk):
can = request.user.is_staff or request.user == school.admin
if not can:
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
- return redirect(reverse('settings:index'))
+ return redirect(reverse('home'))
school_form = forms.EditJury2(request.POST or None, instance=school)
if school_form.is_valid():
s = school_form.save()
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
- return redirect(redirect('settings:index'))
+ return redirect(s.get_absolute_url())
return render(request, 'edit.html', {
'form': school_form,
'title': "Édition du jury 2",
@@ -137,27 +137,45 @@ def edit_jury_2(request, pk):
})
+def edit_name(request, pk):
+ school = get_object_or_404(School, pk=pk)
+ can = request.user.is_staff or request.user == school.admin
+ if not can:
+ messages.error(request, 'Vous ne pouvez pas accéder à cette page')
+ return redirect(reverse('home'))
+ school_form = forms.EditName(request.POST or None, instance=school)
+ if school_form.is_valid():
+ s = school_form.save()
+ messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
+ return redirect(s.get_absolute_url())
+ return render(request, 'edit.html', {
+ 'form': school_form,
+ 'title': "Édition du nom",
+ 'validate': "Modifier"
+ })
+
+
def validate(request, pk):
school = get_object_or_404(School, pk=pk)
can = request.user.is_staff or request.user == school.admin
if not can:
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
- return redirect(reverse('settings:index'))
+ return redirect(reverse('home'))
jury_1_ok = any([
- school.first_name_j1 is not None,
- school.last_name_j1 is not None,
- school.phone_j1 is not None,
- school.mail_j1 is not None
+ school.first_name_j1,
+ school.last_name_j1,
+ school.phone_j1,
+ school.mail_j1
])
jury_2_ok = any([
- school.first_name_j2 is not None,
- school.last_name_j2 is not None,
- school.phone_j2 is not None,
- school.mail_j2 is not None
+ school.first_name_j2,
+ school.last_name_j2,
+ school.phone_j2,
+ school.mail_j2
])
- logo_ok = school.logo is not None
- phone_ok = school.phone is not None
- mail_ok = school.admin.email is not None
+ logo_ok = school.logo
+ phone_ok = school.phone
+ mail_ok = school.admin.email
if not jury_1_ok:
messages.warning(request, 'Pas de jury n°1 défini.')
if not jury_2_ok:
@@ -178,4 +196,4 @@ def validate(request, pk):
school.save()
messages.success(request, 'Inscription validée.')
- return redirect(reverse('settings:index'))
+ return redirect(school.get_absolute_url())
|