Browse Source

Édition d'écoles.

master
Hugo LEVY-FALK 8 years ago
parent
commit
543ca0611b
  1. 2
      settings/templates/settings/settings.html
  2. 6
      users/urls.py
  3. 19
      users/views.py

2
settings/templates/settings/settings.html

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

6
users/urls.py

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

19
users/views.py

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

Loading…
Cancel
Save