forms.py 1.63 KB
# -*- coding: utf-8 -*-
from django.forms import Form, ModelMultipleChoiceField, ModelChoiceField, \
    BooleanField, CharField, Textarea

from dictionary.forms import QualifierField
from dictionary.models import Vocabulary, Variant, visible_vocabularies


class ExportForm(Form):
    vocabs = ModelMultipleChoiceField(
        queryset=Vocabulary.objects.all(), label=u'słowniki')
    antivocabs = ModelMultipleChoiceField(
        queryset=Vocabulary.objects.all(), label=u'antysłowniki',
        required=False)
    variant = ModelChoiceField(
        queryset=Variant.objects.filter(type=Variant.TYPE_EXPORT),
        label=u'wariant')
    # refl = BooleanField(label=u'tagi z "refl"', required=False)
    commonness = BooleanField(label=u'etykiety pospolitości', required=False,
                              initial=True)
    dict_id = CharField(
        label=u'identyfikator słownika',
        help_text=u'Znaczniki %Y, %m i %d wstawiają odpowiednio aktualny '
                  u'rok, miesiąc i dzień')
    copyright = CharField(widget=Textarea(attrs={'cols': 80, 'rows': 20}))
    # excluding_qualifiers = QualifiersField(
    #     required=False, label=u'kwal. wykluczające')

    def __init__(self, user, **kwargs):
        super(ExportForm, self).__init__(**kwargs)
        self.fields['vocabs'].queryset = visible_vocabularies(user)
        self.fields['antivocabs'].queryset = visible_vocabularies(user)
        self.fields['vocabs'].help_text = u''
        self.fields['antivocabs'].help_text = u''


class MagicQualifierForm(Form):
    qualifier = QualifierField(label=u'kwal. leksemu')
    regex = CharField(label=u'wzorzec tagu', required=False)