can directly paste wikipedia urls
authorymh <ymh.work@gmail.com>
Wed, 10 Jul 2013 18:47:44 +0200
changeset 63 a7f4a418d5af
parent 62 33fd91a414cc
child 64 4f97481fa28b
can directly paste wikipedia urls
src/core/settings.py
src/core/wp_utils.py
src/jocondelab/__init__.py
src/jocondelab/settings.py
--- a/src/core/settings.py	Wed Jul 10 17:34:14 2013 +0200
+++ b/src/core/settings.py	Wed Jul 10 18:47:44 2013 +0200
@@ -18,6 +18,9 @@
 REPR_CONTEXT  = getattr(settings,'REPR_CONTEXT' , 'http://data.culture.fr/thesaurus/resource/ark:/67717/T523')
 SREP_CONTEXT  = getattr(settings,'SREP_CONTEXT' , 'http://data.culture.fr/thesaurus/resource/ark:/67717/T507')
 
-WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = getattr(settings, 'WIKIPEDIA_VERSION_PERMALINK_TEMPLATE', "http://fr.wikipedia.org/w/index.php?oldid=%s")
+WIKIPEDIA_BASE_URL = getattr(settings, "WIKIPEDIA_BASE_URL", "http://fr.wikipedia.org/")
+WIKIPEDIA_PAGE_URL = getattr(settings, "WIKIPEDIA_PAGE_URL", WIKIPEDIA_BASE_URL+"wiki")
+WIKIPEDIA_API_URL = getattr(settings, "WIKIPEDIA_API_URL", WIKIPEDIA_BASE_URL +"w/api.php")
+WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = getattr(settings, 'WIKIPEDIA_VERSION_PERMALINK_TEMPLATE', WIKIPEDIA_BASE_URL +"w/index.php?oldid=%s")
 
 
--- a/src/core/wp_utils.py	Wed Jul 10 17:34:14 2013 +0200
+++ b/src/core/wp_utils.py	Wed Jul 10 18:47:44 2013 +0200
@@ -1,10 +1,12 @@
 # -*- coding: utf-8 -*-
 from .models import Term, TermLabel, TERM_URL_STATUS_DICT
+from core.models.term import TERM_WK_LINK_SEMANTIC_LEVEL_DICT
 from django.conf import settings
 from django.utils.http import urlquote
+from urlparse import urlparse
 from wikitools import api, wiki
 import logging
-from core.models.term import TERM_WK_LINK_SEMANTIC_LEVEL_DICT
+import urllib2
 
 logger = logging.getLogger(__name__)
 site = None
@@ -172,6 +174,10 @@
         
     if not label:
         label = term.label
+    elif label.startswith(settings.WIKIPEDIA_PAGE_URL):
+        url_parts = urlparse(label)
+        label = urllib2.unquote(str(url_parts.path.split('/')[-1])).decode("utf-8")
+
     wp_res = query_wikipedia_title(site, label=label)
     new_label = wp_res['new_label']
     alternative_label= wp_res['alternative_label']
--- a/src/jocondelab/__init__.py	Wed Jul 10 17:34:14 2013 +0200
+++ b/src/jocondelab/__init__.py	Wed Jul 10 18:47:44 2013 +0200
@@ -1,4 +1,4 @@
-VERSION = (0, 9, 0, "final", 0)
+VERSION = (0, 10, 0, "final", 0)
 
 
 def get_version():
--- a/src/jocondelab/settings.py	Wed Jul 10 17:34:14 2013 +0200
+++ b/src/jocondelab/settings.py	Wed Jul 10 18:47:44 2013 +0200
@@ -183,8 +183,10 @@
     }
 }
 
-WIKIPEDIA_API_URL = "http://fr.wikipedia.org/w/api.php"
-WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = "http://fr.wikipedia.org/w/index.php?oldid=%s"
+WIKIPEDIA_BASE_URL = "http://fr.wikipedia.org/"
+WIKIPEDIA_PAGE_URL = WIKIPEDIA_BASE_URL + "wiki"
+WIKIPEDIA_API_URL = WIKIPEDIA_BASE_URL +"w/api.php"
+WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = WIKIPEDIA_BASE_URL + "w/index.php?oldid=%s"
 DBPEDIA_URI_TEMPLATE = "http://fr.dbpedia.org/resource/%s"
 JOCONDE_IMG_BASE_URL = "http://www.culture.gouv.fr/Wave/image/joconde"
 JOCONDE_NOTICE_BASE_URL = "http://www.culture.gouv.fr/public/mistral/joconde_fr?ACTION=CHERCHER&FIELD_98=REF&VALUE_98="