Add filter on "wikipedia edition" field.
authorymh <ymh.work@gmail.com>
Fri, 19 Jul 2013 19:35:34 +0200
changeset 72 db80ba79fb52
parent 71 3fde7d26ad08
child 73 aa87747487ce
Add filter on "wikipedia edition" field. Correct bug #17457
src/jocondelab/forms.py
src/jocondelab/locale/en/LC_MESSAGES/django.mo
src/jocondelab/locale/en/LC_MESSAGES/django.po
src/jocondelab/locale/fr/LC_MESSAGES/django.mo
src/jocondelab/locale/fr/LC_MESSAGES/django.po
--- a/src/jocondelab/forms.py	Fri Jul 19 10:39:17 2013 +0200
+++ b/src/jocondelab/forms.py	Fri Jul 19 19:35:34 2013 +0200
@@ -8,12 +8,12 @@
     TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS)
 from django.forms import Form, fields, ModelChoiceField
 from django.forms.util import flatatt
-from django.forms.widgets import Widget
+from django.forms.widgets import Widget, Select, NullBooleanSelect as DjangoNullBooleanSelect
 from django.utils import formats
 from django.utils.encoding import force_text
 from django.utils.html import format_html, escape
 from django.utils.safestring import mark_safe
-from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext as _, ugettext_lazy
 from jocondelab import settings
 import json
 
@@ -49,6 +49,16 @@
         
         return input_res + dialog_res
 
+class NullBooleanSelect(DjangoNullBooleanSelect):
+    """
+    A Select Widget intended to be used with NullBooleanField.
+    """
+    def __init__(self, attrs=None):
+        choices = (('1', ('---')),
+                   ('2', ugettext_lazy('yes')),
+                   ('3', ugettext_lazy('no')))
+        Select.__init__(self, attrs, choices)
+
 
 class ValidateTermForm(Form):
     term_id = fields.IntegerField(required=True)
@@ -69,12 +79,6 @@
 
 class RemoveWpLinkForm(Form):
     term_id = fields.IntegerField(required=True)
-
-def validated_to_bool(val):
-    if isinstance(val, basestring) and len(val)==0:
-        return None
-    else:
-        return bool(int(val))
          
 class TermFilterForm(Form):
     thesaurus = ModelChoiceField(label=_("thesaurus"), required=False, queryset=Thesaurus.objects.all().order_by('label'))
@@ -82,7 +86,8 @@
     label = fields.CharField(label=_("label"), required=False)
     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]))
     link_semantic_level = fields.TypedChoiceField(label=_("link_semantic_level"), required=False, empty_value=0, coerce=int, choices=TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS)
-    validated = fields.TypedChoiceField(label=_("validated"), required=False, empty_value=None, coerce=validated_to_bool, choices=(("", "---"),("1", _("yes")), ("0", _("no"))))
+    wikipedia_edition = fields.NullBooleanField(label=_("wikipedia_edition"), required=False, widget=NullBooleanSelect)
+    validated = fields.NullBooleanField(label=_("validated"), required=False, widget=NullBooleanSelect)
     order_by = fields.ChoiceField(label=_("order_by"), required=False, choices=(('normalized_label',_('label')),('nb_notice',_('nb notice')),('level',_('level'))))
     order_dir = fields.ChoiceField(label=_("order_dir"), required=False, choices=(('asc',_('asc')), ('desc',_('desc'))))
     
@@ -106,12 +111,16 @@
             
         lk_semantic_level = self.cleaned_data.get('link_semantic_level', 0)
         if lk_semantic_level:
-            qs = qs.filter(link_semantic_level=lk_semantic_level)
+            qs = qs.filter(link_semantic_level=lk_semantic_level)            
             
         validated = self.cleaned_data.get('validated', None)
         if validated is not None:
             qs = qs.filter(validated=validated)
             
+        wikipedia_edition = self.cleaned_data.get('wikipedia_edition', None)
+        if wikipedia_edition is not None:
+            qs = qs.filter(wikipedia_edition=wikipedia_edition)
+            
         label_regexp = self.cleaned_data.get('label', None)
         if label_regexp:
             qs = qs.filter(label__iregex=label_regexp)
Binary file src/jocondelab/locale/en/LC_MESSAGES/django.mo has changed
--- a/src/jocondelab/locale/en/LC_MESSAGES/django.po	Fri Jul 19 10:39:17 2013 +0200
+++ b/src/jocondelab/locale/en/LC_MESSAGES/django.po	Fri Jul 19 19:35:34 2013 +0200
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-18 21:28+0200\n"
+"POT-Creation-Date: 2013-07-19 18:44+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -24,64 +24,68 @@
 msgid "Open Dialog"
 msgstr "Open thesaurus"
 
-#: forms.py:64
+#: forms.py:58
+msgid "yes"
+msgstr "yes"
+
+#: forms.py:59
+msgid "no"
+msgstr "no"
+
+#: forms.py:74
 msgid "Wikipedia version"
 msgstr "Wikipedia version"
 
