forms.py 1.44 KB
Newer Older
fred's avatar
fred committed
1
from django import forms
2
from django.utils.translation import ugettext_lazy as _
fred's avatar
fred committed
3

4 5
from .models import Track

fred's avatar
fred committed
6 7
def get_nonstop_zones():
    from emissions.models import Nonstop
8
    return [(x.id, x.title) for x in Nonstop.objects.all() if x.start != x.end]
fred's avatar
fred committed
9

10 11
def get_optional_nonstop_zones():
    return [('', '')] + get_nonstop_zones()
fred's avatar
fred committed
12

13 14 15
def get_search_nonstop_zones():
    return [('', 'All'), ('', '--------------')] + get_nonstop_zones() + [('', '--------------'), ('none', 'None')]

fred's avatar
fred committed
16 17 18
class UploadTracksForm(forms.Form):
    tracks = forms.FileField(widget=forms.ClearableFileInput(
        attrs={'multiple': True, 'accept': 'audio/*'}))
19 20 21
    nonstop_zone = forms.ChoiceField(choices=get_optional_nonstop_zones)


22
class TrackMetaForm(forms.ModelForm):
23 24
    class Meta:
        model = Track
25
        fields = ['language', 'instru', 'sabam', 'cfwb', 'nonstop_zones']
26 27 28


class TrackSearchForm(forms.Form):
29 30 31
    q = forms.CharField(label=_('Text'), required=False)
    zone = forms.ChoiceField(label=_('Nonstop Zone'),
            choices=get_search_nonstop_zones, required=False)
32
    order_by = forms.ChoiceField(label=_('Order'),
33 34 35 36
            required=False,
            choices=[('title', _('Alphabetically')),
                     ('-added_to_nonstop_timestamp', _('Newest first')),
                     ('added_to_nonstop_timestamp', _('Oldest first'))])
37 38 39 40


class CleanupForm(forms.Form):
    zone = forms.ChoiceField(label=_('Nonstop Zone'), choices=get_optional_nonstop_zones)