1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-06-29 18:31:09 +02:00

Django upgrade

This commit is contained in:
Alexandre Iooss
2019-08-10 10:44:17 +02:00
parent 80055771e9
commit a6dc8653af
19 changed files with 240 additions and 137 deletions

View File

@ -10,10 +10,12 @@ from .models import Auteur, Emprunt, Jeu, Media
class AuteurAdmin(VersionAdmin):
list_display = ('nom',)
search_fields = ('nom',)
class MediaAdmin(VersionAdmin):
list_display = ('titre', 'authors', 'cote')
search_fields = ('titre', 'authors', 'cote')
def authors(self, obj):
return ", ".join([a.nom for a in obj.auteur.all()])
@ -22,11 +24,14 @@ class MediaAdmin(VersionAdmin):
class EmpruntAdmin(VersionAdmin):
list_display = ('media', 'user', 'date_emprunt', 'date_rendu',
'permanencier_emprunt', 'permanencier_rendu')
search_fields = ('media', 'user', 'date_emprunt', 'date_rendu')
date_hierarchy = 'date_emprunt'
class JeuAdmin(VersionAdmin):
list_display = ('nom', 'proprietaire', 'duree', 'nombre_joueurs_min',
'nombre_joueurs_max', 'comment')
search_fields = ('nom', 'proprietaire', 'duree', 'comment')
admin_site.register(Auteur, AuteurAdmin)

View File

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-09 22:25+0200\n"
"POT-Creation-Date: 2019-08-10 10:24+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"
@ -45,78 +45,10 @@ msgstr "jeu"
msgid "games"
msgstr "jeux"
#: templates/media/index.html:41
msgid "My profile"
msgstr "Mon profil"
#: templates/media/index.html:43
msgid "Edit"
msgstr "Éditer"
#: templates/media/index.html:47
msgid "username"
msgstr ""
#: templates/media/index.html:48
msgid "email"
msgstr ""
#: templates/media/index.html:49
msgid "comment"
msgstr ""
#: templates/media/index.html:50
msgid "date joined"
msgstr ""
#: templates/media/index.html:51
msgid "last login"
msgstr ""
#: templates/media/index.html:52
msgid "address"
msgstr ""
#: templates/media/index.html:53
msgid "phone number"
msgstr ""
#: templates/media/index.html:54
msgid "groups"
msgstr ""
#: templates/media/index.html:55
msgid "maximum borrowed"
msgstr "emprunts maximal"
#: templates/media/index.html:57
msgid "membership for current year"
msgstr "membre pour cette année"
#: templates/media/index.html:59
msgid "yes"
msgstr "oui"
#: templates/media/index.html:61
msgid "no"
msgstr "non"
#: templates/media/index.html:66
msgid "Current borrowed items"
msgstr "Emprunts en cours"
#: templates/media/index.html:70
msgid "since"
msgstr "depuis"
#: templates/media/index.html:74
msgid "No current borrowed items."
msgstr "Pas d'emprunts en cours."
#: templates/media/index.html:77
msgid "You are not logged in."
msgstr "Vous n'êtes pas identifié."
#: templates/media/media.html:37
msgid "Save"
msgstr "Enregistrer"
#: views.py:80
msgid "Welcome to the Mediatek database"
msgstr "Bienvenue sur la base de données de la Mediatek"

View File

@ -6,6 +6,7 @@ from django.conf.urls import url
from . import views
app_name = 'media'
urlpatterns = [
url(r'^add_emprunt/(?P<userid>[0-9]+)$', views.add_emprunt,
name='add-emprunt'),

View File

@ -29,14 +29,14 @@ def add_emprunt(request, userid):
user = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect("/")
return redirect("admin:media_emprunt_changelist")
emprunts_en_cours = Emprunt.objects.filter(date_rendu=None,
user=user).count()
if emprunts_en_cours >= user.maxemprunt:
messages.error(request,
"Maximum d'emprunts atteint de "
"l'user %s" % user.maxemprunt)
return redirect("/")
return redirect("admin:media_emprunt_changelist")
emprunt = EmpruntForm(request.POST or None)
if emprunt.is_valid():
emprunt = emprunt.save(commit=False)
@ -48,7 +48,7 @@ def add_emprunt(request, userid):
reversion.set_user(request.user)
reversion.set_comment("Création")
messages.success(request, "Le emprunt a été ajouté")
return redirect("/")
return redirect("admin:media_emprunt_changelist")
return form({'form': emprunt}, 'media/media.html', request)
@ -59,14 +59,14 @@ def retour_emprunt(request, empruntid):
emprunt_instance = Emprunt.objects.get(pk=empruntid)
except Emprunt.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect("/")
return redirect("admin:media_emprunt_changelist")
with transaction.atomic(), reversion.create_revision():
emprunt_instance.permanencier_rendu = request.user
emprunt_instance.date_rendu = timezone.now()
emprunt_instance.save()
reversion.set_user(request.user)
messages.success(request, "Retour enregistré")
return redirect("/")
return redirect("admin:media_emprunt_changelist")
def index(request):