Édition d'écoles.

This commit is contained in:
Hugo LEVY-FALK 2018-01-31 13:01:04 +01:00
parent 4da81b99a0
commit 543ca0611b
3 changed files with 23 additions and 4 deletions

View file

@ -43,7 +43,7 @@
<tr>
<th>{{school.group.name}}</th>
<td>{{school.group.user_set.count}}</td>
<td><a class="btn btn-primary btn-sm" href="">
<td><a class="btn btn-primary btn-sm" href="{% url "users:edit-school" pk=school.pk%}">
<i class="glyphicon glyphicon-edit"></i>
Éditer
</a>

View file

@ -3,6 +3,7 @@ from .views import (
CreateUser,
CreateUserProfile,
CreateSchool,
EditSchool,
)
app_name = 'users'
@ -22,4 +23,9 @@ urlpatterns = [
CreateSchool.as_view(),
name='new-school'
),
path(
'school/<int:pk>/edit',
EditSchool.as_view(),
name='edit-school'
),
]

View file

@ -1,5 +1,5 @@
from django.contrib.auth.models import User, Group
from django.views.generic import CreateView
from django.views.generic import CreateView, UpdateView
from django.urls import reverse, reverse_lazy
from django.shortcuts import get_object_or_404
@ -50,9 +50,9 @@ class CreateUserProfile(CreateView):
class CreateSchool(CreateView):
model = Group
fields = '__all__'
fields = ['name']
template_name = 'edit.html'
success_url = reverse_lazy('home')
success_url = reverse_lazy('settings:index')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -66,3 +66,16 @@ class CreateSchool(CreateView):
profile.group = form.instance
profile.save()
return response
class EditSchool(UpdateView):
model = Group
fields = ['name']
template_name = 'edit.html'
success_url = reverse_lazy('settings:index')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = "Édition de l'école"
context['validate'] = "Modifier"
return context