1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2024-12-24 03:02:24 +00:00

Remove old views

This commit is contained in:
Alexandre Iooss 2019-08-09 22:26:32 +02:00
parent b4cfb8d3b6
commit 7f2f22f156
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
16 changed files with 56 additions and 363 deletions

View File

@ -2,32 +2,12 @@
# Copyright (C) 2017-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django import forms
from django.forms import ModelForm
from .models import Jeu, Emprunt
class JeuForm(ModelForm):
class Meta:
model = Jeu
fields = '__all__'
def clean_nombre_joueurs_max(self):
max_player = self.cleaned_data['nombre_joueurs_max']
if max_player < self.cleaned_data['nombre_joueurs_min']:
raise forms.ValidationError("Max ne peut être inférieur à min")
return max_player
from .models import Emprunt
class EmpruntForm(ModelForm):
class Meta:
model = Emprunt
fields = ['media']
class EditEmpruntForm(ModelForm):
class Meta:
model = Emprunt
fields = ['media', 'permanencier_emprunt', 'permanencier_rendu',
'date_rendu']

View File

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-08 18:54+0200\n"
"POT-Creation-Date: 2019-08-09 22:25+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -115,4 +115,8 @@ msgstr "Pas d'emprunts en cours."
#: templates/media/index.html:77
msgid "You are not logged in."
msgstr "Vous n'êtes pas identifié."
msgstr "Vous n'êtes pas identifié."
#: templates/media/media.html:37
msgid "Save"
msgstr "Enregistrer"

View File

@ -1,20 +0,0 @@
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% if auteurs_list.paginator %}
{% include "pagination.html" with list=auteurs_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>Nom</th>
</tr>
</thead>
{% for auteur in auteurs_list %}
<tr>
<td>{{ auteur.nom }}</td>
</tr>
{% endfor %}
</table>

View File

@ -1,44 +0,0 @@
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% if emprunts_list.paginator %}
{% include "pagination.html" with list=emprunts_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>Media</th>
<th>Utilisateur</th>
<th>Date emprunt</th>
<th>Permanencier emprunt</th>
<th>Date rendu</th>
<th>Permanencier rendu</th>
<th></th>
</tr>
</thead>
{% for emprunt in emprunts_list %}
<tr>
<td>{{ emprunt.media }}</td>
<td>{{ emprunt.user }}</td>
<td>{{ emprunt.date_emprunt }}</td>
<td>{{ emprunt.permanencier_emprunt }}</td>
<td>
{% if not emprunt.date_rendu %}
{% if perms.media.change_emprunt %}
<a class="btn btn-primary btn-sm" href="{% url 'media:retour-emprunt' emprunt.id %}">Retour</a>
{% endif %}
{% else %}
{{ emprunt.date_rendu }}
{% endif %}
</td>
<td>{{ emprunt.permanencier_rendu }}</td>
<td>
{% if perms.media.change_emprunt %}
<a href="{% url 'media:edit-emprunt' emprunt.id %}">Editer</a>
{% endif %}
</td>
</tr>
{% endfor %}
</table>

View File

@ -1,30 +0,0 @@
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% 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>
</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>
</tr>
{% endfor %}
</table>

View File

@ -1,24 +0,0 @@
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% if medias_list.paginator %}
{% include "pagination.html" with list=medias_list %}
{% endif %}
<table class="table table-striped">
<thead>
<tr>
<th>Titre</th>
<th>Auteur</th>
<th>Cote</th>
</tr>
</thead>
{% for media in medias_list %}
<tr>
<td>{{ media.titre }}</td>
<td>{% for aut in media.auteur.all %}{{ aut }}, {% endfor %}</td>
<td>{{ media.cote }}</td>
</tr>
{% endfor %}
</table>

View File

