From: Radek Czajka Date: Sat, 23 May 2020 23:47:07 +0000 (+0200) Subject: Configurable license. X-Git-Url: https://git.mdrn.pl/audio.git/commitdiff_plain/0678dd50bd89ef1ad0f0d95c1e7907e31187a0d3?ds=inline;hp=4ed2ea5a00aa1293135923b513925c46b963be93 Configurable license. --- diff --git a/src/archive/migrations/0009_auto_20200524_0139.py b/src/archive/migrations/0009_auto_20200524_0139.py new file mode 100644 index 0000000..4d01e36 --- /dev/null +++ b/src/archive/migrations/0009_auto_20200524_0139.py @@ -0,0 +1,27 @@ +# Generated by Django 3.0.4 on 2020-05-24 01:39 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0008_remove_audiobook_youtube_file'), + ] + + operations = [ + migrations.CreateModel( + name='License', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('uri', models.CharField(max_length=255, unique=True)), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.AddField( + model_name='audiobook', + name='license', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='archive.License', verbose_name='license'), + ), + ] diff --git a/src/archive/migrations/0010_populate_license.py b/src/archive/migrations/0010_populate_license.py new file mode 100644 index 0000000..dc59bdc --- /dev/null +++ b/src/archive/migrations/0010_populate_license.py @@ -0,0 +1,34 @@ +# Generated by Django 3.0.4 on 2020-05-24 01:40 + +import json +from django.db import migrations + + +def populate_license(apps, schema_editor): + License = apps.get_model('archive.License') + Audiobook = apps.get_model('archive.Audiobook') + licenses = {} + for a in Audiobook.objects.all(): + if a.mp3_tags: + tags = json.loads(a.mp3_tags) + uri = tags.get('license') + if not uri: + continue + if uri not in licenses: + licenses[uri], created = License.objects.get_or_create(uri=uri, defaults={"name": "?"}) + a.license = licenses[uri] + a.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('archive', '0009_auto_20200524_0139'), + ] + + operations = [ + migrations.RunPython( + populate_license, + migrations.RunPython.noop + ) + ] diff --git a/src/archive/models.py b/src/archive/models.py index d76ed99..d8b85ad 100644 --- a/src/archive/models.py +++ b/src/archive/models.py @@ -8,10 +8,15 @@ from django.utils.translation import gettext_lazy as _ from django_pglocks import advisory_lock import requests from archive.constants import status -from archive.settings import FILES_SAVE_PATH, ADVERT, LICENSE, ORGANIZATION, PROJECT +from archive.settings import FILES_SAVE_PATH, ADVERT, ORGANIZATION, PROJECT from archive.utils import OverwriteStorage, sha1_file +class License(models.Model): + uri = models.CharField(max_length=255, unique=True) + name = models.CharField(max_length=255) + + class Project(models.Model): """ an audiobook project, needed for specyfing sponsors """ @@ -68,6 +73,7 @@ class Audiobook(models.Model): url = models.URLField(max_length=255, verbose_name=_('book url')) translator = models.CharField(max_length=255, null=True, blank=True, verbose_name=_('translator')) modified = models.DateTimeField(null=True, editable=False) + license = models.ForeignKey(License, models.PROTECT, null=True, blank=True, verbose_name=_('license')) # publishing process mp3_status = models.SmallIntegerField(null=True, editable=False, choices=status.choices) @@ -124,7 +130,7 @@ class Audiobook(models.Model): title += ' (tłum. %s)' % self.translator copyright = "%s %s. Licensed to the public under %s verify at %s" % ( - self.date, ORGANIZATION, LICENSE, self.url) + self.date, ORGANIZATION, self.license.uri, self.url) comment = "\n".join(( self.project.get_description(), @@ -142,7 +148,7 @@ class Audiobook(models.Model): 'date': self.date, 'genre': 'Speech', 'language': 'pol', - 'license': LICENSE, + 'license': self.license.uri, 'organization': ORGANIZATION, 'title': title, 'project': self.project.name, diff --git a/src/archive/settings.py b/src/archive/settings.py index 91921a8..77a8cbe 100644 --- a/src/archive/settings.py +++ b/src/archive/settings.py @@ -49,18 +49,6 @@ except AttributeError: PROJECT = 'Wolne Lektury' -LICENSE = getattr( - settings, - 'ARCHIVE_LICENSE', - 'http://artlibre.org/licence/lal/pl/' -) - -LICENSE_NAME = getattr( - settings, 'ARCHIVE_LICENSE_NAME', - 'Licencja Wolnej Sztuki 1.3' -) - - try: ORGANIZATION = settings.ARCHIVE_ORGANIZATION except AttributeError: diff --git a/src/youtube/models.py b/src/youtube/models.py index 027befd..39a1d2d 100644 --- a/src/youtube/models.py +++ b/src/youtube/models.py @@ -5,7 +5,6 @@ from django.db import models from django.utils.translation import gettext_lazy as _ from django.template import Template, Context from apiclient import youtube_call -from archive.settings import LICENSE, LICENSE_NAME from .utils import ( concat_audio, concat_videos, @@ -20,6 +19,9 @@ from .utils import ( from .thumbnail import create_thumbnail +YOUTUBE_TITLE_LIMIT = 100 + + class YouTube(models.Model): title_template = models.CharField(max_length=1024, blank=True) description_template = models.TextField(blank=True) @@ -46,15 +48,13 @@ class YouTube(models.Model): def get_context(self, audiobook): return Context(dict( audiobook=audiobook, - LICENSE=LICENSE, - LICENSE_NAME=LICENSE_NAME, )) def get_description(self, audiobook): return Template(self.description_template).render(self.get_context(audiobook)) def get_title(self, audiobook): - return Template(self.title_template).render(self.get_context(audiobook)) + return Template(self.title_template).render(self.get_context(audiobook))[:YOUTUBE_TITLE_LIMIT] def get_data(self, audiobook): return dict(