forms.py 967 Bytes
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()]
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

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


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


class TrackSearchForm(forms.Form):
    q = forms.CharField(label=_('Text'))
    zone = forms.ChoiceField(label=_('Nonstop Zone'), choices=get_optional_nonstop_zones)
    order_by = forms.ChoiceField(label=_('Order'),
            choices=[('alpha', _('Alphabetically'))])