Création d'écoles.

This commit is contained in:
Hugo LEVY-FALK 2018-01-31 11:53:37 +01:00
parent 5e594d6b85
commit 4da81b99a0
6 changed files with 82 additions and 4 deletions

View file

@ -29,6 +29,31 @@
{% endfor %}
</table>
<h2>Écoles</h2>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:new-school' %}">
<i class="glyphicon glyphicon-plus"></i>
Inscrire une nouvelle école
</a>
<table class="table table-striped">
<tr>
<th>Nom</th>
<th>Nombre de membres</th>
<th></th>
{% for school in schools %}
<tr>
<th>{{school.group.name}}</th>
<td>{{school.group.user_set.count}}</td>
<td><a class="btn btn-primary btn-sm" href="">
<i class="glyphicon glyphicon-edit"></i>
Éditer
</a>
<a class="btn btn-danger btn-sm" title="Supprimer" href="">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
</tr>
{% endfor %}
</table>
<h2>Réglages</h2>
<h3>Réglages du site</h3>
<a class="btn btn-primary btn-sm" href="">

View file

@ -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

View file

@ -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'),
),
]

View file

@ -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):

View file

@ -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/<int:pk>/set_school',
CreateUserProfile.as_view(),
name='create-userprofile'
)
),
path(
'school/new',
CreateSchool.as_view(),
name='new-school'
),
]

View file

@ -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