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

Add a model to store future media list.

This commit is contained in:
Yohann D'ANELLO 2020-05-12 17:33:32 +02:00
parent adbaf66401
commit ea30cdec6e
3 changed files with 36 additions and 4 deletions

View File

@ -9,7 +9,7 @@ from reversion.admin import VersionAdmin
from med.admin import admin_site from med.admin import admin_site
from .forms import MediaAdminForm from .forms import MediaAdminForm
from .models import Auteur, Emprunt, Jeu, Media from .models import Auteur, Emprunt, Jeu, Media, FutureMedia
class AuteurAdmin(VersionAdmin): class AuteurAdmin(VersionAdmin):
@ -60,6 +60,22 @@ class MediaAdmin(VersionAdmin):
extra_context=extra_context) extra_context=extra_context)
class FutureMediaAdmin(VersionAdmin):
list_display = ('isbn',)
search_fields = ('isbn',)
def changeform_view(self, request, object_id=None, form_url='',
extra_context=None):
"""
We use _continue for ISBN fetching, so remove continue button
"""
extra_context = extra_context or {}
extra_context['show_save_and_continue'] = False
extra_context['show_save'] = False
return super().changeform_view(request, object_id, form_url,
extra_context=extra_context)
class EmpruntAdmin(VersionAdmin): class EmpruntAdmin(VersionAdmin):
list_display = ('media', 'user', 'date_emprunt', 'date_rendu', list_display = ('media', 'user', 'date_emprunt', 'date_rendu',
'permanencier_emprunt', 'permanencier_rendu_custom') 'permanencier_emprunt', 'permanencier_rendu_custom')
@ -105,5 +121,6 @@ class JeuAdmin(VersionAdmin):
admin_site.register(Auteur, AuteurAdmin) admin_site.register(Auteur, AuteurAdmin)
admin_site.register(Media, MediaAdmin) admin_site.register(Media, MediaAdmin)
admin_site.register(FutureMedia, FutureMediaAdmin)
admin_site.register(Emprunt, EmpruntAdmin) admin_site.register(Emprunt, EmpruntAdmin)
admin_site.register(Jeu, JeuAdmin) admin_site.register(Jeu, JeuAdmin)

View File

@ -41,7 +41,7 @@ class MediaAdminForm(ModelForm):
Download data from google books Download data from google books
:return True if success :return True if success
""" """
api_url = "https://www.googleapis.com/books/v1/volumes?q=isbn:{}".format(isbn) api_url = "https://www.googleapis.com/books/v1/volumes?q=ISBN:{}".format(isbn)
with urllib.request.urlopen(api_url) as url: with urllib.request.urlopen(api_url) as url:
data = json.loads(url.read().decode()) data = json.loads(url.read().decode())
@ -234,8 +234,6 @@ class MediaAdminForm(ModelForm):
).casefold().upper() ).casefold().upper()
self.cleaned_data['side_identifier'] = side_identifier self.cleaned_data['side_identifier'] = side_identifier
print(self.cleaned_data)
return self.cleaned_data return self.cleaned_data
def _clean_fields(self): def _clean_fields(self):

View File

@ -84,6 +84,23 @@ class Media(models.Model):
ordering = ['title', 'subtitle'] ordering = ['title', 'subtitle']
class FutureMedia(models.Model):
isbn = ISBNField(
_('ISBN'),
help_text=_('You may be able to scan it from a bar code.'),
unique=True,
blank=True,
null=True,
)
class Meta:
verbose_name = _("future medium")
verbose_name_plural = _("future media")
def __str__(self):
return "Future medium (ISBN: {isbn})".format(isbn=self.isbn, )
class Emprunt(models.Model): class Emprunt(models.Model):
media = models.ForeignKey( media = models.ForeignKey(
'Media', 'Media',