From: Radek Czajka Date: Sun, 29 Mar 2020 21:39:33 +0000 (+0200) Subject: Remove jsonfield dependency. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/9e7f72dcee48e4ced62061b559db75dcf9b79694?ds=sidebyside Remove jsonfield dependency. --- diff --git a/requirements.txt b/requirements.txt index 72fb5dc..f2437f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,14 @@ -i https://py.mdrn.pl:8443/simple django>=1.11,<2.0 -jsonfield==2.0.2 django-cas==2.1.1.1 -django-bootstrap4 +django-bootstrap4==0.0.7 celery[redis]==4.2 kombu redis vine -mutagen +mutagen==1.42.0 requests requests-oauthlib diff --git a/src/archive/migrations/0001_initial.py b/src/archive/migrations/0001_initial.py index cc10a9f..c1f2837 100644 --- a/src/archive/migrations/0001_initial.py +++ b/src/archive/migrations/0001_initial.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from django.db import models, migrations import archive.utils -import jsonfield.fields import archive.models @@ -32,15 +31,15 @@ class Migration(migrations.Migration): ('modified', models.DateTimeField(null=True, editable=False)), ('mp3_status', models.SmallIntegerField(null=True, editable=False, choices=[(1, 'Waiting'), (2, 'Encoding'), (3, 'Tagging'), (4, 'Sending')])), ('mp3_task', models.CharField(max_length=64, null=True, editable=False)), - ('mp3_tags', jsonfield.fields.JSONField(null=True, editable=False)), + ('mp3_tags', models.TextField(null=True, editable=False)), ('mp3_file', models.FileField(storage=archive.utils.OverwriteStorage(), upload_to=b'archive/final', null=True, editable=False)), - ('mp3_published_tags', jsonfield.fields.JSONField(null=True, editable=False)), + ('mp3_published_tags', models.TextField(null=True, editable=False)), ('mp3_published', models.DateTimeField(null=True, editable=False)), ('ogg_status', models.SmallIntegerField(null=True, editable=False, choices=[(1, 'Waiting'), (2, 'Encoding'), (3, 'Tagging'), (4, 'Sending')])), ('ogg_task', models.CharField(max_length=64, null=True, editable=False)), - ('ogg_tags', jsonfield.fields.JSONField(null=True, editable=False)), + ('ogg_tags', models.TextField(null=True, editable=False)), ('ogg_file', models.FileField(storage=archive.utils.OverwriteStorage(), upload_to=b'archive/final', null=True, editable=False)), - ('ogg_published_tags', jsonfield.fields.JSONField(null=True, editable=False)), + ('ogg_published_tags', models.TextField(null=True, editable=False)), ('ogg_published', models.DateTimeField(null=True, editable=False)), ], options={ diff --git a/src/archive/models.py b/src/archive/models.py index c75a874..56b61af 100644 --- a/src/archive/models.py +++ b/src/archive/models.py @@ -3,7 +3,6 @@ import os.path from django.db import models from time import sleep -from jsonfield.fields import JSONField from django.utils.encoding import force_bytes from django.utils.translation import ugettext_lazy as _ from archive.constants import status @@ -54,19 +53,18 @@ class Audiobook(models.Model): # publishing process mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) mp3_task = models.CharField(max_length=64, null=True, editable=False) - mp3_tags = JSONField(null=True, editable=False) + mp3_tags = models.TextField(null=True, editable=False) mp3_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False) - mp3_published_tags = JSONField(null=True, editable=False) + mp3_published_tags = models.TextField(null=True, editable=False) mp3_published = models.DateTimeField(null=True, editable=False) ogg_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) ogg_task = models.CharField(max_length=64, null=True, editable=False) - ogg_tags = JSONField(null=True, editable=False) + ogg_tags = models.TextField(null=True, editable=False) ogg_file = models.FileField(null=True, upload_to='archive/final', storage=OverwriteStorage(), editable=False) - ogg_published_tags = JSONField(null=True, editable=False) + ogg_published_tags = models.TextField(null=True, editable=False) ogg_published = models.DateTimeField(null=True, editable=False) - class Meta: verbose_name = _("audiobook") verbose_name_plural = _("audiobooks") @@ -75,6 +73,13 @@ class Audiobook(models.Model): def __unicode__(self): return self.title + def get_mp3_tags(self): return json.loads(self.mp3_tags) if self.mp3_tags else None + def get_ogg_tags(self): return json.loads(self.ogg_tags) if self.ogg_tags else None + def get_mp3_published_tags(self): return json.loads(self.mp3_published_tags) if self.mp3_published_tags else None + def get_ogg_published_tags_tags(self): return json.loads(self.ogg_published_tags) if self.ogg_published_tags else None + def set_mp3_tags(self, tags): self.mp3_tags = json.dumps(tags) + def set_ogg_tags(self, tags): self.ogg_tags = json.dumps(tags) + def published(self): return self.mp3_published and self.ogg_published diff --git a/src/archive/tasks.py b/src/archive/tasks.py index 2b3d696..1eeeb28 100644 --- a/src/archive/tasks.py +++ b/src/archive/tasks.py @@ -39,7 +39,7 @@ class AudioFormatTask(Task): @classmethod def set_tags(cls, audiobook, file_name): - tags = getattr(audiobook, "%s_tags" % cls.ext)['tags'] + tags = getattr(audiobook, "get_%s_tags" % cls.ext)()['tags'] if not tags.get('flac_sha1'): tags['flac_sha1'] = audiobook.get_source_sha1() audio = File(file_name) @@ -71,7 +71,7 @@ class AudioFormatTask(Task): @classmethod def put(cls, user, audiobook, path): - tags = getattr(audiobook, "%s_tags" % cls.ext) + tags = getattr(audiobook, "get_%s_tags" % cls.ext)() data = { 'book': tags['url'], 'type': cls.ext, @@ -167,7 +167,7 @@ class Mp3Task(AudioFormatTask): @classmethod def set_tags(cls, audiobook, file_name): - mp3_tags = audiobook.mp3_tags['tags'] + mp3_tags = audiobook.get_mp3_tags()['tags'] if not mp3_tags.get('flac_sha1'): mp3_tags['flac_sha1'] = audiobook.get_source_sha1() audio = id3.ID3(file_name) diff --git a/src/archive/templates/archive/file_managed.html b/src/archive/templates/archive/file_managed.html index 6859429..25a6b81 100644 --- a/src/archive/templates/archive/file_managed.html +++ b/src/archive/templates/archive/file_managed.html @@ -23,7 +23,7 @@

