mirror of
https://gitlab.crans.org/mediatek/med.git
synced 2024-12-26 04:22:24 +00:00
Add a model to store future media list.
This commit is contained in:
parent
adbaf66401
commit
ea30cdec6e
@ -9,7 +9,7 @@ from reversion.admin import VersionAdmin
|
||||
|
||||
from med.admin import admin_site
|
||||
from .forms import MediaAdminForm
|
||||
from .models import Auteur, Emprunt, Jeu, Media
|
||||
from .models import Auteur, Emprunt, Jeu, Media, FutureMedia
|
||||
|
||||
|
||||
class AuteurAdmin(VersionAdmin):
|
||||
@ -60,6 +60,22 @@ class MediaAdmin(VersionAdmin):
|
||||
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):
|
||||
list_display = ('media', 'user', 'date_emprunt', 'date_rendu',
|
||||
'permanencier_emprunt', 'permanencier_rendu_custom')
|
||||
@ -105,5 +121,6 @@ class JeuAdmin(VersionAdmin):
|
||||
|
||||
admin_site.register(Auteur, AuteurAdmin)
|
||||
admin_site.register(Media, MediaAdmin)
|
||||
admin_site.register(FutureMedia, FutureMediaAdmin)
|
||||
admin_site.register(Emprunt, EmpruntAdmin)
|
||||
admin_site.register(Jeu, JeuAdmin)
|
||||
|
@ -41,7 +41,7 @@ class MediaAdminForm(ModelForm):
|
||||
Download data from google books
|
||||
: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:
|
||||
data = json.loads(url.read().decode())
|
||||
|
||||
@ -234,8 +234,6 @@ class MediaAdminForm(ModelForm):
|
||||
).casefold().upper()
|
||||
self.cleaned_data['side_identifier'] = side_identifier
|
||||
|
||||
print(self.cleaned_data)
|
||||
|
||||
return self.cleaned_data
|
||||
|
||||
def _clean_fields(self):
|
||||
|
@ -84,6 +84,23 @@ class Media(models.Model):
|
||||
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):
|
||||
media = models.ForeignKey(
|
||||
'Media',
|
||||
|
Loading…
Reference in New Issue
Block a user