diff --git a/docs/source/upgrade/5.0.rst b/docs/source/upgrade/5.0.rst index a54cd5e..1ada37a 100755 --- a/docs/source/upgrade/5.0.rst +++ b/docs/source/upgrade/5.0.rst @@ -9,6 +9,7 @@ What's new in 5.0 * Upgrading docker image to python:3.6.10-buster * Upgrading requirements (Django 1.11.29 / grappelli 2.10.4 among others) * Dropping mysql support. +* Adding Podcast file field to upload audio files manually. ******************** How this affects you diff --git a/radioco/apps/programmes/admin.py b/radioco/apps/programmes/admin.py index be0525a..33d585c 100755 --- a/radioco/apps/programmes/admin.py +++ b/radioco/apps/programmes/admin.py @@ -267,10 +267,17 @@ def queryset(self, request, queryset): return queryset +class PodcastAdminForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(PodcastAdminForm, self).__init__(*args, **kwargs) + self.fields['url'].required = False + + class PodcastInline(admin.StackedInline): inline_classes = ('grp-collapse grp-open',) extra = 0 model = Podcast + form = PodcastAdminForm class NonStaffEpisodeAdmin(admin.ModelAdmin): diff --git a/radioco/apps/programmes/migrations/0012__v5_0__podcast_podcast_file.py b/radioco/apps/programmes/migrations/0012__v5_0__podcast_podcast_file.py new file mode 100644 index 0000000..0a7cf97 --- /dev/null +++ b/radioco/apps/programmes/migrations/0012__v5_0__podcast_podcast_file.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-03-06 18:26 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('programmes', '0011__v3_2__ensure_one_user_role'), + ] + + operations = [ + migrations.AddField( + model_name='podcast', + name='podcast_file', + field=models.FileField(blank=True, upload_to='podcasts/'), + ), + ] diff --git a/radioco/apps/programmes/models.py b/radioco/apps/programmes/models.py index 6f31c05..7377c02 100755 --- a/radioco/apps/programmes/models.py +++ b/radioco/apps/programmes/models.py @@ -295,6 +295,14 @@ class Podcast(models.Model): mime_type = models.CharField(max_length=20) length = models.PositiveIntegerField() # bytes duration = models.PositiveIntegerField(validators=[MinValueValidator(1)]) + podcast_file = models.FileField(upload_to='podcasts/', blank=True) + + def save(self, *args, **kwargs): + if not self.url and self.podcast_file: + from radioco.apps.global_settings.models import PodcastConfiguration + podcast_config = PodcastConfiguration.get_global() + self.url = podcast_config.url_source.rstrip('/') + self.podcast_file.url + super(Podcast, self).save(*args, **kwargs) def get_absolute_url(self): return self.episode.get_absolute_url()