MP3

- {% tags_table audiobook.mp3_tags.tags %} + {% tags_table audiobook.get_mp3_tags.tags %}

Status: {{ audiobook.get_mp3_status_display }}

{% endif %} @@ -32,7 +32,7 @@

Ogg Vorbis

- {% tags_table audiobook.ogg_tags.tags %} + {% tags_table audiobook.get_ogg_tags.tags %}

Status: {{ audiobook.get_ogg_status_display }}

{% endif %} @@ -79,8 +79,8 @@

{% trans "Download MP3 file." %}

{% if audiobook.mp3_published %}

{% trans "Published:" %} {{ audiobook.mp3_published }}

- {% if audiobook.mp3_published_tags.tags %} - {% tags_table audiobook.mp3_published_tags.tags %} + {% if audiobook.get_mp3_published_tags.tags %} + {% tags_table audiobook.get_mp3_published_tags.tags %} {% endif %} {% else %}

{% trans "Not published yet." %}

@@ -102,8 +102,8 @@

{% trans "Download Ogg Vorbis file." %}

{% if audiobook.ogg_published %}

{% trans "Published:" %} {{ audiobook.ogg_published }}

- {% if audiobook.ogg_published_tags.tags %} - {% tags_table audiobook.ogg_published_tags.tags %} + {% if audiobook.get_ogg_published_tags.tags %} + {% tags_table audiobook.get_ogg_published_tags.tags %} {% endif %} {% else %}

{% trans "Not published yet." %}

diff --git a/src/archive/views.py b/src/archive/views.py index 55f4f07..fc3a7e5 100644 --- a/src/archive/views.py +++ b/src/archive/views.py @@ -166,8 +166,8 @@ def publish(request, aid, publish=True): 'url': audiobook.url, 'tags': audiobook.new_publish_tags(), } - audiobook.mp3_tags = tags - audiobook.ogg_tags = tags + audiobook.set_mp3_tags(tags) + audiobook.set_ogg_tags(tags) audiobook.mp3_status = audiobook.ogg_status = status.WAITING audiobook.save() # isn't there a race here?