Add a way to show trees in the result list for terms.
authorymh <ymh.work@gmail.com>
Tue, 30 Jul 2013 16:21:04 +0200
changeset 81 e78e5a2017b6
parent 80 3851909cb730
child 82 8a67acd1f3aa
Add a way to show trees in the result list for terms. This mode is activated only if a thesaurus is selected, if the "node" sort field is selected and no other field than a thesaurus node is selected.
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
src/jocondelab/templates/jocondelab/partial/term_list_table.html
src/jocondelab/templates/jocondelab/term_list.html
src/jocondelab/views.py
--- a/src/jocondelab/forms.py	Mon Jul 29 22:55:07 2013 +0200
+++ b/src/jocondelab/forms.py	Tue Jul 30 16:21:04 2013 +0200
@@ -95,9 +95,15 @@
     link_semantic_level = fields.TypedChoiceField(label=_("link_semantic_level"), required=False, empty_value=0, coerce=int, choices=TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS)
     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_by = fields.ChoiceField(label=_("order_by"), required=False, choices=(('normalized_label',_('label')),('nb_notice',_('nb notice')),('level',_('level')),('lft', _('order_lft'))))
     order_dir = fields.ChoiceField(label=_("order_dir"), required=False, choices=(('asc',_('asc')), ('desc',_('desc'))))
     
+    def clean(self):
+        fields_not_empty = any([v for k,v in self.cleaned_data.items() if k not in ('thesaurus','thesaurus_tree', 'link_status', 'order_by', 'order_dir')] + [self.cleaned_data.get('link_status', -1) >= 0])
+        self.can_display_level = (not fields_not_empty) and (self.cleaned_data.get('thesaurus',None) is not None) and (self.cleaned_data.get('order_by','normalized_label') == 'lft') 
+        return super(TermFilterForm, self).clean()
+        
+    
     def get_filter_qs(self, base_qs=None):
         qs = base_qs
         
@@ -135,11 +141,15 @@
         order_by = self.cleaned_data.get('order_by', 'normalized_label') or 'normalized_label'
         order_dir = self.cleaned_data.get('order_dir', 'asc') or 'asc'
         if order_dir == 'desc':
-            order_by = "-"+order_by
+            dir_order_by = "-"+order_by
+        else:
+            dir_order_by = order_by
         if order_by == "normalized_label" or order_by == "label":
-            order_by = [order_by, 'nb_notice', 'id']
+            order_by = [dir_order_by, 'nb_notice', 'id']
+        elif order_by == "lft":
+            order_by = ['tree_id', order_by, 'nb_notice', 'id']
         else:
-            order_by = [order_by, 'normalized_label', 'id']
+            order_by = [dir_order_by, 'normalized_label', 'id']
         qs = qs.order_by(*order_by)
         
         return qs
Binary file src/jocondelab/locale/en/LC_MESSAGES/django.mo has changed
--- a/src/jocondelab/locale/en/LC_MESSAGES/django.po	Mon Jul 29 22:55:07 2013 +0200
+++ b/src/jocondelab/locale/en/LC_MESSAGES/django.po	Tue Jul 30 16:21:04 2013 +0200
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-19 18:44+0200\n"
+"POT-Creation-Date: 2013-07-30 16:14+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"
@@ -16,76 +16,80 @@
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: admin.py:11 admin.py:17
+#: admin.py:11 forms.py:173
 msgid "language"
 msgstr "language"
 
-#: forms.py:46 forms.py:48
+#: forms.py:53 forms.py:55
 msgid "Open Dialog"
 msgstr "Open thesaurus"
 
-#: forms.py:58
+#: forms.py:65
 msgid "yes"
 msgstr "yes"
 
-#: forms.py:59
+#: forms.py:66
 msgid "no"
 msgstr "no"
 
-#: forms.py:74
+#: forms.py:81
 msgid "Wikipedia version"
 msgstr "Wikipedia version"
 
