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
from logilab.common.shellutils import ProgressBar
from cubicweb.req import FindEntityError
from cubicweb.web import NotFound
from psycopg2 import DataError
SECTIONSPEC = {
# commented sections are not usefull to view
......@@ -135,24 +138,21 @@ def extract_stats_dict(filepath):
section_name = None
return stats_dict
def eid_from_url(session, value):
def eid_from_url(req, value):
''' return an eid from an url '''
# FIXME - should use url_resolver for a more serious guess
# FIXME - BNF specific right now
#url_resolver = session.vreg['components'].select('urlpublisher',
# vreg=session.vreg)
#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):
url_resolver = req.vreg['components'].select('urlpublisher',
vreg=req.vreg)
req.url = lambda includeparams: value
req.relative_path = lambda includeparams: value[1:]
try:
return int(match.group(1))
except:
pmid, rset = url_resolver.process(req, value)
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
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