From c606570a99ca2da65a03c2747486bd8694d15d7d Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Fri, 9 Mar 2018 11:44:49 +0100 Subject: [PATCH] =?UTF-8?q?Vues=20d'affichage=20et=20d'=C3=A9dition=20pour?= =?UTF-8?q?=20les=20nouveaux=20mod=C3=A8les?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/migrations/0002_auto_20180309_1116.py | 23 +++ content/models.py | 8 +- content/templates/content/content.html | 4 +- content/templates/content/content_list.html | 8 +- content/urls.py | 14 +- content/views.py | 19 +-- settings/templates/settings/settings.html | 32 ++-- settings/views.py | 14 +- templates/nav_bar.html | 7 +- users/admin.py | 6 + users/forms.py | 10 +- users/migrations/0002_school_validated.py | 18 +++ users/migrations/0003_school_name.py | 18 +++ users/models.py | 9 +- users/templates/users/school.html | 151 ++++++++++++++++-- users/urls.py | 12 +- users/views.py | 68 +++++--- 17 files changed, 319 insertions(+), 102 deletions(-) create mode 100644 content/migrations/0002_auto_20180309_1116.py create mode 100644 users/migrations/0002_school_validated.py create mode 100644 users/migrations/0003_school_name.py diff --git a/content/migrations/0002_auto_20180309_1116.py b/content/migrations/0002_auto_20180309_1116.py new file mode 100644 index 0000000..392f4dd --- /dev/null +++ b/content/migrations/0002_auto_20180309_1116.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.1 on 2018-03-09 10:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('content', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='category', + name='description_short', + field=models.TextField(null=True, verbose_name='Description courte'), + ), + migrations.AlterField( + model_name='category', + name='description', + field=models.TextField(default='', verbose_name='Description de la catégorie'), + ), + ] diff --git a/content/models.py b/content/models.py index 9597d81..256b91f 100644 --- a/content/models.py +++ b/content/models.py @@ -13,8 +13,12 @@ class Category(models.Model): max_length=255, verbose_name="Nom de la catégorie" ) + description_short = models.TextField( + verbose_name="Description courte", + null=True, + ) description = models.TextField( - verbose_name="Descriton de la catégorie", + verbose_name="Description de la catégorie", default="" ) image = models.ImageField( @@ -23,7 +27,7 @@ class Category(models.Model): ) def get_absolute_url(self): - return reverse('content:category-list', kwargs={'pk': self.pk}) + return reverse('content:category', kwargs={'pk': self.pk}) def __str__(self): return self.name diff --git a/content/templates/content/content.html b/content/templates/content/content.html index 3785644..21d579d 100644 --- a/content/templates/content/content.html +++ b/content/templates/content/content.html @@ -5,15 +5,13 @@

{{content.name}}

-

Contenu proposé par {{content.school_owner.group.name}}

- {% if content.manager_right in perms %} +

Catégorie : {{content.category.name}}

- {% endif %}
diff --git a/content/templates/content/content_list.html b/content/templates/content/content_list.html index d6fb175..cc56d5b 100644 --- a/content/templates/content/content_list.html +++ b/content/templates/content/content_list.html @@ -22,15 +22,13 @@ $('html, body').animate({scrollTop: $('#category-content').offset().top}, 800);

{{category.name}}

-

{{category.description}}

+

{{category.description_short}}

Aller voir !

-
- {% for content in contents %} - {% include "content/content.html" %} - {% endfor %} +
+ {{category.description|safe}}


diff --git a/content/urls.py b/content/urls.py index ab53c2a..2ae991c 100644 --- a/content/urls.py +++ b/content/urls.py @@ -1,8 +1,8 @@ from django.urls import path from .views import ( - ContentCategoryList, CreateCategory, + ViewCategory, DeleteCategory, EditCategory, CreateContent, @@ -12,11 +12,6 @@ from .views import ( app_name = 'content' urlpatterns = [ - path( - 'category//', - ContentCategoryList.as_view(), - name='category-list' - ), path( 'category/delete/', DeleteCategory.as_view(), @@ -28,7 +23,12 @@ urlpatterns = [ name='category-new' ), path( - 'category/edit/', + 'category/', + ViewCategory.as_view(), + name='category', + ), + path( + 'category//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 @@ - - + {% for school in schools %} - - + - {% endfor %} @@ -142,9 +144,5 @@ {% endif %} - - - -
NomNombre de membres Nombre de contenus Nombre de catégories Numéro de téléphoneInscription
{{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 %}
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 %} {% endfor %}