-#: forms.py:84 templates/jocondelab/term_list.html:20
+#: forms.py:91 templates/jocondelab/term_list.html:20
 msgid "thesaurus"
 msgstr "thesaurus"
 
-#: forms.py:85
+#: forms.py:92
 msgid "thesaurus tree"
 msgstr "thesaurus tree"
 
-#: forms.py:86 forms.py:91 templates/jocondelab/term_edit.html:80
+#: forms.py:93 forms.py:98 templates/jocondelab/term_edit.html:80
 msgid "label"
 msgstr "label"
 
-#: forms.py:87
+#: forms.py:94
 msgid "link_status"
 msgstr "link status"
 
-#: forms.py:88
+#: forms.py:95
 msgid "link_semantic_level"
 msgstr "link level"
 
-#: forms.py:89
+#: forms.py:96
 msgid "wikipedia_edition"
 msgstr "Wp Edit"
 
-#: forms.py:90
+#: forms.py:97
 msgid "validated"
 msgstr "valid."
 
-#: forms.py:91
+#: forms.py:98
 msgid "order_by"
 msgstr "order by"
 
-#: forms.py:91 templates/jocondelab/term_edit.html:179
+#: forms.py:98 templates/jocondelab/term_edit.html:181
 #: templates/jocondelab/term_list.html:20
 msgid "nb notice"
 msgstr "nb of notice"
 
-#: forms.py:91 templates/jocondelab/term_list.html:20
+#: forms.py:98 templates/jocondelab/term_list.html:20
 msgid "level"
 msgstr "level"
 
-#: forms.py:92
+#: forms.py:98
+msgid "order_lft"
+msgstr "node"
+
+#: forms.py:99
 msgid "order_dir"
 msgstr "sort order"
 
-#: forms.py:92
+#: forms.py:99
 msgid "asc"
 msgstr "asc."
 
-#: forms.py:92
+#: forms.py:99
 msgid "desc"
 msgstr "desc."
 
@@ -123,23 +127,23 @@
 msgid "info wikipedia"
 msgstr "Wikipedia info"
 
-#: templates/jocondelab/term_edit.html:119
+#: templates/jocondelab/term_edit.html:121
 msgid "Créer page WK"
 msgstr "Create WK page"
 
-#: templates/jocondelab/term_edit.html:119
+#: templates/jocondelab/term_edit.html:121
 msgid "Need wikipedia article"
 msgstr "Need wikipedia article"
 
-#: templates/jocondelab/term_edit.html:150
+#: templates/jocondelab/term_edit.html:152
 msgid "Rech. joconde"
 msgstr "Joconde search"
 
-#: templates/jocondelab/term_edit.html:156
+#: templates/jocondelab/term_edit.html:158
 msgid "Edition wk"
 msgstr "WK Edition"
 
-#: templates/jocondelab/term_edit.html:183
+#: templates/jocondelab/term_edit.html:185
 msgid "notices"
 msgstr "notices"
 
Binary file src/jocondelab/locale/fr/LC_MESSAGES/django.mo has changed
--- a/src/jocondelab/locale/fr/LC_MESSAGES/django.po	Mon Jul 29 22:55:07 2013 +0200
+++ b/src/jocondelab/locale/fr/LC_MESSAGES/django.po	Tue Jul 30 16:21:04 2013 +0200
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-07-19 18:44+0200\n"
+"POT-Creation-Date: 2013-07-30 16:14+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"
@@ -17,76 +17,80 @@
 "Content-Transfer-Encoding: 8bit\n"
 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
 
-#: admin.py:11 admin.py:17
+#: admin.py:11 forms.py:173
 msgid "language"
 msgstr "langue"
 
-#: forms.py:46 forms.py:48
+#: forms.py:53 forms.py:55
 msgid "Open Dialog"
 msgstr "Ouvrir thésaurus"
 
-#: forms.py:58
+#: forms.py:65
 msgid "yes"
 msgstr "oui"
 
-#: forms.py:59
+#: forms.py:66
 msgid "no"
 msgstr "non"
 
