1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-11-26 22:07:09 +00:00

Change media permissions

This commit is contained in:
Alexandre Iooss 2019-08-08 16:33:05 +02:00
parent 8a1af4c2b3
commit deb28aa93b
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
13 changed files with 147 additions and 275 deletions

View File

@ -17,11 +17,15 @@ class MediaAdmin(VersionAdmin):
class EmpruntAdmin(VersionAdmin): class EmpruntAdmin(VersionAdmin):
list_display = ('media', 'user', 'date_emprunt', 'date_rendu', 'permanencier_emprunt', 'permanencier_rendu') list_display = (
'media', 'user', 'date_emprunt', 'date_rendu', 'permanencier_emprunt',
'permanencier_rendu')
class JeuAdmin(VersionAdmin): class JeuAdmin(VersionAdmin):
list_display = ('nom', 'proprietaire', 'duree', 'nombre_joueurs_min', 'nombre_joueurs_max', 'comment') list_display = (
'nom', 'proprietaire', 'duree', 'nombre_joueurs_min', 'nombre_joueurs_max',
'comment')
admin.site.register(Auteur, AuteurAdmin) admin.site.register(Auteur, AuteurAdmin)

View File

@ -15,7 +15,9 @@ class AuteurForm(ModelForm):
class MediaForm(ModelForm): class MediaForm(ModelForm):
auteur = forms.ModelMultipleChoiceField(Auteur.objects.all(), widget=forms.CheckboxSelectMultiple, required=False) auteur = forms.ModelMultipleChoiceField(Auteur.objects.all(),
widget=forms.CheckboxSelectMultiple,
required=False)
class Meta: class Meta:
model = Media model = Media
@ -28,7 +30,8 @@ class JeuForm(ModelForm):
fields = '__all__' fields = '__all__'
def clean_nombre_joueurs_max(self): def clean_nombre_joueurs_max(self):
if self.cleaned_data['nombre_joueurs_max'] < self.cleaned_data['nombre_joueurs_min']: if self.cleaned_data['nombre_joueurs_max'] < self.cleaned_data[
'nombre_joueurs_min']:
raise forms.ValidationError("Max ne peut être inférieur à min") raise forms.ValidationError("Max ne peut être inférieur à min")
return self.cleaned_data['nombre_joueurs_max'] return self.cleaned_data['nombre_joueurs_max']
@ -42,4 +45,5 @@ class EmpruntForm(ModelForm):
class EditEmpruntForm(ModelForm): class EditEmpruntForm(ModelForm):
class Meta: class Meta:
model = Emprunt model = Emprunt
fields = ['media', 'permanencier_emprunt', 'permanencier_rendu', 'date_rendu'] fields = ['media', 'permanencier_emprunt', 'permanencier_rendu',
'date_rendu']

View File

@ -35,11 +35,23 @@ class Emprunt(models.Model):
media = models.ForeignKey('Media', on_delete=models.PROTECT) media = models.ForeignKey('Media', on_delete=models.PROTECT)
user = models.ForeignKey('users.User', on_delete=models.PROTECT) user = models.ForeignKey('users.User', on_delete=models.PROTECT)
date_emprunt = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S') date_emprunt = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S')
date_rendu = models.DateTimeField(help_text='%d/%m/%y %H:%M:%S', blank=True, null=True) date_rendu = models.DateTimeField(
permanencier_emprunt = models.ForeignKey('users.User', on_delete=models.PROTECT, help_text='%d/%m/%y %H:%M:%S',
related_name='user_permanencier_emprunt') blank=True,
permanencier_rendu = models.ForeignKey('users.User', on_delete=models.PROTECT, null=True,
related_name='user_permanencier_rendu', blank=True, null=True) )
permanencier_emprunt = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
related_name='user_permanencier_emprunt',
)
permanencier_rendu = models.ForeignKey(
'users.User',
on_delete=models.PROTECT,
related_name='user_permanencier_rendu',
blank=True,
null=True,
)
def __str__(self): def __str__(self):
return str(self.media) + str(self.user) return str(self.media) + str(self.user)
@ -63,7 +75,8 @@ class Jeu(models.Model):
duree = models.CharField(choices=DUREE, max_length=255) duree = models.CharField(choices=DUREE, max_length=255)
nombre_joueurs_min = models.IntegerField(validators=[MinValueValidator(1)]) nombre_joueurs_min = models.IntegerField(validators=[MinValueValidator(1)])
nombre_joueurs_max = models.IntegerField(validators=[MinValueValidator(1)]) nombre_joueurs_max = models.IntegerField(validators=[MinValueValidator(1)])
comment = models.CharField(help_text="Commentaire", max_length=255, blank=True, null=True) comment = models.CharField(help_text="Commentaire", max_length=255,
blank=True, null=True)
def __str__(self): def __str__(self):
return str(self.nom) return str(self.nom)

