]> git.0d.be Git - django-panik-nonstop.git/blob - nonstop/forms.py
make jingle optional
[django-panik-nonstop.git] / nonstop / forms.py
1 from django import forms
2 from django.utils.translation import ugettext_lazy as _
3
4 from .models import Track, Jingle
5
6 def get_nonstop_zones():
7     from emissions.models import Nonstop
8     return [(x.id, x.title) for x in Nonstop.objects.all()]
9
10 def get_optional_nonstop_zones():
11     return [('', '')] + get_nonstop_zones()
12
13 def get_search_nonstop_zones():
14     return [('', 'All'),
15             ('any', _('Any')),
16             ('', '--------------')] + get_nonstop_zones() + [('', '--------------'), ('none', 'None')]
17
18 class UploadTracksForm(forms.Form):
19     tracks = forms.FileField(widget=forms.ClearableFileInput(
20         attrs={'multiple': True, 'accept': 'audio/*'}))
21     nonstop_zone = forms.ChoiceField(choices=get_optional_nonstop_zones)
22
23
24 class TrackMetaForm(forms.ModelForm):
25     class Meta:
26         model = Track
27         fields = ['language', 'instru', 'sabam', 'cfwb', 'nonstop_zones']
28
29
30 class TrackSearchForm(forms.Form):
31     q = forms.CharField(label=_('Text'), required=False)
32     zone = forms.ChoiceField(label=_('Nonstop Zone'),
33             choices=get_search_nonstop_zones, required=False)
34     order_by = forms.ChoiceField(label=_('Order'),
35             required=False,
36             choices=[('title', _('Alphabetically')),
37                      ('-added_to_nonstop_timestamp', _('Newest first')),
38                      ('added_to_nonstop_timestamp', _('Oldest first'))])
39
40
41 class CleanupForm(forms.Form):
42     zone = forms.ChoiceField(label=_('Nonstop Zone'), choices=get_optional_nonstop_zones)
43
44
45
46 def get_optional_jingle():
47     return [('', '')] + [(x.id, x.label) for x in Jingle.objects.all()]
48
49
50 class AddDiffusionForm(forms.Form):
51     jingle = forms.ChoiceField(label=_('Jingle'), choices=get_optional_jingle, required=False)