From 7f2f22f1567a1309c6db9ca4b8a0d30035bc50de Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 9 Aug 2019 22:26:32 +0200 Subject: [PATCH] Remove old views --- media/forms.py | 22 +---- media/locale/fr/LC_MESSAGES/django.po | 8 +- media/templates/media/aff_auteurs.html | 20 ----- media/templates/media/aff_emprunts.html | 44 ---------- media/templates/media/aff_jeux.html | 30 ------- media/templates/media/aff_medias.html | 24 ------ media/templates/media/index_auteurs.html | 16 ---- media/templates/media/index_emprunts.html | 16 ---- media/templates/media/index_jeux.html | 16 ---- media/templates/media/index_medias.html | 16 ---- media/templates/media/media.html | 40 ++++++--- media/templates/media/sidebar.html | 24 ------ media/urls.py | 6 -- media/views.py | 99 +---------------------- theme/locale/fr/LC_MESSAGES/django.po | 23 +++--- theme/templates/admin/base_site.html | 15 +--- 16 files changed, 56 insertions(+), 363 deletions(-) delete mode 100644 media/templates/media/aff_auteurs.html delete mode 100644 media/templates/media/aff_emprunts.html delete mode 100644 media/templates/media/aff_jeux.html delete mode 100644 media/templates/media/aff_medias.html delete mode 100644 media/templates/media/index_auteurs.html delete mode 100644 media/templates/media/index_emprunts.html delete mode 100644 media/templates/media/index_jeux.html delete mode 100644 media/templates/media/index_medias.html delete mode 100644 media/templates/media/sidebar.html diff --git a/media/forms.py b/media/forms.py index 2c2b7bb..f47b4e9 100644 --- a/media/forms.py +++ b/media/forms.py @@ -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'] diff --git a/media/locale/fr/LC_MESSAGES/django.po b/media/locale/fr/LC_MESSAGES/django.po index ac3aad8..5284baf 100644 --- a/media/locale/fr/LC_MESSAGES/django.po +++ b/media/locale/fr/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \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é." \ No newline at end of file +msgstr "Vous n'êtes pas identifié." + +#: templates/media/media.html:37 +msgid "Save" +msgstr "Enregistrer" diff --git a/media/templates/media/aff_auteurs.html b/media/templates/media/aff_auteurs.html deleted file mode 100644 index e7b7762..0000000 --- a/media/templates/media/aff_auteurs.html +++ /dev/null @@ -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 %} - - - - - - - - {% for auteur in auteurs_list %} - - - - {% endfor %} -
Nom
{{ auteur.nom }}
diff --git a/media/templates/media/aff_emprunts.html b/media/templates/media/aff_emprunts.html deleted file mode 100644 index ab72aa2..0000000 --- a/media/templates/media/aff_emprunts.html +++ /dev/null @@ -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 %} - - - - - - - - - - - - - - {% for emprunt in emprunts_list %} - - - - - - - - - - {% endfor %} -
MediaUtilisateurDate empruntPermanencier empruntDate renduPermanencier rendu
{{ emprunt.media }}{{ emprunt.user }}{{ emprunt.date_emprunt }}{{ emprunt.permanencier_emprunt }} - {% if not emprunt.date_rendu %} - {% if perms.media.change_emprunt %} - Retour - {% endif %} - {% else %} - {{ emprunt.date_rendu }} - {% endif %} - {{ emprunt.permanencier_rendu }} - {% if perms.media.change_emprunt %} - Editer - {% endif %} -
diff --git a/media/templates/media/aff_jeux.html b/media/templates/media/aff_jeux.html deleted file mode 100644 index 6669de1..0000000 --- a/media/templates/media/aff_jeux.html +++ /dev/null @@ -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 %} - - - - - - - - - - - - - {% for jeu in jeux_list %} - - - - - - - - - {% endfor %} -
NomProprietaireDuréeJoueurs minJoueurs maxComment
{{ jeu.nom }}{{ jeu.proprietaire }}{{ jeu.duree }}{{ jeu.nombre_joueurs_min }}{{ jeu.nombre_joueurs_max }}{{ jeu.comment }}
diff --git a/media/templates/media/aff_medias.html b/media/templates/media/aff_medias.html deleted file mode 100644 index 331fccf..0000000 --- a/media/templates/media/aff_medias.html +++ /dev/null @@ -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 %} - - - - - - - - - - {% for media in medias_list %} - - - - - - {% endfor %} -
TitreAuteurCote
{{ media.titre }}{% for aut in media.auteur.all %}{{ aut }}, {% endfor %}{{ media.cote }}
diff --git a/media/templates/media/index_auteurs.html b/media/templates/media/index_auteurs.html deleted file mode 100644 index 0d5a2d4..0000000 --- a/media/templates/media/index_auteurs.html +++ /dev/null @@ -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 %} -

Liste des auteurs

