Correct joconde search link
authorymh <ymh.work@gmail.com>
Tue, 25 Jun 2013 17:38:09 +0200
changeset 37 b6a04c4ab494
parent 36 f770159c3cee
child 38 7abb8925853d
Correct joconde search link
src/jocondelab/templates/jocondelab/term_edit.html
src/jocondelab/views.py
--- a/src/jocondelab/templates/jocondelab/term_edit.html	Tue Jun 25 16:10:23 2013 +0200
+++ b/src/jocondelab/templates/jocondelab/term_edit.html	Tue Jun 25 17:38:09 2013 +0200
@@ -133,7 +133,7 @@
     <tr>
         <td>{% trans 'Rech. joconde' %}</td>
         <td>
-        <a href='http://www.culture.gouv.fr/public/mistral/joconde_fr?FIELD_1={{term.thesaurus.label}}&VALUE_1={{term.label|urlencode:""}}&ACTION=CHERCHER' target="_blank">Recherche joconde</a>
+        <a href='http://www.culture.gouv.fr/public/mistral/joconde_fr?{{encoded_term_label_query_parameter}}&ACTION=CHERCHER' target="_blank">Recherche joconde</a>
         </td>
     </tr>
     <tr id="edition-wk">
--- a/src/jocondelab/views.py	Tue Jun 25 16:10:23 2013 +0200
+++ b/src/jocondelab/views.py	Tue Jun 25 17:38:09 2013 +0200
@@ -17,6 +17,7 @@
 from django.views.generic import ListView, DetailView, View
 from jocondelab.forms import WikipediaEditionForm, LinkSemanticLevelForm
 import logging
+import urllib
 
 logger = logging.getLogger(__name__)
 
@@ -77,7 +78,24 @@
     def get_context_data(self, **kwargs):        
         context = DetailView.get_context_data(self, **kwargs)
         context['filter_form'] = self.get_filter_form()
-        context['link_semantic_level_choice'] = TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES 
+        context['link_semantic_level_choice'] = TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES
+        
+        field_index = {
+            'DOMN' : 1,
+            'AUTR' : 3,
+            'ECOL' : 4,
+            'REPR' : 5,
+            'PERI' : 6,
+            'EPOQ' : 6,
+            'LIEUX': 4,
+            'SREP' : 9
+        }[self.object.thesaurus.label]
+        
+        encoded_label = self.object.label.encode('latin1') if self.object.label is not None else ""
+        
+        context['encoded_term_label_query_parameter'] = urllib.urlencode({
+                'FIELD_%d' % field_index: self.object.thesaurus.label,
+                'VALUE_%d' % field_index: encoded_label})                                                                          
         return context