-#: forms.py:74
+#: forms.py:81
 msgid "Wikipedia version"
 msgstr "Version wikipedia"
 
-#: forms.py:84 templates/jocondelab/term_list.html:20
+#: forms.py:91 templates/jocondelab/term_list.html:20
 msgid "thesaurus"
 msgstr "thésaurus"
 
-#: forms.py:85
+#: forms.py:92
 msgid "thesaurus tree"
 msgstr "Arbre du thésaurus"
 
-#: forms.py:86 forms.py:91 templates/jocondelab/term_edit.html:80
+#: forms.py:93 forms.py:98 templates/jocondelab/term_edit.html:80
 msgid "label"
 msgstr "label"
 
-#: forms.py:87
+#: forms.py:94
 msgid "link_status"
 msgstr "statut lien"
 
-#: forms.py:88
+#: forms.py:95
 msgid "link_semantic_level"
 msgstr "niveau lien"
 
-#: forms.py:89
+#: forms.py:96
 msgid "wikipedia_edition"
 msgstr "Édit. wk"
 
-#: forms.py:90
+#: forms.py:97
 msgid "validated"
 msgstr "validé"
 
-#: forms.py:91
+#: forms.py:98
 msgid "order_by"
 msgstr "ord. par"
 
-#: forms.py:91 templates/jocondelab/term_edit.html:179
+#: forms.py:98 templates/jocondelab/term_edit.html:181
 #: templates/jocondelab/term_list.html:20
 msgid "nb notice"
 msgstr "nb notice"
 
-#: forms.py:91 templates/jocondelab/term_list.html:20
+#: forms.py:98 templates/jocondelab/term_list.html:20
 msgid "level"
 msgstr "niveau"
 
-#: forms.py:92
+#: forms.py:98
+msgid "order_lft"
+msgstr "node"
+
+#: forms.py:99
 msgid "order_dir"
 msgstr "ordre tri"
 
-#: forms.py:92
+#: forms.py:99
 msgid "asc"
 msgstr "asc."
 
-#: forms.py:92
+#: forms.py:99
 msgid "desc"
 msgstr "desc."
 
@@ -124,23 +128,23 @@
 msgid "info wikipedia"
 msgstr "info wikipedia"
 
-#: templates/jocondelab/term_edit.html:119
+#: templates/jocondelab/term_edit.html:121
 msgid "Créer page WK"
 msgstr "Créer page WK"
 
-#: templates/jocondelab/term_edit.html:119
+#: templates/jocondelab/term_edit.html:121
 msgid "Need wikipedia article"
 msgstr "Besoin article Wikipedia"
 
-#: templates/jocondelab/term_edit.html:150
+#: templates/jocondelab/term_edit.html:152
 msgid "Rech. joconde"
 msgstr "Rech. Joconde"
 
-#: templates/jocondelab/term_edit.html:156
+#: templates/jocondelab/term_edit.html:158
 msgid "Edition wk"
 msgstr "Edition wk"
 
-#: templates/jocondelab/term_edit.html:183
+#: templates/jocondelab/term_edit.html:185
 msgid "notices"
 msgstr "notices"
 
--- a/src/jocondelab/templates/jocondelab/partial/term_list_table.html	Mon Jul 29 22:55:07 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/partial/term_list_table.html	Tue Jul 30 16:21:04 2013 +0200
@@ -8,7 +8,7 @@
         <tbody>
         {% for term in object_list %}
         <tr class="{% cycle 'hdabooddline' 'hdaboevenline' %}" id="term-{{term.id}}">
-            <td class="{{term.url_status_text}} term-list-label"><a href="{% url 'term' term_id=term.id %}{% append_to_param %}">{{ term.label }}</a></td>
+            <td class="{{term.url_status_text}} term-list-label" {% if show_levels %}style="padding-left: {{ term.corrected_level }}em"{% endif %}><a href="{% url 'term' term_id=term.id %}{% append_to_param %}">{{ term.label }}</a></td>
             <td class="text_centered">{{ term.thesaurus.label }}</td>
             <td class="text_centered">{{ term.level }}</td>
             <td class="text_centered">