- {% if user.is_staff %} - {% trans 'Go to admin' %} - {% endif %} - {% include "media/aff_auteurs.html" with auteurs_list=auteurs_list %} -{% endblock %} diff --git a/media/templates/media/index_emprunts.html b/media/templates/media/index_emprunts.html deleted file mode 100644 index a06d84d..0000000 --- a/media/templates/media/index_emprunts.html +++ /dev/null @@ -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 %} -

Liste des emprunts

- {% if user.is_staff %} - {% trans 'Go to admin' %} - {% endif %} - {% include "media/aff_emprunts.html" with emprunts_list=emprunts_list %} -{% endblock %} diff --git a/media/templates/media/index_jeux.html b/media/templates/media/index_jeux.html deleted file mode 100644 index 22d65ff..0000000 --- a/media/templates/media/index_jeux.html +++ /dev/null @@ -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 %} -

Liste des jeux

- {% if user.is_staff %} - {% trans 'Go to admin' %} - {% endif %} - {% include "media/aff_jeux.html" with jeux_list=jeux_list %} -{% endblock %} diff --git a/media/templates/media/index_medias.html b/media/templates/media/index_medias.html deleted file mode 100644 index a5e6e99..0000000 --- a/media/templates/media/index_medias.html +++ /dev/null @@ -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 %} -

Liste des medias

- {% if user.is_staff %} - {% trans 'Go to admin' %} - {% endif %} - {% include "media/aff_medias.html" with medias_list=medias_list %} -{% endblock %} diff --git a/media/templates/media/media.html b/media/templates/media/media.html index 2ee600a..5542ff1 100644 --- a/media/templates/media/media.html +++ b/media/templates/media/media.html @@ -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 %} +
{% csrf_token %} + {% if form.non_field_errors %} +

+ {% for error in form.non_field_errors %} + {{ error }} + {% endfor %} +

+ {% endif %} +
+ {% for field in form %} +
+ {{ field.errors }} +
+ {{ field.label_tag }} + {% if field.is_readonly %} +
{{ field.contents }}
+ {% else %} + {{ field }} + {% endif %} + {% if field.field.help_text %} +
{{ field.field.help_text|safe }}
+ {% endif %} +
+
+ {% endfor %} +
- - {% csrf_token %} - {% bootstrap_form mediaform %} - {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} +
+ +
{% endblock %} diff --git a/media/templates/media/sidebar.html b/media/templates/media/sidebar.html deleted file mode 100644 index 880d56b..0000000 --- a/media/templates/media/sidebar.html +++ /dev/null @@ -1,24 +0,0 @@ -{% extends "base.html" %} -{% comment %} -SPDX-License-Identifier: GPL-3.0-or-later -{% endcomment %} - -{% block sidebar %} - - - Emprunts - - - - Auteurs - - - - Medias - - - - Jeux - -{% endblock %} - diff --git a/media/urls.py b/media/urls.py index c0d9fdf..2e62a3e 100644 --- a/media/urls.py +++ b/media/urls.py @@ -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[0-9]+)$', views.add_emprunt, name='add-emprunt'), url(r'^retour_emprunt/(?P[0-9]+)$', views.retour_emprunt, name='retour-emprunt'), - url(r'^edit_emprunt/(?P[0-9]+)$', views.edit_emprunt, - name='edit-emprunt'), - url(r'^index_emprunts/$', views.index_emprunt, name='index'), ] diff --git a/media/views.py b/media/views.py index e08901d..6bdc7fe 100644 --- a/media/views.py +++ b/media/views.py @@ -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 diff --git a/theme/locale/fr/LC_MESSAGES/django.po b/theme/locale/fr/LC_MESSAGES/django.po index 141cdbf..c93b2a3 100644 --- a/theme/locale/fr/LC_MESSAGES/django.po +++ b/theme/locale/fr/LC_MESSAGES/django.po @@ -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 \n" "Language-Team: LANGUAGE \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" diff --git a/theme/templates/admin/base_site.html b/theme/templates/admin/base_site.html index c111140..8ec9ce8 100644 --- a/theme/templates/admin/base_site.html +++ b/theme/templates/admin/base_site.html @@ -25,17 +25,6 @@ SPDX-License-Identifier: GPL-3.0-or-later {% endif %} {% endblock %} {% block userlinks %} - {# Link to our apps outside of admin #} - - {% trans 'Library' %} - - Emprunts - Auteurs - Medias - Jeux - - / - {% if user.is_authenticated %} {% if perms.users.add_user %} Nouveau utilisateur / @@ -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 #} - {% trans 'View admin' %} + {% trans 'Explore database' %} {% for app in available_apps %} {% for model in app.models %} @@ -66,7 +55,7 @@ SPDX-License-Identifier: GPL-3.0-or-later / {% elif user.is_staff %} {# When not in admin site, but user is staff then add a link #} - {% trans 'View admin' %} / + {% trans 'Explore database' %} / {% endif %} {% trans 'Log out' %} {% else %}