Skip to content

Commit

Permalink
Adding Podcast file field to upload audio files manually
Browse files Browse the repository at this point in the history
  • Loading branch information
Iago Veloso committed Mar 6, 2020
1 parent f2113f1 commit c14cd2c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/upgrade/5.0.rst
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions radioco/apps/programmes/admin.py
Expand Up @@ -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):
Expand Down
@@ -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/'),
),
]
8 changes: 8 additions & 0 deletions radioco/apps/programmes/models.py
Expand Up @@ -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()

0 comments on commit c14cd2c

Please sign in to comment.