Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cubicweb
cubes
awstats
Commits
fc379159c6b1
Commit
20681cf9
authored
Jun 29, 2011
by
Arthur Lutz
Browse files
resolve eid in a more appropriate/generic way
parent
5725545efb43
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils.py
View file @
fc379159
...
...
@@ -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,25 +138,22 @@ 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
):
try
:
return
int
(
match
.
group
(
1
))
except
:
pass
url_resolver
=
req
.
vreg
[
'components'
].
select
(
'urlpublisher'
,
vreg
=
req
.
vreg
)
req
.
url
=
lambda
includeparams
:
value
req
.
relative_path
=
lambda
includeparams
:
value
[
1
:]
try
:
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
=
{}):
rql
=
'Any P WHERE P is StatPeriod, P start "%(start_date)s", P stop "%(end_date)s"'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment