Gestion des jeux
This commit is contained in:
parent
2b8ae80b4d
commit
b2a653dd97
|
@ -3,7 +3,7 @@ from reversion.admin import VersionAdmin
|
|||
from django.contrib import admin
|
||||
from django.contrib.auth.models import Group
|
||||
|
||||
from .models import Auteur, Emprunt, Media
|
||||
from .models import Auteur, Emprunt, Media, Jeu
|
||||
|
||||
class AuteurAdmin(VersionAdmin):
|
||||
list_display = ('nom',)
|
||||
|
@ -14,7 +14,10 @@ class MediaAdmin(VersionAdmin):
|
|||
class EmpruntAdmin(VersionAdmin):
|
||||
list_display = ('media','user','date_emprunt', 'date_rendu', 'permanencier_emprunt', 'permanencier_rendu')
|
||||
|
||||
class JeuAdmin(VersionAdmin):
|
||||
list_display = ('nom','proprietaire', 'duree', 'nombre_joueurs_min', 'nombre_joueurs_max', 'comment')
|
||||
|
||||
admin.site.register(Auteur, AuteurAdmin)
|
||||
admin.site.register(Media, MediaAdmin)
|
||||
admin.site.register(Emprunt, EmpruntAdmin)
|
||||
admin.site.register(Jeu, JeuAdmin)
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
from django.forms import ModelForm, Form, ValidationError
|
||||
from django import forms
|
||||
from .models import Auteur, Media, Emprunt
|
||||
from .models import Auteur, Media, Jeu, Emprunt
|
||||
|
||||
class AuteurForm(ModelForm):
|
||||
class Meta:
|
||||
|
@ -34,6 +34,11 @@ class MediaForm(ModelForm):
|
|||
model = Media
|
||||
fields = '__all__'
|
||||
|
||||
class JeuForm(ModelForm):
|
||||
class Meta:
|
||||
model = Jeu
|
||||
fields = '__all__'
|
||||
|
||||
class EmpruntForm(ModelForm):
|
||||
class Meta:
|
||||
model = Emprunt
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
{% 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 %}
|
||||
|
||||
{% if jeux_list.paginator %}
|
||||
{% include "pagination.html" with list=jeux_list %}
|
||||
{% endif %}
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Proprietaire</th>
|
||||
<th>Durée</th>
|
||||
<th>Joueurs min</th>
|
||||
<th>Joueurs max</th>
|
||||
<th>Comment</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for jeu in jeux_list %}
|
||||
<tr>
|
||||
<td>{{ jeu.nom }}</td>
|
||||
<td>{{ jeu.proprietaire }}</td>
|
||||
<td>{{ jeu.duree }}</td>
|
||||
<td>{{ jeu.nombre_joueurs_min }}</td>
|
||||
<td>{{ jeu.nombre_joueurs_max }}</td>
|
||||
<td>{{ jeu.comment }}</td>
|
||||
<td>{% include 'buttons/edit.html' with href='media:edit-jeu' id=jeu.id %}
|
||||
{% include 'buttons/suppr.html' with href='media:del-jeu' id=jeu.id %}
|
||||
{% include 'buttons/history.html' with href='media:history' name='jeu' id=jeu.id %}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
|
@ -0,0 +1,39 @@
|
|||
{% extends "media/sidebar.html" %}
|
||||
{% 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 %}
|
||||
|
||||
{% load bootstrap3 %}
|
||||
|
||||
{% block title %}Jeux{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Liste des jeux</h2>
|
||||
{% if is_perm %}
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'media:add-jeu' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un jeu</a>
|
||||
{% endif %}
|
||||
{% include "media/aff_jeux.html" with jeux_list=jeux_list %}
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
{% endblock %}
|
|
@ -37,5 +37,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
<i class="glyphicon glyphicon-list"></i>
|
||||
Medias
|
||||
</a>
|
||||
<a class="list-group-item list-group-item-info" href="{% url "media:index-jeux" %}">
|
||||
<i class="glyphicon glyphicon-list"></i>
|
||||
Jeux
|
||||
</a>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -30,6 +30,11 @@ urlpatterns = [
|
|||
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'^history/(?P<object>auteur)/(?P<id>[0-9]+)$', views.history, name='history'),
|
||||
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'^del_jeu/(?P<jeuid>[0-9]+)$', views.del_jeu, name='del-jeu'),
|
||||
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'^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'),
|
||||
|
|
|
@ -9,8 +9,8 @@ from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
|||
from django.contrib.auth import authenticate, login
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils import timezone
|
||||
from .forms import AuteurForm, MediaForm, EmpruntForm, EditEmpruntForm
|
||||
from .models import Auteur, Media, Emprunt
|
||||
from .forms import AuteurForm, MediaForm, JeuForm, EmpruntForm, EditEmpruntForm
|
||||
from .models import Auteur, Media, Jeu, Emprunt
|
||||
from users.models import User
|
||||
from django.db import transaction
|
||||
from reversion import revisions as reversion
|
||||
|
@ -118,6 +118,53 @@ def del_media(request, mediaid):
|
|||
return redirect("/media/index_medias")
|
||||
return form({'objet': media_instance, 'objet_name': 'media'}, 'media/delete.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('perm')
|
||||
def add_jeu(request):
|
||||
jeu = JeuForm(request.POST or None)
|
||||
if jeu.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
jeu.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Création")
|
||||
messages.success(request, "Le jeu a été ajouté")
|
||||
return redirect("/media/index_jeux/")
|
||||
return form({'mediaform': jeu}, 'media/media.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('perm')
|
||||
def edit_jeu(request, jeuid):
|
||||
try:
|
||||
jeu_instance = Jeu.objects.get(pk=jeuid)
|
||||
except Jeu.DoesNotExist:
|
||||
messages.error(request, u"Entrée inexistante" )
|
||||
return redirect("/media/index_jeux/")
|
||||
jeu = JeuForm(request.POST or None, instance=jeu_instance)
|
||||
if jeu.is_valid():
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
jeu.save()
|
||||
reversion.set_user(request.user)
|
||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in jeu.changed_data))
|
||||
messages.success(request, "Media modifié")
|
||||
return redirect("/media/index_jeux/")
|
||||
return form({'mediaform': jeu}, 'media/media.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('perm')
|
||||
def del_jeu(request, jeuid):
|
||||
try:
|
||||
jeu_instance = Jeu.objects.get(pk=jeuid)
|
||||
except Jeu.DoesNotExist:
|
||||
messages.error(request, u"Entrée inexistante" )
|
||||
return redirect("/media/index_jeux/")
|
||||
if request.method == "POST":
|
||||
with transaction.atomic(), reversion.create_revision():
|
||||
jeu_instance.delete()
|
||||
reversion.set_user(request.user)
|
||||
messages.success(request, "Le jeu a été détruit")
|
||||
return redirect("/media/index_jeux")
|
||||
return form({'objet': jeu_instance, 'objet_name': 'jeu'}, 'media/delete.html', request)
|
||||
|
||||
@login_required
|
||||
@permission_required('perm')
|
||||
def add_emprunt(request, userid):
|
||||
|
@ -197,6 +244,21 @@ def del_emprunt(request, empruntid):
|
|||
|
||||
|
||||
|
||||
@login_required
|
||||
def index_jeux(request):
|
||||
jeux_list = Jeu.objects.all()
|
||||
paginator = Paginator(jeux_list, PAGINATION_NUMBER)
|
||||
page = request.GET.get('page')
|
||||
try:
|
||||
jeux_list = paginator.page(page)
|
||||
except PageNotAnInteger:
|
||||
# If page is not an integer, deliver first page.
|
||||
jeux_list = paginator.page(1)
|
||||
except EmptyPage:
|
||||
# If page is out of range (e.g. 9999), deliver last page of results.
|
||||
jeux_list = paginator.page(paginator.num_pages)
|
||||
return render(request, 'media/index_jeux.html', {'jeux_list':jeux_list})
|
||||
|
||||
@login_required
|
||||
def index_auteurs(request):
|
||||
auteurs_list = Auteur.objects.all()
|
||||
|
@ -267,6 +329,12 @@ def history(request, object, 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')
|
||||
|
|
Loading…
Reference in New Issue