| author | ymh <ymh.work@gmail.com> |
| Fri, 28 Jun 2013 18:16:58 +0200 | |
| changeset 54 | 040d7a2adb27 |
| parent 51 | 8890db197b37 |
| child 62 | 33fd91a414cc |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
3 |
Created on Jun 13, 2013 |
|
4 |
||
5 |
@author: ymh |
|
6 |
''' |
|
| 15 | 7 |
from core.models import Thesaurus, Term, TERM_URL_STATUS_CHOICES_TRANS |
| 0 | 8 |
from django.forms import Form, fields, ModelChoiceField |
| 15 | 9 |
from django.utils.translation import ugettext_lazy as _ |
| 0 | 10 |
|
11 |
||
12 |
class ValidateTermForm(Form): |
|
13 |
term_id = fields.IntegerField(required=True) |
|
14 |
validation_val = fields.BooleanField(required=False) |
|
|
26
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
15 |
|
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
16 |
class WikipediaEditionForm(Form): |
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
17 |
term_id = fields.IntegerField(required=True) |
|
758b9289aa9a
add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents:
15
diff
changeset
|
18 |
wikipedia_edition = fields.BooleanField(required=False) |
| 0 | 19 |
|
20 |
class ModifyWpLinkForm(Form): |
|
21 |
term_id = fields.IntegerField(required=True) |
|
22 |
label = fields.CharField(required=True, min_length=1) |
|
23 |
||
|
35
859862939996
add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
24 |
class LinkSemanticLevelForm(Form): |
|
859862939996
add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
25 |
term_id = fields.IntegerField(required=True) |
|
859862939996
add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
26 |
link_semantic_level = fields.IntegerField(required=True) |
|
859862939996
add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents:
26
diff
changeset
|
27 |
|
| 0 | 28 |
class RemoveWpLinkForm(Form): |
29 |
term_id = fields.IntegerField(required=True) |
|
30 |
||
31 |
def validated_to_bool(val): |
|
32 |
if isinstance(val, basestring) and len(val)==0: |
|
33 |
return None |
|
34 |
else: |
|
35 |
return bool(int(val)) |
|
36 |
||
37 |
class TermFilterForm(Form): |
|
| 43 | 38 |
thesaurus = ModelChoiceField(label=_("thesaurus"), required=False, queryset=Thesaurus.objects.all().order_by('label')) |
| 15 | 39 |
label = fields.CharField(label=_("label"), required=False) |
40 |
link_status = fields.TypedChoiceField(label=_("link_status"), required=False, empty_value=-1, coerce=int, choices=tuple([(-1,'---------')]+[(v, l) for v,l in TERM_URL_STATUS_CHOICES_TRANS])) |
|
41 |
validated = fields.TypedChoiceField(label=_("validated"), required=False, empty_value=None, coerce=validated_to_bool, choices=(("", "---"),("1", _("yes")), ("0", _("no")))) |
|
| 43 | 42 |
order_by = fields.ChoiceField(label=_("order_by"), required=False, choices=(('normalized_label',_('label')),('nb_notice',_('nb notice')))) |
| 15 | 43 |
order_dir = fields.ChoiceField(label=_("order_dir"), required=False, choices=(('asc',_('asc')), ('desc',_('desc')))) |
| 0 | 44 |
|
45 |
def get_filter_qs(self, base_qs=None): |
|
46 |
qs = base_qs |
|
47 |
if qs is None: |
|
48 |
qs = Term.objects.all() |
|
49 |
||
50 |
thes = self.cleaned_data.get('thesaurus',None) |
|
51 |
if thes: |
|
52 |
qs = qs.filter(thesaurus=thes) |
|
53 |
||
54 |
lk_status = self.cleaned_data.get('link_status',-1) |
|
55 |
if lk_status>=0: |
|
56 |
qs = qs.filter(url_status=lk_status) |
|
57 |
||
58 |
validated = self.cleaned_data.get('validated', None) |
|
59 |
if validated is not None: |
|
60 |
qs = qs.filter(validated=validated) |
|
61 |
||
62 |
label_regexp = self.cleaned_data.get('label', None) |
|
63 |
if label_regexp: |
|
64 |
qs = qs.filter(label__iregex=label_regexp) |
|
65 |
||
66 |
order_by = self.cleaned_data.get('order_by', 'normalized_label') or 'normalized_label' |
|
67 |
order_dir = self.cleaned_data.get('order_dir', 'asc') or 'asc' |
|
68 |
if order_dir == 'desc': |
|
69 |
order_by = "-"+order_by |
|
| 51 | 70 |
if order_by == "normalized_label" or order_by == "label": |
71 |
order_by = [order_by, 'nb_notice', 'id'] |
|
72 |
else: |
|
73 |
order_by = [order_by, 'normalized_label', 'id'] |
|
74 |
qs = qs.order_by(*order_by) |
|
| 0 | 75 |
|
76 |
return qs |