Numéro de téléphone
This commit is contained in:
parent
1721c95925
commit
0c75f32c5f
6 changed files with 71 additions and 8 deletions
|
@ -43,12 +43,14 @@
|
|||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Nombre de membres</th>
|
||||
<th>Numéro de téléphone</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-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>
|
||||
Éditer
|
||||
</a>
|
||||
|
|
18
users/migrations/0006_schoolprofile_phone.py
Normal file
18
users/migrations/0006_schoolprofile_phone.py
Normal 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'),
|
||||
),
|
||||
]
|
|
@ -4,6 +4,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||
from django.db.models.signals import post_save
|
||||
from django.urls import reverse
|
||||
from django.dispatch import receiver
|
||||
from django.core import validators
|
||||
|
||||
|
||||
class SchoolProfile(models.Model):
|
||||
|
@ -19,6 +20,17 @@ class SchoolProfile(models.Model):
|
|||
related_name="admin_of",
|
||||
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):
|
||||
return self.group.name
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
|
||||
{% block content %}
|
||||
<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>
|
||||
Éditer
|
||||
</a>
|
||||
|
|
|
@ -3,7 +3,8 @@ from .views import (
|
|||
CreateUser,
|
||||
CreateUserProfile,
|
||||
CreateSchool,
|
||||
EditSchool,
|
||||
EditSchoolName,
|
||||
EditSchoolPhone,
|
||||
DeleteSchool,
|
||||
Login,
|
||||
Logout,
|
||||
|
@ -67,9 +68,14 @@ urlpatterns = [
|
|||
name='promote-user'
|
||||
),
|
||||
path(
|
||||
'school/<int:pk>/edit',
|
||||
EditSchool.as_view(),
|
||||
name='edit-school'
|
||||
'school/<int:pk>/edit_name',
|
||||
EditSchoolName.as_view(),
|
||||
name='edit-school-name'
|
||||
),
|
||||
path(
|
||||
'school/<int:pk>/edit_phone',
|
||||
EditSchoolPhone.as_view(),
|
||||
name='edit-school-phone'
|
||||
),
|
||||
path(
|
||||
'school/<int:pk>/delete',
|
||||
|
|
|
@ -103,14 +103,14 @@ class CreateSchool(LoginRequiredMixin, PermissionRequiredMixin, CreateView):
|
|||
return response
|
||||
|
||||
|
||||
class EditSchool(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
|
||||
class EditSchoolName(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
|
||||
model = Group
|
||||
fields = ['name']
|
||||
template_name = 'edit.html'
|
||||
queryset = Group.objects.filter(school__isnull=False)
|
||||
|
||||
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):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
@ -127,14 +127,34 @@ class EditSchool(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
|
|||
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):
|
||||
model = Group
|
||||
permission_required = 'users.delete_schoolprofile'
|
||||
queryset = Group.objects.filter(school__isnull=False)
|
||||
|
||||
|
||||
class School(LoginRequiredMixin, PermissionRequiredMixin, DetailView):
|
||||
model = Group
|
||||
template_name = "users/school.html"
|
||||
queryset = Group.objects.filter(school__isnull=False)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data()
|
||||
|
|
Loading…
Reference in a new issue