diff --git a/settings/templates/settings/settings.html b/settings/templates/settings/settings.html index bab1f25..8e3116d 100644 --- a/settings/templates/settings/settings.html +++ b/settings/templates/settings/settings.html @@ -29,6 +29,31 @@ {% endfor %} +

Écoles

+ + + Inscrire une nouvelle école + + + + + + +{% for school in schools %} + + + + + +{% endfor %} +
NomNombre de membres
{{school.group.name}}{{school.group.user_set.count}} + + Éditer + + + + +

Réglages

Réglages du site

diff --git a/settings/views.py b/settings/views.py index 4f10f14..12301ae 100644 --- a/settings/views.py +++ b/settings/views.py @@ -1,5 +1,6 @@ from django.views.generic import TemplateView from content.models import Category +from users.models import SchoolProfile from .models import ContentSettings, SiteSettings class SettingsView(TemplateView): @@ -9,4 +10,5 @@ class SettingsView(TemplateView): context['categories'] = Category.objects.all() context['site_settings'],_ = SiteSettings.objects.get_or_create() context['content_settings'],_ = ContentSettings.objects.get_or_create() + context['schools'] = SchoolProfile.objects.all() return context diff --git a/users/migrations/0002_auto_20180131_1052.py b/users/migrations/0002_auto_20180131_1052.py new file mode 100644 index 0000000..8cfaf07 --- /dev/null +++ b/users/migrations/0002_auto_20180131_1052.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.1 on 2018-01-31 10:52 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='schoolprofile', + name='is_school', + ), + migrations.AlterField( + model_name='userprofile', + name='school', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='users.SchoolProfile'), + ), + ] diff --git a/users/models.py b/users/models.py index 0436886..496bc27 100644 --- a/users/models.py +++ b/users/models.py @@ -6,7 +6,6 @@ from django.dispatch import receiver class SchoolProfile(models.Model): """Ajoute un champ pour distinguer les groupes écoles des autres.""" - is_school = models.BooleanField() group = models.OneToOneField(Group, on_delete=models.CASCADE) def __str__(self): diff --git a/users/urls.py b/users/urls.py index 51cb8cd..cd8345f 100644 --- a/users/urls.py +++ b/users/urls.py @@ -1,5 +1,9 @@ from django.urls import path -from .views import CreateUser, CreateUserProfile +from .views import ( + CreateUser, + CreateUserProfile, + CreateSchool, +) app_name = 'users' urlpatterns = [ @@ -12,5 +16,10 @@ urlpatterns = [ 'user//set_school', CreateUserProfile.as_view(), name='create-userprofile' - ) + ), + path( + 'school/new', + CreateSchool.as_view(), + name='new-school' + ), ] diff --git a/users/views.py b/users/views.py index abc4750..ecd9ae6 100644 --- a/users/views.py +++ b/users/views.py @@ -3,7 +3,7 @@ from django.views.generic import CreateView from django.urls import reverse, reverse_lazy from django.shortcuts import get_object_or_404 -from .models import UserProfile +from .models import UserProfile, SchoolProfile class CreateUser(CreateView): @@ -46,3 +46,23 @@ class CreateUserProfile(CreateView): def form_valid(self, form): form.instance.user = get_object_or_404(User, pk=self.kwargs['pk']) return super(CreateUserProfile, self).form_valid(form) + + +class CreateSchool(CreateView): + model = Group + fields = '__all__' + template_name = 'edit.html' + success_url = reverse_lazy('home') + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['title'] = "Création de l'école" + context['validate'] = "Créer" + return context + + def form_valid(self, form): + response = super(CreateSchool, self).form_valid(form) + profile = SchoolProfile() + profile.group = form.instance + profile.save() + return response