-#: forms.py:80 templates/jocondelab/term_list.html:20
+#: forms.py:84 templates/jocondelab/term_list.html:20
 msgid "thesaurus"
 msgstr "thesaurus"
 
-#: forms.py:81
+#: forms.py:85
 msgid "thesaurus tree"
 msgstr "thesaurus tree"
 
-#: forms.py:82 forms.py:86 templates/jocondelab/term_edit.html:80
+#: forms.py:86 forms.py:91 templates/jocondelab/term_edit.html:80
 msgid "label"
 msgstr "label"
 
-#: forms.py:83
+#: forms.py:87
 msgid "link_status"
 msgstr "link status"
 
-#: forms.py:84
+#: forms.py:88
 msgid "link_semantic_level"
 msgstr "link level"
 
-#: forms.py:85
+#: forms.py:89
+msgid "wikipedia_edition"
+msgstr "Wp Edit"
+
+#: forms.py:90
 msgid "validated"
 msgstr "valid."
 
-#: forms.py:85
-msgid "yes"
-msgstr "yes"
-
-#: forms.py:85
-msgid "no"
-msgstr "no"
-
-#: forms.py:86
+#: forms.py:91
 msgid "order_by"
 msgstr "order by"
 
-#: forms.py:86 templates/jocondelab/term_edit.html:179
+#: forms.py:91 templates/jocondelab/term_edit.html:179
 #: templates/jocondelab/term_list.html:20
 msgid "nb notice"
 msgstr "nb of notice"
 
-#: forms.py:86 templates/jocondelab/term_list.html:20
+#: forms.py:91 templates/jocondelab/term_list.html:20
 msgid "level"
 msgstr "level"
 
-#: forms.py:87
+#: forms.py:92
 msgid "order_dir"
 msgstr "sort order"
 
-#: forms.py:87
+#: forms.py:92
 msgid "asc"
 msgstr "asc."
 
-#: forms.py:87
+#: forms.py:92
 msgid "desc"
 msgstr "desc."
 
@@ -181,6 +185,3 @@
 #: templates/registration/login.html:19
 msgid "login"
 msgstr "login"
-
-#msgid "English"
-#msgstr "English"
Binary file src/jocondelab/locale/fr/LC_MESSAGES/django.mo has changed
--- a/src/jocondelab/locale/fr/LC_MESSAGES/django.po	Fri Jul 19 10:39:17 2013 +0200
+++ b/src/jocondelab/locale/fr/LC_MESSAGES/django.po	Fri Jul 19 19:35:34 2013 +0200
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-18 21:28+0200\n"
+"POT-Creation-Date: 2013-07-19 18:44+0200\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -25,64 +25,68 @@
 msgid "Open Dialog"
 msgstr "Ouvrir thésaurus"
 
-#: forms.py:64
+#: forms.py:58
+msgid "yes"
+msgstr "oui"
+
+#: forms.py:59
+msgid "no"
+msgstr "non"
+
+#: forms.py:74
 msgid "Wikipedia version"
 msgstr "Version wikipedia"
 
-#: forms.py:80 templates/jocondelab/term_list.html:20
+#: forms.py:84 templates/jocondelab/term_list.html:20
 msgid "thesaurus"
 msgstr "thésaurus"
 
-#: forms.py:81
+#: forms.py:85
 msgid "thesaurus tree"
 msgstr "Arbre du thésaurus"
 
-#: forms.py:82 forms.py:86 templates/jocondelab/term_edit.html:80
+#: forms.py:86 forms.py:91 templates/jocondelab/term_edit.html:80
 msgid "label"
 msgstr "label"
 
-#: forms.py:83
+#: forms.py:87
 msgid "link_status"
 msgstr "statut lien"
 
-#: forms.py:84
+#: forms.py:88
 msgid "link_semantic_level"
 msgstr "niveau lien"
 
-#: forms.py:85
+#: forms.py:89
+msgid "wikipedia_edition"
+msgstr "Édit. wk"
+
+#: forms.py:90
 msgid "validated"
 msgstr "validé"
 
-#: forms.py:85
-msgid "yes"
-msgstr "oui"
-
-#: forms.py:85
-msgid "no"
-msgstr "non"
-
-#: forms.py:86
+#: forms.py:91
 msgid "order_by"
 msgstr "ord. par"
 
-#: forms.py:86 templates/jocondelab/term_edit.html:179
+#: forms.py:91 templates/jocondelab/term_edit.html:179
 #: templates/jocondelab/term_list.html:20
 msgid "nb notice"
 msgstr "nb notice"
 
-#: forms.py:86 templates/jocondelab/term_list.html:20
+#: forms.py:91 templates/jocondelab/term_list.html:20
 msgid "level"
 msgstr "niveau"
 
-#: forms.py:87
+#: forms.py:92
 msgid "order_dir"
 msgstr "ordre tri"
 
-#: forms.py:87
+#: forms.py:92
 msgid "asc"
 msgstr "asc."
 
-#: forms.py:87
+#: forms.py:92
 msgid "desc"
 msgstr "desc."