View File

@ -23,22 +23,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %} {% endcomment %}
{% if auteurs_list.paginator %} {% if auteurs_list.paginator %}
{% include "pagination.html" with list=auteurs_list %} {% include "pagination.html" with list=auteurs_list %}
{% endif %} {% endif %}
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Nom</th> <th>Nom</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for auteur in auteurs_list %} {% for auteur in auteurs_list %}
<tr> <tr>
<td>{{ auteur.nom }}</td> <td>{{ auteur.nom }}</td>
<td>{% if is_perm %}{% include 'buttons/edit.html' with href='media:edit-auteur' id=auteur.id %} <td>
{% include 'buttons/suppr.html' with href='media:del-auteur' id=auteur.id %}{% endif %} {% if is_perm %}
{% include 'buttons/history.html' with href='media:history' name='auteur' id=auteur.id %}</td> <a class="btn btn-primary btn-sm" role="button" title="Éditer"
href="{% url 'media:edit-auteur' auteur.id %}">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'media:del-auteur' auteur.id %}"
title="Supprimer">
<i class="glyphicon glyphicon-trash"></i>
</a>
{% endif %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -46,9 +46,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ jeu.nombre_joueurs_min }}</td> <td>{{ jeu.nombre_joueurs_min }}</td>
<td>{{ jeu.nombre_joueurs_max }}</td> <td>{{ jeu.nombre_joueurs_max }}</td>
<td>{{ jeu.comment }}</td> <td>{{ jeu.comment }}</td>
<td>{% if is_perm %}{% include 'buttons/edit.html' with href='media:edit-jeu' id=jeu.id %} <td>
{% include 'buttons/suppr.html' with href='media:del-jeu' id=jeu.id %}{% endif %} {% if is_perm %}
{% include 'buttons/history.html' with href='media:history' name='jeu' id=jeu.id %}</td> <a class="btn btn-primary btn-sm" role="button" title="Éditer"
href="{% url 'media:edit-jeu' jeu.id %}">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'media:del-jeu' jeu.id %}"
title="Supprimer">
<i class="glyphicon glyphicon-trash"></i>
</a>
{% endif %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -23,26 +23,35 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %} {% endcomment %}
{% if medias_list.paginator %} {% if medias_list.paginator %}
{% include "pagination.html" with list=medias_list %} {% include "pagination.html" with list=medias_list %}
{% endif %} {% endif %}
<table class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th>Titre</th> <th>Titre</th>
<th>Auteur</th> <th>Auteur</th>
<th>Cote</th> <th>Cote</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% for media in medias_list %} {% for media in medias_list %}
<tr> <tr>
<td>{{ media.titre }}</td> <td>{{ media.titre }}</td>
<td>{% for aut in media.auteur.all %}{{ aut }}, {% endfor %}</td> <td>{% for aut in media.auteur.all %}{{ aut }}, {% endfor %}</td>
<td>{{ media.cote }}</td> <td>{{ media.cote }}</td>
<td>{% if is_perm %}{% include 'buttons/edit.html' with href='media:edit-media' id=media.id %} <td>
{% include 'buttons/suppr.html' with href='media:del-media' id=media.id %}{% endif %} {% if is_perm %}
{% include 'buttons/history.html' with href='media:history' name='media' id=media.id %}</td> <a class="btn btn-primary btn-sm" role="button" title="Éditer"
href="{% url 'media:edit-media' media.id %}">
<i class="glyphicon glyphicon-edit"></i>
</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'media:del-media' media.id %}"
title="Supprimer">
<i class="glyphicon glyphicon-trash"></i>
</a>
{% endif %}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View File