--- a/src/jocondelab/templates/jocondelab/term_list.html	Mon Jul 29 22:55:07 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/term_list.html	Tue Jul 30 16:21:04 2013 +0200
@@ -22,7 +22,7 @@
         <tbody>
         {% for term in object_list %}
         <tr class="{% cycle 'hdabooddline' 'hdaboevenline' %}">
-            <td class="{{term.url_status_text}} term-list-label"><a href="{% url 'term' term_id=term.id %}{% append_to_param %}">{{ term.label }}</a></td>
+            <td class="{{term.url_status_text}} term-list-label" {% if show_levels %}style="padding-left: {{ term.corrected_level }}em"{% endif %} ><a href="{% url 'term' term_id=term.id %}{% append_to_param %}">{{ term.label }}</a></td>
             <td class="text_centered">{{ term.thesaurus.label }}</td>
             <td class="text_centered">{{ term.level }}</td>            
             <td class="text_centered">
--- a/src/jocondelab/views.py	Mon Jul 29 22:55:07 2013 +0200
+++ b/src/jocondelab/views.py	Tue Jul 30 16:21:04 2013 +0200
@@ -44,7 +44,24 @@
     
     def get_context_data(self, **kwargs):
         context = ListView.get_context_data(self, **kwargs)
-        context['filter_form'] = self.get_filter_form()
+        filter_form = self.get_filter_form()
+        context['filter_form'] = filter_form
+        page = context.get('page_obj', None)
+        if page and self.can_display_level:
+            levels = [t.level for t in page.object_list]
+            min_level = min(levels)
+            max_level = max(levels)
+            if max_level > 0 :
+                context['show_levels'] = True
+                new_object_list = []
+                for t in page.object_list:
+                    t.corrected_level = 2*(t.level-min_level)
+                    new_object_list.append(t)
+                page.object_list = new_object_list
+            else:
+                context['show_levels'] = False
+        else:
+            context['show_level'] = False
         context['term_tree_valid_thesaurus'] = json.dumps([entry['thesaurus__id'] for entry in Term.objects.root_nodes().values('thesaurus__id').annotate(root_nodes_count=Count('thesaurus__id')).order_by().filter(root_nodes_count__lt=settings.JOCONDE_TERM_TREE_MAX_ROOT_NODE)])  # @UndefinedVariable
         return context
     
@@ -52,8 +69,10 @@
         qs = super(TermListView, self).get_queryset()
         filter_form = self.get_filter_form()
         if filter_form.is_valid():
+            self.can_display_level = filter_form.can_display_level            
             return filter_form.get_filter_qs(qs)
         else:
+            self.can_display_level = False
             return None
 
 class TermListTableView(TermListView):
@@ -84,6 +103,7 @@
         qs = self.queryset._clone()
         filter_form = self.get_filter_form()
         if filter_form.is_valid():
+            self.can_display_level = filter_form.can_display_level
             return filter_form.get_filter_qs(qs)
         else:
             return None
@@ -120,6 +140,24 @@
         context['wikipedia_lang_list'] = settings.WIKIPEDIA_URLS.keys()
         context['wikipedia_urls'] = json.dumps(settings.WIKIPEDIA_URLS)
         
+        page = context.get('page_obj', None)
+        if page and self.can_display_level:
+            levels = [t.level for t in page.object_list]
+            min_level = min(levels)
+            max_level = max(levels)
+            if max_level > 0 :
+                context['show_levels'] = True
+                new_object_list = []
+                for t in page.object_list:
+                    t.corrected_level = 2*(t.level-min_level)
+                    new_object_list.append(t)
+                page.object_list = new_object_list
+            else:
+                context['show_levels'] = False
+        else:
+            context['show_level'] = False
+
+        
         field_index = {
             'DOMN' : 1,
             'AUTR' : 3,