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
43840b7dfba7
Commit
9137d103
authored
May 26, 2011
by
Arthur Lutz
Browse files
refactoring and bugfixes
parent
a1f28ddd656a
Changes
1
Hide whitespace changes
Inline
Side-by-side
views/startup.py
View file @
43840b7d
...
...
@@ -33,28 +33,24 @@ from cubicweb.web import formwidgets as fwdgs
from
cubes.awstats.utils
import
SECTIONSPEC
,
SECTIONLABELS
,
\
extract_stats_dict
,
ORIGIN_LABELS
# FIXME - find a clean way to attach or pass this to form so
# it is available in form choices
AWSTATS_DIR
=
'/var/lib/awstats'
#AWSTATS_DIR = self._cw.vreg.config['awstats-dir']
def
extract_available_months
(
form
,
**
attrs
):
""" extract available months from list of awstats files """
months
=
[]
selected_domain
=
form
.
req
.
form
.
get
(
'domain'
,
''
)
for
filename
in
os
.
listdir
(
AWSTATS_DIR
):
selected_domain
=
form
.
_cw
.
form
.
get
(
'domain'
,
''
)
awstats_dir
=
form
.
_cw
.
vreg
.
config
[
'awstats-dir'
]
for
filename
in
os
.
listdir
(
awstats_dir
):
match
=
re
.
search
(
'awstats(\d{6})\.?%s.txt'
%
selected_domain
,
filename
)
if
match
:
months
.
append
(
match
.
group
(
1
))
months
.
sort
()
return
months
# TODO - rename extract_available_time_periods (from awstats-periodicity)
def
extract_available_domains
(
form
,
**
attrs
):
""" extract available domains from list of awstats files """
domains
=
[]
for
filename
in
os
.
listdir
(
AWSTATS_DIR
):
awstats_dir
=
form
.
_cw
.
vreg
.
config
[
'awstats-dir'
]
for
filename
in
os
.
listdir
(
awstats_dir
):
match
=
re
.
search
(
'awstats(\d{2})(\d{4})\.?(.*).txt'
,
filename
)
if
match
and
match
.
group
(
3
)
not
in
domains
:
domains
.
append
(
match
.
group
(
3
))
...
...
@@ -106,7 +102,7 @@ class AwstatsRefreshForm(forms.FieldsForm):
choices
=
extract_available_months
)
limit
=
StringField
(
widget
=
fwdgs
.
Select
(
attrs
=
{
'onchange'
:
'this.form.submit()'
}),
label
=
_
(
'Number of results :'
),
choices
=
[
10
,
25
,
50
,
100
])
choices
=
[
u
'%s'
%
i
for
i
in
(
10
,
25
,
50
,
100
)
])
section
=
StringField
(
widget
=
fwdgs
.
Select
(
attrs
=
{
'onchange'
:
'this.form.submit()'
}),
label
=
_
(
'Show section :'
),
choices
=
[(
''
,
''
),]
+
[(
label
,
value
)
for
value
,
label
in
SECTIONLABELS
.
items
()])
...
...
@@ -129,12 +125,13 @@ class AwstatsView(StartupView):
limit
=
int
(
req
.
form
.
get
(
'limit'
,
10
))
filename
=
'awstats%s%s.txt'
%
(
month
,
domain
and
'.%s'
%
domain
)
awstats_dir
=
self
.
_cw
.
vreg
.
config
[
'awstats-dir'
]
try
:
stats_dict
=
extract_stats_dict
(
AWSTATS_DIR
,
filename
)
stats_dict
=
extract_stats_dict
(
awstats_dir
,
filename
)
except
IOError
:
filename
=
'awstats%s%s.txt'
%
(
extract_available_months
(
form
)[
0
],
domain
and
'.%s'
%
domain
)
stats_dict
=
extract_stats_dict
(
AWSTATS_DIR
,
filename
)
stats_dict
=
extract_stats_dict
(
awstats_dir
,
filename
)
self
.
w
(
u
'<div id="awstats">'
)
self
.
w
(
u
'<h1>%s : %s</h1>'
%
(
_
(
'Domain'
),
domain
or
'default'
))
...
...
@@ -153,14 +150,14 @@ class AwstatsView(StartupView):
self
.
w
(
u
'<div>'
)
self
.
w
(
u
'<table id="navigation">'
)
for
key
in
SECTIONSPEC
.
keys
():
if
stats_dict
[
key
].
values
():
if
key
in
stats_dict
.
keys
()
and
stats_dict
[
key
].
values
():
self
.
w
(
u
'<tr><td><a href="#%s">%s</a></td></tr>'
%
(
key
,
SECTIONLABELS
[
key
]))
self
.
w
(
u
'</table>'
)
self
.
w
(
u
'</div>'
)
def
generic_table
(
self
,
section_name
,
stats_dict
,
limit
):
""" generic table from a section in awstats """
if
not
stats_dict
[
section_name
].
values
():
if
section_name
not
in
stats_dict
.
keys
()
or
not
stats_dict
[
section_name
].
values
():
return
self
.
w
(
u
'<a name="%s"/>'
%
section_name
)
self
.
w
(
u
'<h3>%s</h3>'
%
SECTIONLABELS
[
section_name
])
...
...
@@ -210,7 +207,7 @@ class WebStatsRefreshForm(forms.FieldsForm):
start
=
DateField
(
label
=
_
(
'Start:'
),)
stop
=
DateField
(
label
=
_
(
'Stop:'
),)
limit
=
StringField
(
label
=
_
(
'Number of results :'
),
choices
=
[
10
,
25
,
50
,
100
,
200
,
500
])
choices
=
[
u
'%s'
%
i
for
i
in
(
10
,
25
,
50
,
100
,
200
,
500
)
])
form_buttons
=
[
fwdgs
.
SubmitButton
(
label
=
_
(
'Apply'
))]
...
...
@@ -238,10 +235,7 @@ class StatPeriodsView(StartupView):
self
.
w
(
u
'<h2>%s</h2>'
%
_
(
'from %(start)s to %(stop)s (%(duration)s days)'
%
{
'start'
:
start
,
'stop'
:
stop
,
'duration'
:
duration
.
days
}))
# TODO - slider FacetRangeWidget
rql
=
'Any X,S WHERE X is StatPeriod, X start S'
self
.
wview
(
'calendar'
,
self
.
_cw
.
execute
(
rql
),
'null'
)
self
.
description
()
rset
=
self
.
_cw
.
execute
(
'Any C GROUPBY C WHERE X is Hits, X hit_type C'
)
for
index
,
hit_type
in
enumerate
(
rset
):
self
.
w
(
u
'<h3>%s</h3>'
%
hit_type
[
0
])
...
...
@@ -258,8 +252,7 @@ class StatPeriodsView(StartupView):
self
.
w
(
u
'<td>'
)
typedrql
=
rql
+
', X is %s'
%
etype
rset
=
self
.
_cw
.
execute
(
typedrql
)
self
.
w
(
self
.
_cw
.
view
(
'table'
,
rset
,
'null'
,
headers
=
(
_
(
etype
),
'hits'
)))
self
.
generate_table_form
(
rset
,
etype
)
nolimit_rql
=
typedrql
.
replace
(
'LIMIT %s'
%
limit
,
''
)
self
.
w
(
u
'<a href="%s">Export CSV</a>'
%
self
.
_cw
.
build_url
(
rql
=
nolimit_rql
,
vid
=
'csvexport'
))
...
...
@@ -267,5 +260,12 @@ class StatPeriodsView(StartupView):
self
.
w
(
u
'</tr></table>'
)
else
:
rset
=
self
.
_cw
.
execute
(
rql
)
self
.
w
(
self
.
_cw
.
view
(
'table'
,
rset
,
'null'
)
)
self
.
generate_table_form
(
rset
)
self
.
w
(
u
'</div>'
)
def
generate_table_form
(
self
,
rset
,
etype
):
self
.
w
(
self
.
_cw
.
view
(
'table'
,
rset
,
'null'
))
def
description
(
self
):
pass
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