@ -1,43 +0,0 @@
{% extends "base.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load bootstrap3 %}
{% block title %}Historique{% endblock %}
{% block content %}
<h2>Historique de {{ object }}</h2>
{% if reversions.paginator %}
<ul class="pagination nav navbar-nav">
{% if reversions.has_previous %}
<li><a href="?page={{ reversions.previous_page_number }}">Suivants</a></li>
{% endif %}
{% for page in reversions.paginator.page_range %}
<li class="{% if reversions.number == page %}active{% endif %}"><a
href="?page={{ page }}">{{ page }}</a></li>
{% endfor %}
{% if reversions.has_next %}
<li><a href="?page={{ reversions.next_page_number }}">Précédents</a></li>
{% endif %}
</ul>
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Cableur</th>
<th>Commentaire</th>
</tr>
</thead>
{% for rev in reversions %}
<tr>
<td>{{ rev.revision.date_created }}</td>
<td>{{ rev.revision.user }}</td>
<td>{{ rev.revision.comment }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

View File

@ -8,25 +8,28 @@ from . import views
urlpatterns = [ urlpatterns = [
url(r'^add_auteur/$', views.add_auteur, name='add-auteur'), url(r'^add_auteur/$', views.add_auteur, name='add-auteur'),
url(r'^edit_auteur/(?P<auteurid>[0-9]+)$', views.edit_auteur, name='edit-auteur'), url(r'^edit_auteur/(?P<auteurid>[0-9]+)$', views.edit_auteur,
url(r'^del_auteur/(?P<auteurid>[0-9]+)$', views.del_auteur, name='del-auteur'), name='edit-auteur'),
url(r'^del_auteur/(?P<auteurid>[0-9]+)$', views.del_auteur,
name='del-auteur'),
url(r'^index_auteurs/$', views.index_auteurs, name='index-auteurs'), url(r'^index_auteurs/$', views.index_auteurs, name='index-auteurs'),
url(r'^history/(?P<object>auteur)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^add_jeu/$', views.add_jeu, name='add-jeu'), url(r'^add_jeu/$', views.add_jeu, name='add-jeu'),
url(r'^edit_jeu/(?P<jeuid>[0-9]+)$', views.edit_jeu, name='edit-jeu'), url(r'^edit_jeu/(?P<jeuid>[0-9]+)$', views.edit_jeu, name='edit-jeu'),
url(r'^del_jeu/(?P<jeuid>[0-9]+)$', views.del_jeu, name='del-jeu'), url(r'^del_jeu/(?P<jeuid>[0-9]+)$', views.del_jeu, name='del-jeu'),
url(r'^index_jeux/$', views.index_jeux, name='index-jeux'), url(r'^index_jeux/$', views.index_jeux, name='index-jeux'),
url(r'^history/(?P<object>jeu)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^add_media/$', views.add_media, name='add-media'), url(r'^add_media/$', views.add_media, name='add-media'),
url(r'^edit_media/(?P<mediaid>[0-9]+)$', views.edit_media, name='edit-media'), url(r'^edit_media/(?P<mediaid>[0-9]+)$', views.edit_media,
name='edit-media'),
url(r'^del_media/(?P<mediaid>[0-9]+)$', views.del_media, name='del-media'), url(r'^del_media/(?P<mediaid>[0-9]+)$', views.del_media, name='del-media'),
url(r'^index_medias/$', views.index_medias, name='index-medias'), url(r'^index_medias/$', views.index_medias, name='index-medias'),
url(r'^history/(?P<object>media)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^add_emprunt/(?P<userid>[0-9]+)$', views.add_emprunt,
url(r'^add_emprunt/(?P<userid>[0-9]+)$', views.add_emprunt, name='add-emprunt'), name='add-emprunt'),
url(r'^retour_emprunt/(?P<empruntid>[0-9]+)$', views.retour_emprunt, name='retour-emprunt'), url(r'^retour_emprunt/(?P<empruntid>[0-9]+)$', views.retour_emprunt,
url(r'^edit_emprunt/(?P<empruntid>[0-9]+)$', views.edit_emprunt, name='edit-emprunt'), name='retour-emprunt'),
url(r'^del_emprunt/(?P<empruntid>[0-9]+)$', views.del_emprunt, name='del-emprunt'), url(r'^edit_emprunt/(?P<empruntid>[0-9]+)$', views.edit_emprunt,
name='edit-emprunt'),
url(r'^del_emprunt/(?P<empruntid>[0-9]+)$', views.del_emprunt,
name='del-emprunt'),
url(r'^index_emprunts/$', views.index, name='index'), url(r'^index_emprunts/$', views.index, name='index'),
url(r'^history/(?P<object>emprunt)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]

View File

@ -10,7 +10,6 @@ from django.shortcuts import render, redirect
from django.template.context_processors import csrf from django.template.context_processors import csrf
from django.utils import timezone from django.utils import timezone
from reversion import revisions as reversion from reversion import revisions as reversion
from reversion.models import Version
from med.settings import PAGINATION_NUMBER from med.settings import PAGINATION_NUMBER
from users.models import User from users.models import User
@ -25,7 +24,7 @@ def form(ctx, template, request):
@login_required @login_required
@permission_required('perm') @permission_required('media.add_auteur')
def add_auteur(request): def add_auteur(request):
auteur = AuteurForm(request.POST or None) auteur = AuteurForm(request.POST or None)
if auteur.is_valid(): if auteur.is_valid():
@ -39,7 +38,7 @@ def add_auteur(request):
@login_required @login_required
@permission_required('perm') @permission_required('media.edit_auteur')
def edit_auteur(request, auteurid): def edit_auteur(request, auteurid):
try: try:
auteur_instance = Auteur.objects.get(pk=auteurid) auteur_instance = Auteur.objects.get(pk=auteurid)
@ -51,14 +50,15 @@ def edit_auteur(request, auteurid):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
auteur.save() auteur.save()
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in auteur.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for field in auteur.changed_data))
messages.success(request, "Auteur modifié") messages.success(request, "Auteur modifié")
return redirect("/media/index_auteurs/") return redirect("/media/index_auteurs/")
return form({'mediaform': auteur}, 'media/media.html', request) return form({'mediaform': auteur}, 'media/media.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.delete_auteur')
def del_auteur(request, auteurid): def del_auteur(request, auteurid):
try: try:
auteur_instance = Auteur.objects.get(pk=auteurid) auteur_instance = Auteur.objects.get(pk=auteurid)
@ -71,11 +71,12 @@ def del_auteur(request, auteurid):
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "L'auteur a été détruit") messages.success(request, "L'auteur a été détruit")
return redirect("/media/index_auteurs") return redirect("/media/index_auteurs")
return form({'objet': auteur_instance, 'objet_name': 'auteur'}, 'media/delete.html', request) return form({'objet': auteur_instance, 'objet_name': 'auteur'},
'media/delete.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.add_media')
def add_media(request): def add_media(request):
media = MediaForm(request.POST or None) media = MediaForm(request.POST or None)
if media.is_valid(): if media.is_valid():
@ -89,7 +90,7 @@ def add_media(request):
@login_required @login_required
@permission_required('perm') @permission_required('media.edit_media')
def edit_media(request, mediaid): def edit_media(request, mediaid):
try: try:
media_instance = Media.objects.get(pk=mediaid) media_instance = Media.objects.get(pk=mediaid)
@ -101,14 +102,15 @@ def edit_media(request, mediaid):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
media.save() media.save()
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in media.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for field in media.changed_data))
messages.success(request, "Media modifié") messages.success(request, "Media modifié")
return redirect("/media/index_medias/") return redirect("/media/index_medias/")
return form({'mediaform': media}, 'media/media.html', request) return form({'mediaform': media}, 'media/media.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.delete_media')
def del_media(request, mediaid): def del_media(request, mediaid):
try: try:
media_instance = Media.objects.get(pk=mediaid) media_instance = Media.objects.get(pk=mediaid)
@ -121,11 +123,12 @@ def del_media(request, mediaid):
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "Le media a été détruit") messages.success(request, "Le media a été détruit")
return redirect("/media/index_medias") return redirect("/media/index_medias")
return form({'objet': media_instance, 'objet_name': 'media'}, 'media/delete.html', request) return form({'objet': media_instance, 'objet_name': 'media'},
'media/delete.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.add_jeu')
def add_jeu(request): def add_jeu(request):
jeu = JeuForm(request.POST or None) jeu = JeuForm(request.POST or None)
if jeu.is_valid(): if jeu.is_valid():
@ -139,7 +142,7 @@ def add_jeu(request):
@login_required @login_required
@permission_required('perm') @permission_required('media.edit_jeu')
def edit_jeu(request, jeuid): def edit_jeu(request, jeuid):
try: try:
jeu_instance = Jeu.objects.get(pk=jeuid) jeu_instance = Jeu.objects.get(pk=jeuid)
@ -151,14 +154,15 @@ def edit_jeu(request, jeuid):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
jeu.save() jeu.save()
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in jeu.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for field in jeu.changed_data))
messages.success(request, "Media modifié") messages.success(request, "Media modifié")
return redirect("/media/index_jeux/") return redirect("/media/index_jeux/")
return form({'mediaform': jeu}, 'media/media.html', request) return form({'mediaform': jeu}, 'media/media.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.delete_jeu')
def del_jeu(request, jeuid): def del_jeu(request, jeuid):
try: try:
jeu_instance = Jeu.objects.get(pk=jeuid) jeu_instance = Jeu.objects.get(pk=jeuid)
@ -171,20 +175,23 @@ def del_jeu(request, jeuid):
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "Le jeu a été détruit") messages.success(request, "Le jeu a été détruit")
return redirect("/media/index_jeux") return redirect("/media/index_jeux")
return form({'objet': jeu_instance, 'objet_name': 'jeu'}, 'media/delete.html', request) return form({'objet': jeu_instance, 'objet_name': 'jeu'},
'media/delete.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.add_emprunt')
def add_emprunt(request, userid): def add_emprunt(request, userid):
try: try:
user = User.objects.get(pk=userid) user = User.objects.get(pk=userid)
except User.DoesNotExist: except User.DoesNotExist:
messages.error(request, u"Entrée inexistante") messages.error(request, u"Entrée inexistante")
return redirect("/media/index_emprunts/") return redirect("/media/index_emprunts/")
emprunts_en_cours = Emprunt.objects.filter(date_rendu=None, user=user).count() emprunts_en_cours = Emprunt.objects.filter(date_rendu=None,
user=user).count()
if emprunts_en_cours >= user.maxemprunt: if emprunts_en_cours >= user.maxemprunt:
messages.error(request, "Maximum d'emprunts atteint de l'user %s" % user.maxemprunt) messages.error(request,
"Maximum d'emprunts atteint de l'user %s" % user.maxemprunt)
return redirect("/media/index_emprunts/") return redirect("/media/index_emprunts/")
emprunt = EmpruntForm(request.POST or None) emprunt = EmpruntForm(request.POST or None)
if emprunt.is_valid(): if emprunt.is_valid():
@ -202,7 +209,7 @@ def add_emprunt(request, userid):
@login_required @login_required
@permission_required('perm') @permission_required('media.edit_emprunt')
def edit_emprunt(request, empruntid): def edit_emprunt(request, empruntid):
try: try:
emprunt_instance = Emprunt.objects.get(pk=empruntid) emprunt_instance = Emprunt.objects.get(pk=empruntid)
@ -214,14 +221,15 @@ def edit_emprunt(request, empruntid):
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
emprunt.save() emprunt.save()
reversion.set_user(request.user) reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in emprunt.changed_data)) reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for field in emprunt.changed_data))
messages.success(request, "Emprunt modifié") messages.success(request, "Emprunt modifié")
return redirect("/media/index_emprunts/") return redirect("/media/index_emprunts/")
return form({'mediaform': emprunt}, 'media/media.html', request) return form({'mediaform': emprunt}, 'media/media.html', request)
@login_required @login_required
@permission_required('perm') @permission_required('media.edit_emprunt')
def retour_emprunt(request, empruntid): def retour_emprunt(request, empruntid):
try: try:
emprunt_instance = Emprunt.objects.get(pk=empruntid) emprunt_instance = Emprunt.objects.get(pk=empruntid)
@ -238,7 +246,7 @@ def retour_emprunt(request, empruntid):
@login_required @login_required
@permission_required('perm') @permission_required('media.delete_emprunt')
def del_emprunt(request, empruntid): def del_emprunt(request, empruntid):
try: try:
emprunt_instance = Emprunt.objects.get(pk=empruntid) emprunt_instance = Emprunt.objects.get(pk=empruntid)
@ -251,7 +259,8 @@ def del_emprunt(request, empruntid):
reversion.set_user(request.user) reversion.set_user(request.user)
messages.success(request, "L'emprunt a été détruit") messages.success(request, "L'emprunt a été détruit")
return redirect("/media/index_emprunts") return redirect("/media/index_emprunts")
return form({'objet': emprunt_instance, 'objet_name': 'emprunt'}, 'media/delete.html', request) return form({'objet': emprunt_instance, 'objet_name': 'emprunt'},
'media/delete.html', request)
@login_required @login_required
@ -283,7 +292,8 @@ def index_auteurs(request):
except EmptyPage: except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results. # If page is out of range (e.g. 9999), deliver last page of results.
auteurs_list = paginator.page(paginator.num_pages) auteurs_list = paginator.page(paginator.num_pages)
return render(request, 'media/index_auteurs.html', {'auteurs_list': auteurs_list}) return render(request, 'media/index_auteurs.html',
{'auteurs_list': auteurs_list})
@login_required @login_required
@ -299,7 +309,8 @@ def index_medias(request):
except EmptyPage: except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results. # If page is out of range (e.g. 9999), deliver last page of results.
medias_list = paginator.page(paginator.num_pages) medias_list = paginator.page(paginator.num_pages)
return render(request, 'media/index_medias.html', {'medias_list': medias_list}) return render(request, 'media/index_medias.html',
{'medias_list': medias_list})
@login_required @login_required
@ -308,7 +319,8 @@ def index(request):
emprunts_list = Emprunt.objects.all() emprunts_list = Emprunt.objects.all()
else: else:
emprunts_list = Emprunt.objects.filter(user=request.user) emprunts_list = Emprunt.objects.filter(user=request.user)
paginator = Paginator(emprunts_list.order_by('date_emprunt').reverse(), PAGINATION_NUMBER) paginator = Paginator(emprunts_list.order_by('date_emprunt').reverse(),
PAGINATION_NUMBER)
page = request.GET.get('page') page = request.GET.get('page')
try: try:
emprunts_list = paginator.page(page) emprunts_list = paginator.page(page)
@ -318,44 +330,5 @@ def index(request):
except EmptyPage: except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results. # If page is out of range (e.g. 9999), deliver last page of results.
emprunts_list = paginator.page(paginator.num_pages) emprunts_list = paginator.page(paginator.num_pages)
return render(request, 'media/index_emprunts.html', {'emprunts_list': emprunts_list}) return render(request, 'media/index_emprunts.html',
{'emprunts_list': emprunts_list})
@login_required
def history(request, object, id):
if object == 'auteur':
try:
object_instance = Auteur.objects.get(pk=id)
except Auteur.DoesNotExist:
messages.error(request, "Auteur inexistant")
return redirect("/media/index_auteurs")
elif object == 'media':
try:
object_instance = Media.objects.get(pk=id)
except Media.DoesNotExist:
messages.error(request, "Media inexistant")
return redirect("/media/index_medias")
elif object == 'emprunt':
try:
object_instance = Emprunt.objects.get(pk=id)
except Emprunt.DoesNotExist:
messages.error(request, "Emprunt inexistant")
return redirect("/media/index_emprunts")
elif object == 'jeu':
try:
object_instance = Jeu.objects.get(pk=id)
except Jeu.DoesNotExist:
messages.error(request, "Jeu inexistant")
return redirect("/media/index_jeux")
reversions = Version.objects.get_for_object(object_instance)
paginator = Paginator(reversions, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
reversions = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
reversions = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
reversions = paginator.page(paginator.num_pages)
return render(request, 'media/history.html', {'reversions': reversions, 'object': object_instance})

View File

@ -1,27 +0,0 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<a class="btn btn-primary btn-sm" role="button" href="{% url href id %}" title="{{ desc|default:"Ajouter" }}">
<i class="glyphicon glyphicon-plus"></i>
</a>

View File

@ -1,27 +0,0 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<a class="btn btn-primary btn-sm" role="button" title="{{ desc|default:"Éditer" }}" href="{% url href id %}">
<i class="glyphicon glyphicon-edit"></i>
</a>

View File

@ -1,28 +0,0 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url href name id %}">
<i class="glyphicon glyphicon-time"></i>
</a>

View File

@ -1,27 +0,0 @@
{% comment %}
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
se veut agnostique au réseau considéré, de manière à être installable en
quelques clics.
Copyright © 2017 Gabriel Détraz
Copyright © 2017 Goulven Kermarec
Copyright © 2017 Augustin Lemesle
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<a class="btn btn-danger btn-sm" role="button" href="{% url href id %}" title="{{ desc|default:"Supprimer" }}">
<i class="glyphicon glyphicon-trash"></i>
</a>