Commit 20681cf9 authored by Arthur Lutz's avatar Arthur Lutz
Browse files

resolve eid in a more appropriate/generic way

parent 5725545efb43
...@@ -22,6 +22,9 @@ from logilab.common.date import previous_month, first_day, date_range, last_day ...@@ -22,6 +22,9 @@ from logilab.common.date import previous_month, first_day, date_range, last_day
from logilab.common.shellutils import ProgressBar from logilab.common.shellutils import ProgressBar
from cubicweb.req import FindEntityError from cubicweb.req import FindEntityError
from cubicweb.web import NotFound
from psycopg2 import DataError
SECTIONSPEC = { SECTIONSPEC = {
# commented sections are not usefull to view # commented sections are not usefull to view
...@@ -135,24 +138,21 @@ def extract_stats_dict(filepath): ...@@ -135,24 +138,21 @@ def extract_stats_dict(filepath):
section_name = None section_name = None
return stats_dict return stats_dict
def eid_from_url(session, value): def eid_from_url(req, value):
''' return an eid from an url ''' ''' return an eid from an url '''
# FIXME - should use url_resolver for a more serious guess url_resolver = req.vreg['components'].select('urlpublisher',
# FIXME - BNF specific right now vreg=req.vreg)
#url_resolver = session.vreg['components'].select('urlpublisher', req.url = lambda includeparams: value
# vreg=session.vreg) req.relative_path = lambda includeparams: value[1:]
#req = session
#req.form = {}
#pmid, rset = url_resolver.process(session, value)
#print value, pmid, rset
for pattern in ['/(\d+)/(.*?)/',
'/(.*?)/(.*?)/(fr|en|es).html',
'/(.*?)/(.*?)/rdf.(xml|n3|nt)']:
match = re.search(pattern, value)
if match and match.group(1):
try: try:
return int(match.group(1)) pmid, rset = url_resolver.process(req, value)
except: if rset and len(rset) == 1:
return rset[0][0]
elif req.form.get('rql'):
rset = req.execute(req.form.get('rql'))
if rset and len(rset) == 1:
return rset[0][0]
except (NotFound, DataError):
pass pass
def get_or_create_statperiod(session, start, stop, stats_report={}): def get_or_create_statperiod(session, start, stop, stats_report={}):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment