Numéro de téléphone

This commit is contained in:
Klafyvel 2018-03-02 09:33:37 +01:00
parent 1721c95925
commit 0c75f32c5f
6 changed files with 71 additions and 8 deletions

View file

@ -43,12 +43,14 @@
<tr> <tr>
<th>Nom</th> <th>Nom</th>
<th>Nombre de membres</th> <th>Nombre de membres</th>
<th>Numéro de téléphone</th>
<th></th> <th></th>
{% for school in schools %} {% for school in schools %}
<tr> <tr>
<th>{{school.group.name}}</th> <th>{{school.group.name}}</th>
<td>{{school.group.user_set.count}}</td> <td>{{school.group.user_set.count}}</td>
<td><a class="btn btn-outline-primary btn-sm" href="{% url "users:edit-school" pk=school.group.pk%}"> <td>{{school.phone}}</td>
<td><a class="btn btn-outline-primary btn-sm" href="{% url "users:edit-school-name" pk=school.group.pk%}">
<i class="fas fa-edit"></i> <i class="fas fa-edit"></i>
Éditer Éditer
</a> </a>

View file

@ -0,0 +1,18 @@
# Generated by Django 2.0.1 on 2018-03-01 23:28
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0005_auto_20180301_1029'),
]
operations = [
migrations.AddField(
model_name='schoolprofile',
name='phone',
field=models.CharField(help_text='Visible uniquement des administrateurs', max_length=10, null=True, verbose_name='Numéro de téléphone pour contacter le responsable des productions'),
),
]

View file

@ -4,6 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.urls import reverse from django.urls import reverse
from django.dispatch import receiver from django.dispatch import receiver
from django.core import validators
class SchoolProfile(models.Model): class SchoolProfile(models.Model):
@ -19,6 +20,17 @@ class SchoolProfile(models.Model):
related_name="admin_of", related_name="admin_of",
null=True null=True
) )
phone = models.CharField(
max_length=10,
help_text="Visible uniquement des administrateurs",
verbose_name="Numéro de téléphone pour contacter le responsable des productions",
blank=False,
null=True,
validators=[
validators.RegexValidator('^[0-9]{10}$',
"Veuillez entrer un numéro à 10 chiffres."),
]
)
def __str__(self): def __str__(self):
return self.group.name return self.group.name

View file

@ -3,7 +3,12 @@
{% block content %} {% block content %}
<h1>{{object.name}}</h1> <h1>{{object.name}}</h1>
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-school' object.pk %}"> {% if manager_right in perms %}
Numéro de téléphone :
{% if object.school.phone %}{{object.school.phone}}{%else%}
Non indiqué{%endif%}<br/>
{%endif%}
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-school-name' object.pk %}">
<i class="fa fa-edit"></i> <i class="fa fa-edit"></i>
Éditer Éditer
</a> </a>

View file

@ -3,7 +3,8 @@ from .views import (
CreateUser, CreateUser,
CreateUserProfile, CreateUserProfile,
CreateSchool, CreateSchool,
EditSchool, EditSchoolName,
EditSchoolPhone,
DeleteSchool, DeleteSchool,
Login, Login,
Logout, Logout,
@ -67,9 +68,14 @@ urlpatterns = [
name='promote-user' name='promote-user'
), ),
path( path(
'school/<int:pk>/edit', 'school/<int:pk>/edit_name',
EditSchool.as_view(), EditSchoolName.as_view(),
name='edit-school' name='edit-school-name'
),
path(
'school/<int:pk>/edit_phone',
EditSchoolPhone.as_view(),
name='edit-school-phone'
), ),
path( path(
'school/<int:pk>/delete', 'school/<int:pk>/delete',

View file

@ -103,14 +103,14 @@ class CreateSchool(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
return response return response
class EditSchool(LoginRequiredMixin, PermissionRequiredMixin, UpdateView): class EditSchoolName(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
model = Group model = Group
fields = ['name'] fields = ['name']
template_name = 'edit.html' template_name = 'edit.html'
queryset = Group.objects.filter(school__isnull=False) queryset = Group.objects.filter(school__isnull=False)
def get_success_url(self): def get_success_url(self):
return reverse('users:school', kwargs={'pk':self.object.pk}) return reverse('users:edit-school-phone', kwargs={'pk':self.object.school.pk})
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -127,14 +127,34 @@ class EditSchool(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
return r return r
class EditSchoolPhone(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
model = SchoolProfile
fields = ['phone']
template_name = 'edit.html'
def get_success_url(self):
return reverse('users:school', kwargs={'pk':self.object.group.pk})
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['title'] = "Édition de l'école"
context['validate'] = "Modifier"
return context
def has_permission(self):
return self.request.user.has_perm('users.manage_'+str(self.kwargs['pk']))
class DeleteSchool(LoginRequiredMixin, PermissionRequiredMixin, DeleteView): class DeleteSchool(LoginRequiredMixin, PermissionRequiredMixin, DeleteView):
model = Group model = Group
permission_required = 'users.delete_schoolprofile' permission_required = 'users.delete_schoolprofile'
queryset = Group.objects.filter(school__isnull=False)
class School(LoginRequiredMixin, PermissionRequiredMixin, DetailView): class School(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
model = Group model = Group
template_name = "users/school.html" template_name = "users/school.html"
queryset = Group.objects.filter(school__isnull=False)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data() context = super().get_context_data()