Commits

Benoit Boissinot committed 1f4ac98

add initial code support

Comments (0)

Files changed (4)

+upload data: python ../google_appengine/appcfg.py upload_data  --config_file=codeloader.py --filename=articles.csv --kind=CodeArticle --url=http://urnlex.appspot.com/upload .
 - url: /redirect/?
   script: main.py
 
+- url: /upload
+  script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
+  login: admin
 from django.utils import simplejson as json
 import re, urllib, logging, urllib2
 
+from models import CCID, CodeArticle
+
 def quoteurnre(urlre):
     return urllib.quote(urlre, safe='/^$()[]?+.*{}\\')
 
-
-class CCID(db.Model):
-    num = db.StringProperty(required=True)
-    htmlid = db.StringProperty(required=True)
+def resolveetat(query):
+    m = re.search(r'urn:lex:fr:etat:code:(.*?)(~art(.*?))?$', query)
+    onlycode = 'propriete.intellectuelle'
+    if not m or m.group(1) != onlycode:
+        return None
+    article = m.group(3)
+    if article:
+        article = article.lower()
+        id = CodeArticle.all().filter('code = ', m.group(1)).filter('article = ', article).get()
+        if not id:
+            return None
+        args = {'idArticle': id.reflegi}
+        return 'http://www.legifrance.gouv.fr/affichCodeArticle.do?'+urllib.urlencode(args)
+    else:
+        args = {'cidText': 'LEGITEXT000006069414'}
+        return 'http://www.legifrance.gouv.fr/affichCode.do?'+urllib.urlencode(args)
 
 def resolvesenat(query):
     typemapping = {
     return "http://www.conseil-constitutionnel.fr/decision.%s.html" % id.htmlid
 
 resolve = {
+        'etat': resolveetat,
         'senat': resolvesenat,
         'assemblee.nationale': resolvean,
         'conseil.constitutionnel': resolvecc,
+from google.appengine.ext import db
+
+class CCID(db.Model):
+    num = db.StringProperty(required=True)
+    htmlid = db.StringProperty(required=True)
+
+class CodeArticle(db.Model):
+    code = db.StringProperty(required=True)
+    article = db.StringProperty(required=True)
+    reflegi = db.StringProperty(required=True)
+