'file': JqueryFileUploadInput(),
}
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ if getattr(settings, 'USE_EXTERNAL_SOUNDS', True):
+ self.fields['file'].widget = forms.HiddenInput()
+ else:
+ self.fields['external_url'].widget = forms.HiddenInput()
+
def clean(self):
super().clean()
- if self.cleaned_data.get('file'):
- duration = get_duration(self.cleaned_data['file'].file.name)
- if not duration:
- raise ValidationError(_('Invalid file, could not get duration.'))
+ if getattr(settings, 'USE_EXTERNAL_SOUNDS', True):
+ if not self.cleaned_data.get('external_url'):
+ raise ValidationError(_('Missing URL'))
+ else:
+ if not self.cleaned_data.get('file'):
+ raise ValidationError(_('Missing file'))
+ if self.cleaned_data.get('file'):
+ duration = get_duration(self.cleaned_data['file'].file.name)
+ if not duration:
+ raise ValidationError(_('Invalid file, could not get duration.'))
class SoundFileEditForm(forms.ModelForm):
class Meta:
model = SoundFile
- exclude = ('has_focus', 'got_focus', 'file', 'duration', 'download_count')
+ exclude = ('has_focus', 'got_focus', 'file', 'external_url', 'duration', 'download_count')
widgets = {
'episode': forms.HiddenInput(),
}
--- /dev/null
+# Generated by Django 2.2.19 on 2021-05-27 14:54
+
+from django.db import migrations, models
+import emissions.models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('emissions', '0018_emission_tags'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='soundfile',
+ name='external_url',
+ field=models.URLField(blank=True, null=True, verbose_name='URL'),
+ ),
+ migrations.AlterField(
+ model_name='soundfile',
+ name='file',
+ field=models.FileField(blank=True, max_length=250, null=True, upload_to=emissions.models.get_sound_path, verbose_name='File'),
+ ),
+ ]
ordering = ['creation_timestamp']
episode = models.ForeignKey('Episode', verbose_name=_('Episode'), on_delete=models.CASCADE)
- file = models.FileField(_('File'), upload_to=get_sound_path, max_length=250)
+ file = models.FileField(_('File'), upload_to=get_sound_path, max_length=250, blank=True, null=True)
+ external_url = models.URLField(_('URL'), null=True, blank=True)
podcastable = models.BooleanField(
_('Podcastable'),
default=False,