@ -1,16 +0,0 @@
{% extends "media/sidebar.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load i18n %}
{% block title %}Auteurs{% endblock %}
{% block content %}
<h2>Liste des auteurs</h2>
{% if user.is_staff %}
<a class="changelink" href="{% url 'admin:media_auteur_changelist' %}">{% trans 'Go to admin' %}</a>
{% endif %}
{% include "media/aff_auteurs.html" with auteurs_list=auteurs_list %}
{% endblock %}

View File

@ -1,16 +0,0 @@
{% extends "media/sidebar.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load i18n %}
{% block title %}Emprunts{% endblock %}
{% block content %}
<h2>Liste des emprunts</h2>
{% if user.is_staff %}
<a class="changelink" href="{% url 'admin:media_emprunt_changelist' %}">{% trans 'Go to admin' %}</a>
{% endif %}
{% include "media/aff_emprunts.html" with emprunts_list=emprunts_list %}
{% endblock %}

View File

@ -1,16 +0,0 @@
{% extends "media/sidebar.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load i18n %}
{% block title %}Jeux{% endblock %}
{% block content %}
<h2>Liste des jeux</h2>
{% if user.is_staff %}
<a class="changelink" href="{% url 'admin:media_jeu_changelist' %}">{% trans 'Go to admin' %}</a>
{% endif %}
{% include "media/aff_jeux.html" with jeux_list=jeux_list %}
{% endblock %}

View File

@ -1,16 +0,0 @@
{% extends "media/sidebar.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load i18n %}
{% block title %}Media{% endblock %}
{% block content %}
<h2>Liste des medias</h2>
{% if user.is_staff %}
<a class="changelink" href="{% url 'admin:media_media_changelist' %}">{% trans 'Go to admin' %}</a>
{% endif %}
{% include "media/aff_medias.html" with medias_list=medias_list %}
{% endblock %}

View File

@ -1,18 +1,40 @@
{% extends "media/sidebar.html" %}
{% extends "base_form.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% load bootstrap3 %}
{% block title %}Création et modification de media{% endblock %}
{% load i18n %}
{% block content %}
{% bootstrap_form_errors mediaform %}
<form method="post" onsubmit="window.onbeforeunload=null">{% csrf_token %}
{% if form.non_field_errors %}
<p class="errornote">
{% for error in form.non_field_errors %}
{{ error }}
{% endfor %}
</p>
{% endif %}
<fieldset class="module aligned">
{% for field in form %}
<div class="form-row{% if field.errors %} errors{% endif %}">
{{ field.errors }}
<div>
{{ field.label_tag }}
{% if field.is_readonly %}
<div class="readonly">{{ field.contents }}</div>
{% else %}
{{ field }}
{% endif %}
{% if field.field.help_text %}
<div class="help">{{ field.field.help_text|safe }}</div>
{% endif %}
</div>
</div>
{% endfor %}
</fieldset>
<form class="form" method="post">
{% csrf_token %}
{% bootstrap_form mediaform %}
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
<div class="submit-row">
<input class="default" type="submit" value="{% trans 'Save' %}">
</div>
</form>
{% endblock %}

View File

@ -1,24 +0,0 @@
{% extends "base.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
{% block sidebar %}
<a class="list-group-item list-group-item-info" href="{% url "media:index" %}">
<i class="glyphicon glyphicon-list"></i>
Emprunts
</a>
<a class="list-group-item list-group-item-info" href="{% url "media:index-auteurs" %}">
<i class="glyphicon glyphicon-list"></i>
Auteurs
</a>
<a class="list-group-item list-group-item-info" href="{% url "media:index-medias" %}">
<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 %}

View File

@ -7,14 +7,8 @@ from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^index_auteurs/$', views.index_auteurs, name='index-auteurs'),
url(r'^index_jeux/$', views.index_jeux, name='index-jeux'),
url(r'^index_medias/$', views.index_medias, name='index-medias'),
url(r'^add_emprunt/(?P<userid>[0-9]+)$', views.add_emprunt,
name='add-emprunt'),
url(r'^retour_emprunt/(?P<empruntid>[0-9]+)$', views.retour_emprunt,
name='retour-emprunt'),
url(r'^edit_emprunt/(?P<empruntid>[0-9]+)$', views.edit_emprunt,
name='edit-emprunt'),
url(r'^index_emprunts/$', views.index_emprunt, name='index'),
]

View File

@ -4,17 +4,15 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required, permission_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db import transaction
from django.shortcuts import render, redirect
from django.template.context_processors import csrf
from django.utils import timezone
from reversion import revisions as reversion
from med.settings import PAGINATION_NUMBER
from users.models import User
from .forms import EmpruntForm, EditEmpruntForm
from .models import Auteur, Media, Jeu, Emprunt
from .forms import EmpruntForm
from .models import Emprunt
def form(ctx, template, request):
@ -49,27 +47,7 @@ def add_emprunt(request, userid):
reversion.set_comment("Création")
messages.success(request, "Le emprunt a été ajouté")
return redirect("/media/index_emprunts/")
return form({'mediaform': emprunt}, 'media/media.html', request)
@login_required
@permission_required('media.change_emprunt')
def edit_emprunt(request, empruntid):
try:
emprunt_instance = Emprunt.objects.get(pk=empruntid)
except Emprunt.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect("/media/index_emprunts/")
emprunt = EditEmpruntForm(request.POST or None, instance=emprunt_instance)
if emprunt.is_valid():
with transaction.atomic(), reversion.create_revision():
emprunt.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(
field for field in emprunt.changed_data))
messages.success(request, "Emprunt modifié")
return redirect("/media/index_emprunts/")
return form({'mediaform': emprunt}, 'media/media.html', request)
return form({'form': emprunt}, 'media/media.html', request)
@login_required
@ -89,77 +67,6 @@ def retour_emprunt(request, empruntid):
return redirect("/media/index_emprunts/")
@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().order_by('nom')
paginator = Paginator(auteurs_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
auteurs_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
auteurs_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
auteurs_list = paginator.page(paginator.num_pages)
return render(request, 'media/index_auteurs.html',
{'auteurs_list': auteurs_list})
@login_required
def index_medias(request):
medias_list = Media.objects.all()
paginator = Paginator(medias_list, PAGINATION_NUMBER)
page = request.GET.get('page')
try:
medias_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
medias_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
medias_list = paginator.page(paginator.num_pages)
return render(request, 'media/index_medias.html',
{'medias_list': medias_list})
@login_required
def index_emprunt(request):
if request.user.has_perms(['perm']):
emprunts_list = Emprunt.objects.all()
else:
emprunts_list = Emprunt.objects.filter(user=request.user)
paginator = Paginator(emprunts_list.order_by('date_emprunt').reverse(),
PAGINATION_NUMBER)
page = request.GET.get('page')
try:
emprunts_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
emprunts_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
emprunts_list = paginator.page(paginator.num_pages)
return render(request, 'media/index_emprunts.html',
{'emprunts_list': emprunts_list})
def index(request):
"""
Home page with user's borrowed items

View File

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-08 20:49+0200\n"
"POT-Creation-Date: 2019-08-09 22:14+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,27 +17,27 @@ msgstr ""
msgid "Welcome,"
msgstr ""
#: templates/admin/base_site.html:29
msgid "Library"
#: templates/admin/base_site.html:30
msgid "Explore the library"
msgstr "Explorer la médiatèque"
#: templates/admin/base_site.html:42 templates/admin/base_site.html:61
msgid "View admin"
msgstr "Administration"
#: templates/admin/base_site.html:50 templates/admin/base_site.html:69
msgid "Explore database"
msgstr "Explorer la base de données"
#: templates/admin/base_site.html:54
#: templates/admin/base_site.html:62
msgid "Documentation"
msgstr ""
#: templates/admin/base_site.html:63
#: templates/admin/base_site.html:71
msgid "Log out"
msgstr ""
#: templates/admin/base_site.html:65 templates/registration/login.html:8
#: templates/admin/base_site.html:73 templates/registration/login.html:8
msgid "Log in"
msgstr ""
#: templates/registration/logged_out.html:9
#: templates/base.html:10 templates/registration/logged_out.html:9
#: templates/registration/password_change_done.html:9
#: templates/registration/password_change_form.html:9
#: templates/registration/password_reset_complete.html:9
@ -89,3 +89,6 @@ msgstr ""
#, python-format
msgid "The %(site_name)s team"
msgstr ""
#~ msgid "View admin"
#~ msgstr "Administration"

View File

@ -25,17 +25,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endif %}
{% endblock %}
{% block userlinks %}
{# Link to our apps outside of admin #}
<span class="dropdown">
<a href="{% url 'media:index' %}">{% trans 'Library' %}</a>
<span class="dropdown-content">
<a href="{% url "media:index" %}">Emprunts</a>
<a href="{% url "media:index-auteurs" %}">Auteurs</a>
<a href="{% url "media:index-medias" %}">Medias</a>
<a href="{% url "media:index-jeux" %}">Jeux</a>
</span>
</span> /
{% if user.is_authenticated %}
{% if perms.users.add_user %}
<a href="{% url "users:new-user" %}">Nouveau utilisateur</a> /
@ -47,7 +36,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% if available_apps %}
{# When in admin site, list all admin pages and documentation #}
<span class="dropdown">
<a href="{% url 'admin:index' %}">{% trans 'View admin' %}</a>
<a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a>
<span class="dropdown-content">
{% for app in available_apps %}
{% for model in app.models %}
@ -66,7 +55,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
</span> /
{% elif user.is_staff %}
{# When not in admin site, but user is staff then add a link #}
<a href="{% url 'admin:index' %}">{% trans 'View admin' %}</a> /
<a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a> /
{% endif %}
<a href="{% url 'logout' %}">{% trans 'Log out' %}</a>
{% else %}