Vues d'affichage et d'édition pour les nouveaux modèles
This commit is contained in:
parent
0303710d26
commit
c606570a99
17 changed files with 319 additions and 102 deletions
23
content/migrations/0002_auto_20180309_1116.py
Normal file
23
content/migrations/0002_auto_20180309_1116.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-03-09 10:16
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('content', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='category',
|
||||||
|
name='description_short',
|
||||||
|
field=models.TextField(null=True, verbose_name='Description courte'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='category',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(default='', verbose_name='Description de la catégorie'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,8 +13,12 @@ class Category(models.Model):
|
||||||
max_length=255,
|
max_length=255,
|
||||||
verbose_name="Nom de la catégorie"
|
verbose_name="Nom de la catégorie"
|
||||||
)
|
)
|
||||||
|
description_short = models.TextField(
|
||||||
|
verbose_name="Description courte",
|
||||||
|
null=True,
|
||||||
|
)
|
||||||
description = models.TextField(
|
description = models.TextField(
|
||||||
verbose_name="Descriton de la catégorie",
|
verbose_name="Description de la catégorie",
|
||||||
default=""
|
default=""
|
||||||
)
|
)
|
||||||
image = models.ImageField(
|
image = models.ImageField(
|
||||||
|
@ -23,7 +27,7 @@ class Category(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('content:category-list', kwargs={'pk': self.pk})
|
return reverse('content:category', kwargs={'pk': self.pk})
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
|
@ -5,15 +5,13 @@
|
||||||
</video>
|
</video>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h2 class="display-5">{{content.name}}</h2>
|
<h2 class="display-5">{{content.name}}</h2>
|
||||||
<p class="lead">Contenu proposé par {{content.school_owner.group.name}}</p>
|
<p class="lead">Catégorie : {{content.category.name}}</p>
|
||||||
{% if content.manager_right in perms %}
|
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<a class="btn btn-sm btn-outline-primary"i href="{% url "content:content-edit" content.pk %}"><i class="fa fa-edit"></i> Éditer</a>
|
<a class="btn btn-sm btn-outline-primary"i href="{% url "content:content-edit" content.pk %}"><i class="fa fa-edit"></i> Éditer</a>
|
||||||
<a class="btn btn-sm btn-outline-danger" href="{% url "content:content-delete" content.pk %}" ><i class="fa fa-trash"></i> Supprimer</a>
|
<a class="btn btn-sm btn-outline-danger" href="{% url "content:content-delete" content.pk %}" ><i class="fa fa-trash"></i> Supprimer</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,15 +22,13 @@ $('html, body').animate({scrollTop: $('#category-content').offset().top}, 800);
|
||||||
<div class="position-relative overflow-hidden p-3 p-md-5 text-center bg-light page-title">
|
<div class="position-relative overflow-hidden p-3 p-md-5 text-center bg-light page-title">
|
||||||
<div class="col-md-5 p-lg-5 mx-auto my-5 title-block">
|
<div class="col-md-5 p-lg-5 mx-auto my-5 title-block">
|
||||||
<h1 class="display-4 font-weight-normal">{{category.name}}</h1>
|
<h1 class="display-4 font-weight-normal">{{category.name}}</h1>
|
||||||
<p class="lead font-weight-normal">{{category.description}}</p>
|
<p class="lead font-weight-normal">{{category.description_short}}</p>
|
||||||
<a class="btn btn-outline-secondary smooth-scroll" href="#category-content">Aller voir !</a>
|
<a class="btn btn-outline-secondary smooth-scroll" href="#category-content">Aller voir !</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<div class="row text-center" id="category-content">
|
<div id="category-content">
|
||||||
{% for content in contents %}
|
{{category.description|safe}}
|
||||||
{% include "content/content.html" %}
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import (
|
from .views import (
|
||||||
ContentCategoryList,
|
|
||||||
CreateCategory,
|
CreateCategory,
|
||||||
|
ViewCategory,
|
||||||
DeleteCategory,
|
DeleteCategory,
|
||||||
EditCategory,
|
EditCategory,
|
||||||
CreateContent,
|
CreateContent,
|
||||||
|
@ -12,11 +12,6 @@ from .views import (
|
||||||
|
|
||||||
app_name = 'content'
|
app_name = 'content'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
|
||||||
'category/<int:pk>/',
|
|
||||||
ContentCategoryList.as_view(),
|
|
||||||
name='category-list'
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
'category/delete/<int:pk>',
|
'category/delete/<int:pk>',
|
||||||
DeleteCategory.as_view(),
|
DeleteCategory.as_view(),
|
||||||
|
@ -28,7 +23,12 @@ urlpatterns = [
|
||||||
name='category-new'
|
name='category-new'
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
'category/edit/<int:pk>',
|
'category/<int:pk>',
|
||||||
|
ViewCategory.as_view(),
|
||||||
|
name='category',
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
'category/<int:pk>/edit',
|
||||||
EditCategory.as_view(),
|
EditCategory.as_view(),
|
||||||
name='category-edit',
|
name='category-edit',
|
||||||
),
|
),
|
||||||
|
|
|
@ -8,24 +8,11 @@ from .models import Content, Category
|
||||||
from settings.models import SiteSettings
|
from settings.models import SiteSettings
|
||||||
|
|
||||||
|
|
||||||
class ContentCategoryList(generic.ListView):
|
class ViewCategory(generic.DetailView):
|
||||||
"""Affiche les contenus d'une catégorie."""
|
"""Affiche une catégorie."""
|
||||||
model = Content
|
model = Category
|
||||||
context_object_name = "contents"
|
|
||||||
template_name = "content/content_list.html"
|
template_name = "content/content_list.html"
|
||||||
|
|
||||||
def get_queryset(self):
|
|
||||||
pk = self.kwargs['pk']
|
|
||||||
category = get_object_or_404(Category, pk=pk)
|
|
||||||
return Content.objects.filter(category=category)
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
|
||||||
context = super(generic.ListView, self).get_context_data(**kwargs)
|
|
||||||
pk = self.kwargs['pk']
|
|
||||||
category = get_object_or_404(Category, pk=pk)
|
|
||||||
context['category'] = category
|
|
||||||
return context
|
|
||||||
|
|
||||||
|
|
||||||
class CreateCategory(PermissionRequiredMixin, generic.CreateView):
|
class CreateCategory(PermissionRequiredMixin, generic.CreateView):
|
||||||
"""Création de catégorie."""
|
"""Création de catégorie."""
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
<td>{{admin.last_name}}</td>
|
<td>{{admin.last_name}}</td>
|
||||||
<td>{{admin.username}}</td>
|
<td>{{admin.username}}</td>
|
||||||
<td>
|
<td>
|
||||||
<a class="btn btn-outline-danger btn-sm" href="{% url 'settings:degrade-user' admin.pk %}">
|
<a class="btn btn-outline-danger btn-sm" href="{% url 'settings:degrade-user' admin.pk %}">
|
||||||
<i class="fa fa-trash"></i>
|
<i class="fa fa-trash"></i>
|
||||||
Enlever le privilège Administrateur
|
Enlever le privilège Administrateur
|
||||||
</a>
|
</a>
|
||||||
|
@ -76,26 +76,28 @@
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nom</th>
|
<th>Nom</th>
|
||||||
<th>Nombre de membres</th>
|
|
||||||
<th>Nombre de contenus</th>
|
<th>Nombre de contenus</th>
|
||||||
<th>Nombre de catégories</th>
|
<th>Nombre de catégories</th>
|
||||||
<th>Numéro de téléphone</th>
|
<th>Numéro de téléphone</th>
|
||||||
<th></th>
|
<th>Inscription</th>
|
||||||
{% for school in schools %}
|
{% for school in schools %}
|
||||||
<tr>
|
<tr>
|
||||||
<th><a href="{{school.get_absolute_url}}">{{school.group.name}}</a></th>
|
<th><a href="{{school.get_absolute_url}}">{{school.name}}</a></th>
|
||||||
<td>{{school.group.user_set.count}}</td>
|
|
||||||
<td>{{school.content_set.count}}</td>
|
<td>{{school.content_set.count}}</td>
|
||||||
<td>{{school.number_of_categories}}</td>
|
<td>{{school.number_of_categories}}</td>
|
||||||
<td>{{school.phone}}</td>
|
<td>{{school.phone}}</td>
|
||||||
<td><a class="btn btn-outline-primary btn-sm" href="{% url "users:edit-school-name" pk=school.group.pk%}">
|
<td>
|
||||||
<i class="fas fa-edit"></i>
|
{% if school.validated %}
|
||||||
Éditer
|
<span class="badge badge-success">
|
||||||
</a>
|
<i class="fa fa-check"></i>
|
||||||
<a class="btn btn-outline-danger btn-sm" title="Supprimer" href="">
|
Inscription validée
|
||||||
<i class="fas fa-trash-alt"></i>
|
</span>
|
||||||
Supprimer
|
{% else %}
|
||||||
</a>
|
<span class="badge badge-danger">
|
||||||
|
<i class="fa fa-exclamation"></i>
|
||||||
|
Inscription non validée
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -142,9 +144,5 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<th>Nombre minimal de catégories</th>
|
|
||||||
<td>{{ site_settings.min_number_of_categories }}</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.views.generic import TemplateView, UpdateView
|
from django.views.generic import TemplateView, UpdateView
|
||||||
from django.urls import reverse_lazy, reverse
|
from django.urls import reverse_lazy, reverse
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin, LoginRequiredMixin
|
||||||
from django.contrib.auth.decorators import permission_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Group, User
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
@ -22,7 +22,7 @@ class SettingsView(LoginRequiredMixin, PermissionRequiredMixin, TemplateView):
|
||||||
context['site_settings'], _ = SiteSettings.objects.get_or_create()
|
context['site_settings'], _ = SiteSettings.objects.get_or_create()
|
||||||
context['schools'] = School.objects.all()
|
context['schools'] = School.objects.all()
|
||||||
context['settings'] = True
|
context['settings'] = True
|
||||||
context['administrators'] = Group.objects.get(name='admins').user_set.all()
|
context['administrators'] = User.objects.filter(is_staff=True)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
|
class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateView):
|
||||||
|
@ -42,24 +42,22 @@ class EditSiteSettingsView(LoginRequiredMixin, PermissionRequiredMixin, UpdateVi
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@permission_required('auth.change_user')
|
@staff_member_required
|
||||||
def degrade_user(request, pk):
|
def degrade_user(request, pk):
|
||||||
user = get_object_or_404(User, pk=pk)
|
user = get_object_or_404(User, pk=pk)
|
||||||
admins,_ = Group.objects.get_or_create(name='admins')
|
user.is_staff = False
|
||||||
user.groups.remove(admins)
|
|
||||||
user.save()
|
user.save()
|
||||||
messages.success(request, user.username + ' a été enlevé des administrateurs du site')
|
messages.success(request, user.username + ' a été enlevé des administrateurs du site')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('settings:index'))
|
||||||
|
|
||||||
|
|
||||||
@permission_required('auth.change_user')
|
@staff_member_required
|
||||||
def promote_user(request):
|
def promote_user(request):
|
||||||
user_form = SelectUserForm(request.POST or None)
|
user_form = SelectUserForm(request.POST or None)
|
||||||
user_form.populate()
|
user_form.populate()
|
||||||
if user_form.is_valid():
|
if user_form.is_valid():
|
||||||
user=user_form.get_user()
|
user=user_form.get_user()
|
||||||
admins,_ = Group.objects.get_or_create(name='admins')
|
user.is_staff = True
|
||||||
user.groups.add(admins)
|
|
||||||
user.save()
|
user.save()
|
||||||
messages.success(request, user.username + ' a été ajouté des administrateurs du site')
|
messages.success(request, user.username + ' a été ajouté des administrateurs du site')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('settings:index'))
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
{% for c in categories %}
|
{% for c in categories %}
|
||||||
<li class="nav-item
|
<li class="nav-item
|
||||||
{% if category.pk == c.pk %}active{%endif%}">
|
{% if category.pk == c.pk %}active{%endif%}">
|
||||||
<a class="nav-link" href="{% url 'content:category-list' c.pk %}">{{c.name}}
|
<a class="nav-link" href="{% url 'content:category' c.pk %}">{{c.name}}
|
||||||
</a></li>
|
</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<ul class="navbar-nav ml-auto">
|
<ul class="navbar-nav ml-auto">
|
||||||
{% if request.user.userprofile.school %}
|
{% if request.user.school %}
|
||||||
<li class="nav-item {% if school %}active{% endif %}"><a class="nav-link" href="{% url 'users:school' request.user.userprofile.school.group.pk %}"><i class="fas fa-graduation-cap"></i> Mon école</a></li>
|
<li class="nav-item {% if school %}active{% endif %}"><a class="nav-link" href="{% url 'users:school' request.user.school.pk %}"><i class="fas fa-graduation-cap"></i> Mon école</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li class="nav-item {% if settings %}active{% endif %}"><a class="nav-link" href="{% url 'settings:index' %}"><i class="fas fa-cogs"></i> Administration</a></li>
|
<li class="nav-item {% if settings %}active{% endif %}"><a class="nav-link" href="{% url 'settings:index' %}"><i class="fas fa-cogs"></i> Administration</a></li>
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
|
@ -33,7 +33,6 @@
|
||||||
{{request.user}}
|
{{request.user}}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
|
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
|
||||||
<a class="dropdown-item" href="{% url 'users:profile' request.user.pk%}"><i class="fa fa-user"></i> Accéder à mon profil</a>
|
|
||||||
<a class="dropdown-item" href="{% url 'users:logout' %}"><i class="fa fa-sign-out-alt"></i> Se déconnecter</a>
|
<a class="dropdown-item" href="{% url 'users:logout' %}"><i class="fa fa-sign-out-alt"></i> Se déconnecter</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from .models import School
|
||||||
|
|
||||||
|
class SchoolAdmin(admin.ModelAdmin):
|
||||||
|
pass
|
||||||
|
admin.site.register(School, SchoolAdmin)
|
|
@ -6,8 +6,14 @@ from .models import School
|
||||||
|
|
||||||
class CreateSchool(forms.ModelForm):
|
class CreateSchool(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = School
|
||||||
fields = '__all__'
|
fields = ['name', 'admin']
|
||||||
|
|
||||||
|
|
||||||
|
class EditName(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = School
|
||||||
|
fields = ['name']
|
||||||
|
|
||||||
|
|
||||||
class CreateUser(forms.ModelForm):
|
class CreateUser(forms.ModelForm):
|
||||||
|
|
18
users/migrations/0002_school_validated.py
Normal file
18
users/migrations/0002_school_validated.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-03-09 08:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='school',
|
||||||
|
name='validated',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='Inscription validé.'),
|
||||||
|
),
|
||||||
|
]
|
18
users/migrations/0003_school_name.py
Normal file
18
users/migrations/0003_school_name.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 2.0.1 on 2018-03-09 09:07
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0002_school_validated'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='school',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(default='', max_length=255, verbose_name="Nom de l'école"),
|
||||||
|
),
|
||||||
|
]
|
|
@ -13,6 +13,11 @@ def get_upload_to(instance, filename):
|
||||||
|
|
||||||
class School(models.Model):
|
class School(models.Model):
|
||||||
"""Ajoute un champ pour distinguer les groupes écoles des autres."""
|
"""Ajoute un champ pour distinguer les groupes écoles des autres."""
|
||||||
|
name = models.CharField(
|
||||||
|
verbose_name="Nom de l'école",
|
||||||
|
max_length=255,
|
||||||
|
default=""
|
||||||
|
)
|
||||||
admin = models.OneToOneField(
|
admin = models.OneToOneField(
|
||||||
User,
|
User,
|
||||||
verbose_name="Administrateur de l'école",
|
verbose_name="Administrateur de l'école",
|
||||||
|
@ -83,10 +88,10 @@ class School(models.Model):
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.group.name
|
return self.name
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("users:school", kwargs={'pk':self.group.pk})
|
return reverse("users:school", kwargs={'pk':self.pk})
|
||||||
|
|
||||||
def number_of_categories(self):
|
def number_of_categories(self):
|
||||||
return self.content_set.values('category').distinct().count()
|
return self.content_set.values('category').distinct().count()
|
||||||
|
|
|
@ -2,24 +2,155 @@
|
||||||
{% load bootstrap4 %}
|
{% load bootstrap4 %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{school.name}}</h1>
|
{% if school.validated %}
|
||||||
{% if manager_right in perms %}
|
<span class="badge badge-success">
|
||||||
Numéro de téléphone :
|
<i class="fa fa-check"></i>
|
||||||
{% if school.phone %}{{school.phone}}
|
Inscription validée
|
||||||
{%else%}
|
</span>
|
||||||
Non indiqué{%endif%}<br/>
|
{% endif %}
|
||||||
{%endif%}
|
<h1>
|
||||||
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-school-name' school.pk %}">
|
{{school.name}}
|
||||||
|
</h1>
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-school-name' school.pk %}">
|
||||||
<i class="fa fa-edit"></i>
|
<i class="fa fa-edit"></i>
|
||||||
Éditer
|
Éditer
|
||||||
</a>
|
</a>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Numéro de téléphone
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{% if school.phone %}{{school.phone}}{%else%}
|
||||||
|
Non indiqué{%endif%}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-school-phone' school.pk %}">
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
Éditer
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Email
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.admin.email}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-school-mail' school.pk %}">
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
Éditer
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Juré n°1
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Nom
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.last_name_j1}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Prénom
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.first_name_j1}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Email
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.mail_j1}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
N° de téléphone
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.phone_j1}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-jury-1' school.pk %}">
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
Éditer
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Juré n°2
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
<table class="table table-striped">
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Nom
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.last_name_j2}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Prénom
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.first_name_j2}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Email
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.mail_j2}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
N° de téléphone
|
||||||
|
</th>
|
||||||
|
<td>
|
||||||
|
{{school.phone_j2}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a class="btn btn-primary btn-sm" href="{% url 'users:edit-jury-2' school.pk %}">
|
||||||
|
<i class="fa fa-edit"></i>
|
||||||
|
Éditer
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<a class="btn btn-success btn-lg" href="{% url 'users:validate' school.pk %}">
|
||||||
|
<i class="fa fa-check"></i>
|
||||||
|
Valider mon inscription
|
||||||
|
</a>
|
||||||
|
|
||||||
<h2>Contenus</h2>
|
<h2>Contenus</h2>
|
||||||
{% if manager_right in perms %}
|
|
||||||
<a class="btn btn-success btn-sm" href="{% url 'content:content-new' %}">
|
<a class="btn btn-success btn-sm" href="{% url 'content:content-new' %}">
|
||||||
<i class="fa fa-plus"></i>
|
<i class="fa fa-plus"></i>
|
||||||
Ajouter un contenu
|
Ajouter un contenu
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
|
@ -21,12 +21,17 @@ urlpatterns = [
|
||||||
'school/<int:pk>',
|
'school/<int:pk>',
|
||||||
views.school,
|
views.school,
|
||||||
name='school',
|
name='school',
|
||||||
)
|
),
|
||||||
path(
|
path(
|
||||||
'school/<int:pk>/edit_phone',
|
'school/<int:pk>/edit_phone',
|
||||||
views.edit_phone,
|
views.edit_phone,
|
||||||
name='edit-school-phone'
|
name='edit-school-phone'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'school/<int:pk>/edit_name',
|
||||||
|
views.edit_name,
|
||||||
|
name='edit-school-name'
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
'school/<int:pk>/edit_mail',
|
'school/<int:pk>/edit_mail',
|
||||||
views.edit_mail,
|
views.edit_mail,
|
||||||
|
@ -42,4 +47,9 @@ urlpatterns = [
|
||||||
views.edit_jury_2,
|
views.edit_jury_2,
|
||||||
name='edit-jury-2'
|
name='edit-jury-2'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'school/<int:pk>/validate',
|
||||||
|
views.validate,
|
||||||
|
name='validate',
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|
|
@ -30,7 +30,7 @@ def create_school(request):
|
||||||
if school_form.is_valid():
|
if school_form.is_valid():
|
||||||
s = school_form.save()
|
s = school_form.save()
|
||||||
messages.success(request, "L'école {} a bien été créée.".format(s.name))
|
messages.success(request, "L'école {} a bien été créée.".format(s.name))
|
||||||
return redirect(redirect('settings:index'))
|
return redirect(reverse('settings:index'))
|
||||||
return render(request, 'edit.html', {
|
return render(request, 'edit.html', {
|
||||||
'form': school_form,
|
'form': school_form,
|
||||||
'title': "Création d'une école",
|
'title': "Création d'une école",
|
||||||
|
@ -52,12 +52,12 @@ def edit_phone(request, pk):
|
||||||
can = request.user.is_staff or request.user == school.admin
|
can = request.user.is_staff or request.user == school.admin
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('home'))
|
||||||
school_form = forms.EditPhone(request.POST or None, instance=school)
|
school_form = forms.EditPhone(request.POST or None, instance=school)
|
||||||
if school_form.is_valid():
|
if school_form.is_valid():
|
||||||
s = school_form.save()
|
s = school_form.save()
|
||||||
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
||||||
return redirect(redirect('settings:index'))
|
return redirect(s.get_absolute_url())
|
||||||
return render(request, 'edit.html', {
|
return render(request, 'edit.html', {
|
||||||
'form': school_form,
|
'form': school_form,
|
||||||
'title': "Édition du numéro de téléphone",
|
'title': "Édition du numéro de téléphone",
|
||||||
|
@ -70,12 +70,12 @@ def edit_logo(request, pk):
|
||||||
can = request.user.is_staff or request.user == school.admin
|
can = request.user.is_staff or request.user == school.admin
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('home'))
|
||||||
school_form = forms.EditLogo(request.POST or None, instance=school)
|
school_form = forms.EditLogo(request.POST or None, instance=school)
|
||||||
if school_form.is_valid():
|
if school_form.is_valid():
|
||||||
s = school_form.save()
|
s = school_form.save()
|
||||||
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
||||||
return redirect(redirect('settings:index'))
|
return redirect(s.get_absolute_url())
|
||||||
return render(request, 'edit.html', {
|
return render(request, 'edit.html', {
|
||||||
'form': school_form,
|
'form': school_form,
|
||||||
'title': "Édition du logo",
|
'title': "Édition du logo",
|
||||||
|
@ -88,12 +88,12 @@ def edit_mail(request, pk):
|
||||||
can = request.user.is_staff or request.user == school.admin
|
can = request.user.is_staff or request.user == school.admin
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('home'))
|
||||||
user_form = forms.EditMail(request.POST or None, instance=school.admin)
|
user_form = forms.EditMail(request.POST or None, instance=school.admin)
|
||||||
if user_form.is_valid():
|
if user_form.is_valid():
|
||||||
s = user_form.save()
|
s = user_form.save()
|
||||||
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
messages.success(request, "L'école {} a bien été modifiée.".format(s.school.name))
|
||||||
return redirect(redirect('settings:index'))
|
return redirect(s.school.get_absolute_url())
|
||||||
return render(request, 'edit.html', {
|
return render(request, 'edit.html', {
|
||||||
'form': user_form,
|
'form': user_form,
|
||||||
'title': "Édition du numéro du mail",
|
'title': "Édition du numéro du mail",
|
||||||
|
@ -106,12 +106,12 @@ def edit_jury_1(request, pk):
|
||||||
can = request.user.is_staff or request.user == school.admin
|
can = request.user.is_staff or request.user == school.admin
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('home'))
|
||||||
school_form = forms.EditJury1(request.POST or None, instance=school)
|
school_form = forms.EditJury1(request.POST or None, instance=school)
|
||||||
if school_form.is_valid():
|
if school_form.is_valid():
|
||||||
s = school_form.save()
|
s = school_form.save()
|
||||||
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
||||||
return redirect(redirect('settings:index'))
|
return redirect(s.get_absolute_url())
|
||||||
return render(request, 'edit.html', {
|
return render(request, 'edit.html', {
|
||||||
'form': school_form,
|
'form': school_form,
|
||||||
'title': "Édition du jury 1",
|
'title': "Édition du jury 1",
|
||||||
|
@ -124,12 +124,12 @@ def edit_jury_2(request, pk):
|
||||||
can = request.user.is_staff or request.user == school.admin
|
can = request.user.is_staff or request.user == school.admin
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('home'))
|
||||||
school_form = forms.EditJury2(request.POST or None, instance=school)
|
school_form = forms.EditJury2(request.POST or None, instance=school)
|
||||||
if school_form.is_valid():
|
if school_form.is_valid():
|
||||||
s = school_form.save()
|
s = school_form.save()
|
||||||
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
||||||
return redirect(redirect('settings:index'))
|
return redirect(s.get_absolute_url())
|
||||||
return render(request, 'edit.html', {
|
return render(request, 'edit.html', {
|
||||||
'form': school_form,
|
'form': school_form,
|
||||||
'title': "Édition du jury 2",
|
'title': "Édition du jury 2",
|
||||||
|
@ -137,27 +137,45 @@ def edit_jury_2(request, pk):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def edit_name(request, pk):
|
||||||
|
school = get_object_or_404(School, pk=pk)
|
||||||
|
can = request.user.is_staff or request.user == school.admin
|
||||||
|
if not can:
|
||||||
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
|
return redirect(reverse('home'))
|
||||||
|
school_form = forms.EditName(request.POST or None, instance=school)
|
||||||
|
if school_form.is_valid():
|
||||||
|
s = school_form.save()
|
||||||
|
messages.success(request, "L'école {} a bien été modifiée.".format(s.name))
|
||||||
|
return redirect(s.get_absolute_url())
|
||||||
|
return render(request, 'edit.html', {
|
||||||
|
'form': school_form,
|
||||||
|
'title': "Édition du nom",
|
||||||
|
'validate': "Modifier"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def validate(request, pk):
|
def validate(request, pk):
|
||||||
school = get_object_or_404(School, pk=pk)
|
school = get_object_or_404(School, pk=pk)
|
||||||
can = request.user.is_staff or request.user == school.admin
|
can = request.user.is_staff or request.user == school.admin
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
messages.error(request, 'Vous ne pouvez pas accéder à cette page')
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(reverse('home'))
|
||||||
jury_1_ok = any([
|
jury_1_ok = any([
|
||||||
school.first_name_j1 is not None,
|
school.first_name_j1,
|
||||||
school.last_name_j1 is not None,
|
school.last_name_j1,
|
||||||
school.phone_j1 is not None,
|
school.phone_j1,
|
||||||
school.mail_j1 is not None
|
school.mail_j1
|
||||||
])
|
])
|
||||||
jury_2_ok = any([
|
jury_2_ok = any([
|
||||||
school.first_name_j2 is not None,
|
school.first_name_j2,
|
||||||
school.last_name_j2 is not None,
|
school.last_name_j2,
|
||||||
school.phone_j2 is not None,
|
school.phone_j2,
|
||||||
school.mail_j2 is not None
|
school.mail_j2
|
||||||
])
|
])
|
||||||
logo_ok = school.logo is not None
|
logo_ok = school.logo
|
||||||
phone_ok = school.phone is not None
|
phone_ok = school.phone
|
||||||
mail_ok = school.admin.email is not None
|
mail_ok = school.admin.email
|
||||||
if not jury_1_ok:
|
if not jury_1_ok:
|
||||||
messages.warning(request, 'Pas de jury n°1 défini.')
|
messages.warning(request, 'Pas de jury n°1 défini.')
|
||||||
if not jury_2_ok:
|
if not jury_2_ok:
|
||||||
|
@ -178,4 +196,4 @@ def validate(request, pk):
|
||||||
school.save()
|
school.save()
|
||||||
messages.success(request, 'Inscription validée.')
|
messages.success(request, 'Inscription validée.')
|
||||||
|
|
||||||
return redirect(reverse('settings:index'))
|
return redirect(school.get_absolute_url())
|
||||||
|
|
Loading…
Reference in a new issue