forms.py
3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#-*- coding:utf-8 -*-
from django.forms import CharField, ChoiceField, Form, ModelChoiceField
from semantics.models import GeneralSelectivePreference, SelectivePreferenceRelations, SemanticRole
class RoleForm(Form):
negation = ChoiceField(choices=[('', u'---'), ('!', u'!')], required=False,
label=u'')
role = ModelChoiceField(label=u'Rola', required=False,
queryset=SemanticRole.objects.filter(gradient__isnull=True))
attribute = ModelChoiceField(label=u'Atrybut', required=False,
queryset=SemanticRole.objects.filter(gradient__isnull=False))
preference_type = ChoiceField(choices=[('general', u'Predefiniowana'), ('synset', u'Słowosieć'), ('relation', u'Relacja')],
label=u'Preferencje selekcyjne', required=False)
preferences = []
def __init__(self, negation=None, sel_role=None, sel_attribute=None,
sel_preferences=[],
*args, **kwargs):
super(RoleForm, self).__init__(*args, **kwargs)
self.fields['negation'].initial = negation
self.fields['role'].initial = sel_role
self.fields['attribute'].initial = sel_attribute
self.preferences = sel_preferences
class GeneralSelPrefForm(Form):
general_pref = ModelChoiceField(label=u'Predefiniowana',
queryset=GeneralSelectivePreference.objects.order_by('name'), required=False)
def pref_type(self):
return 'general'
def __init__(self, sel_preference=None, *args, **kwargs):
super(GeneralSelPrefForm, self).__init__(*args, **kwargs)
self.fields['general_pref'].initial = sel_preference
class SynsetSelPrefForm(Form):
synset_pref = CharField(label=u'Słowosieć', required=False)
def pref_type(self):
return 'synset'
def __init__(self, sel_preference=None, *args, **kwargs):
super(SynsetSelPrefForm, self).__init__(*args, **kwargs)
self.fields['synset_pref'].initial = sel_preference
class RelationalSelPrefForm(Form):
relational_pref_relation = ModelChoiceField(label=u'Relacja',
queryset=SelectivePreferenceRelations.objects.all(), required=False)
relational_pref_role = ModelChoiceField(label=u'Rola', required=False,
queryset=SemanticRole.objects.filter(gradient__isnull=True))
relational_pref_attribute = ModelChoiceField(label=u'Atrybut', required=False,
queryset=SemanticRole.objects.filter(gradient__isnull=False))
def pref_type(self):
return 'relational'
def __init__(self, sel_relation=None, sel_role=None, sel_attribute=None, *args, **kwargs):
super(RelationalSelPrefForm, self).__init__(*args, **kwargs)
self.fields['relational_pref_relation'].initial = sel_relation
self.fields['relational_pref_role'].initial = sel_role
self.fields['relational_pref_attribute'].initial = sel_attribute