Ajout des CD et des vinyles
This commit is contained in:
parent
001f40a033
commit
054865cd41
|
@ -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, FutureMedia, Jeu, Manga, Media
|
from .models import Auteur, BD, CD, Emprunt, FutureMedia, Jeu, Manga, Vinyle
|
||||||
|
|
||||||
|
|
||||||
class AuteurAdmin(VersionAdmin):
|
class AuteurAdmin(VersionAdmin):
|
||||||
|
@ -76,6 +76,17 @@ class FutureMediaAdmin(VersionAdmin):
|
||||||
extra_context=extra_context)
|
extra_context=extra_context)
|
||||||
|
|
||||||
|
|
||||||
|
class CDAdmin(VersionAdmin):
|
||||||
|
list_display = ('title', 'authors_list', 'side_identifier',)
|
||||||
|
search_fields = ('title', 'authors__name', 'side_identifier',)
|
||||||
|
autocomplete_fields = ('authors',)
|
||||||
|
|
||||||
|
def authors_list(self, obj):
|
||||||
|
return ", ".join([a.name for a in obj.authors.all()])
|
||||||
|
|
||||||
|
authors_list.short_description = _('authors')
|
||||||
|
|
||||||
|
|
||||||
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')
|
||||||
|
@ -120,8 +131,10 @@ class JeuAdmin(VersionAdmin):
|
||||||
|
|
||||||
|
|
||||||
admin_site.register(Auteur, AuteurAdmin)
|
admin_site.register(Auteur, AuteurAdmin)
|
||||||
admin_site.register(Media, MediaAdmin)
|
admin_site.register(BD, MediaAdmin)
|
||||||
admin_site.register(Manga, MediaAdmin)
|
admin_site.register(Manga, MediaAdmin)
|
||||||
|
admin_site.register(CD, CDAdmin)
|
||||||
|
admin_site.register(Vinyle, CDAdmin)
|
||||||
admin_site.register(FutureMedia, FutureMediaAdmin)
|
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)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import urllib.request
|
||||||
from django.forms import ModelForm
|
from django.forms import ModelForm
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from .models import Auteur, Media
|
from .models import Auteur, BD
|
||||||
from .scraper import BedetequeScraper
|
from .scraper import BedetequeScraper
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,5 +263,5 @@ class MediaAdminForm(ModelForm):
|
||||||
self.add_error(name, e)
|
self.add_error(name, e)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Media
|
model = BD
|
||||||
fields = '__all__'
|
fields = '__all__'
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
from django.core.management import BaseCommand
|
from django.core.management import BaseCommand
|
||||||
|
|
||||||
from media.forms import MediaAdminForm
|
from media.forms import MediaAdminForm
|
||||||
from media.models import Manga, Media
|
from media.models import BD, Manga
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
@ -13,7 +15,11 @@ class Command(BaseCommand):
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
converted = 0
|
converted = 0
|
||||||
|
|
||||||
for media in Media.objects.all():
|
for media in BD.objects.all():
|
||||||
|
if media.pk < 3400:
|
||||||
|
continue
|
||||||
|
# We sleep 5 seconds to avoid a ban from Bedetheque
|
||||||
|
sleep(5)
|
||||||
self.stdout.write(str(media))
|
self.stdout.write(str(media))
|
||||||
form = MediaAdminForm(instance=media,
|
form = MediaAdminForm(instance=media,
|
||||||
data={"isbn": media.isbn, "_isbn": True, })
|
data={"isbn": media.isbn, "_isbn": True, })
|
||||||
|
|
|
@ -30,7 +30,7 @@ class Auteur(models.Model):
|
||||||
ordering = ['name']
|
ordering = ['name']
|
||||||
|
|
||||||
|
|
||||||
class Media(models.Model):
|
class BD(models.Model):
|
||||||
isbn = ISBNField(
|
isbn = ISBNField(
|
||||||
_('ISBN'),
|
_('ISBN'),
|
||||||
help_text=_('You may be able to scan it from a bar code.'),
|
help_text=_('You may be able to scan it from a bar code.'),
|
||||||
|
@ -86,8 +86,8 @@ class Media(models.Model):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("medium")
|
verbose_name = _("BD")
|
||||||
verbose_name_plural = _("media")
|
verbose_name_plural = _("BDs")
|
||||||
ordering = ['title', 'subtitle']
|
ordering = ['title', 'subtitle']
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,16 +140,55 @@ class Manga(models.Model):
|
||||||
null=True,
|
null=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Vinyle(models.Model):
|
||||||
|
title = models.CharField(
|
||||||
|
verbose_name=_('title'),
|
||||||
|
max_length=255,
|
||||||
|
)
|
||||||
|
|
||||||
|
side_identifier = models.CharField(
|
||||||
|
verbose_name=_('side identifier'),
|
||||||
|
max_length=255,
|
||||||
|
)
|
||||||
|
|
||||||
|
authors = models.ManyToManyField(
|
||||||
|
'Auteur',
|
||||||
|
verbose_name=_('authors'),
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.subtitle:
|
return self.title
|
||||||
return "{} : {}".format(self.title, self.subtitle)
|
|
||||||
else:
|
|
||||||
return self.title
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _("manga")
|
verbose_name = _("vinyle")
|
||||||
verbose_name_plural = _("mangas")
|
verbose_name_plural = _("vinyles")
|
||||||
ordering = ['title', 'subtitle']
|
ordering = ['title']
|
||||||
|
|
||||||
|
|
||||||
|
class CD(models.Model):
|
||||||
|
title = models.CharField(
|
||||||
|
verbose_name=_('title'),
|
||||||
|
max_length=255,
|
||||||
|
)
|
||||||
|
|
||||||
|
side_identifier = models.CharField(
|
||||||
|
verbose_name=_('side identifier'),
|
||||||
|
max_length=255,
|
||||||
|
)
|
||||||
|
|
||||||
|
authors = models.ManyToManyField(
|
||||||
|
'Auteur',
|
||||||
|
verbose_name=_('authors'),
|
||||||
|
)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.title
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _("CD")
|
||||||
|
verbose_name_plural = _("CDs")
|
||||||
|
ordering = ['title']
|
||||||
|
|
||||||
|
|
||||||
class FutureMedia(models.Model):
|
class FutureMedia(models.Model):
|
||||||
|
@ -171,7 +210,7 @@ class FutureMedia(models.Model):
|
||||||
|
|
||||||
class Emprunt(models.Model):
|
class Emprunt(models.Model):
|
||||||
media = models.ForeignKey(
|
media = models.ForeignKey(
|
||||||
'Media',
|
'BD',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
)
|
)
|
||||||
user = models.ForeignKey(
|
user = models.ForeignKey(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from .models import Auteur, Emprunt, Jeu, Media
|
from .models import Auteur, BD, Emprunt, Jeu
|
||||||
|
|
||||||
|
|
||||||
class AuteurSerializer(serializers.HyperlinkedModelSerializer):
|
class AuteurSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
@ -11,7 +11,7 @@ class AuteurSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
class MediaSerializer(serializers.HyperlinkedModelSerializer):
|
class MediaSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Media
|
model = BD
|
||||||
fields = ['url', 'isbn', 'title', 'subtitle', 'external_url',
|
fields = ['url', 'isbn', 'title', 'subtitle', 'external_url',
|
||||||
'side_identifier', 'authors', 'number_of_pages',
|
'side_identifier', 'authors', 'number_of_pages',
|
||||||
'publish_date']
|
'publish_date']
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from media.models import Auteur, Media
|
from media.models import Auteur, BD
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -25,12 +25,12 @@ class TemplateTests(TestCase):
|
||||||
self.dummy_author = Auteur.objects.create(name="Test author")
|
self.dummy_author = Auteur.objects.create(name="Test author")
|
||||||
|
|
||||||
# Create media
|
# Create media
|
||||||
self.dummy_media1 = Media.objects.create(
|
self.dummy_media1 = BD.objects.create(
|
||||||
title="Test media",
|
title="Test media",
|
||||||
side_identifier="T M",
|
side_identifier="T M",
|
||||||
)
|
)
|
||||||
self.dummy_media1.authors.add(self.dummy_author)
|
self.dummy_media1.authors.add(self.dummy_author)
|
||||||
self.dummy_media2 = Media.objects.create(
|
self.dummy_media2 = BD.objects.create(
|
||||||
title="Test media bis",
|
title="Test media bis",
|
||||||
side_identifier="T M 2",
|
side_identifier="T M 2",
|
||||||
external_url="https://example.com/",
|
external_url="https://example.com/",
|
||||||
|
|
|
@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from reversion import revisions as reversion
|
from reversion import revisions as reversion
|
||||||
|
|
||||||
from .models import Auteur, Emprunt, Jeu, Media
|
from .models import Auteur, BD, Emprunt, Jeu
|
||||||
from .serializers import AuteurSerializer, EmpruntSerializer, \
|
from .serializers import AuteurSerializer, EmpruntSerializer, \
|
||||||
JeuSerializer, MediaSerializer
|
JeuSerializer, MediaSerializer
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class MediaViewSet(viewsets.ModelViewSet):
|
||||||
"""
|
"""
|
||||||
API endpoint that allows media to be viewed or edited.
|
API endpoint that allows media to be viewed or edited.
|
||||||
"""
|
"""
|
||||||
queryset = Media.objects.all()
|
queryset = BD.objects.all()
|
||||||
serializer_class = MediaSerializer
|
serializer_class = MediaSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue