-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathviews.py
74 lines (68 loc) · 2.16 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
""" Welborn Productions - Stats
Gathers stats about projects, posts, etc. and displays them.
Stats tools can also be imported for use with the wpstats command.
"""
import logging
from django.contrib.auth.decorators import login_required
from apps.models import wp_app
from apps.paste.models import wp_paste
from blogger.models import wp_blog
from downloads.models import file_tracker
from img.models import wp_image
from misc.models import wp_misc
from projects.models import wp_project
from stats import tools
from wp_main.utilities import responses
log = logging.getLogger('wp.stats')
@login_required(login_url='/login')
def view_index(request):
""" Render the landing page for /stats and show a general
overview of all the stats.
"""
if not request.user.is_authenticated():
# Not authenticated, return the bad login page. No stats for you!
return responses.clean_response(
'home/badlogin.html',
context=context,
request=request)
# Build the stats page for all known models.
modelinf = {
file_tracker: {
'orderby': '-download_count',
'displayattr': 'shortname'
},
wp_app: {
'orderby': '-view_count',
'displayattr': 'name'
},
wp_blog: {
'orderby': '-view_count',
'displayattr': 'slug'
},
wp_image: {
'orderby': '-view_count',
'displayattr': ('image_id', 'title', 'image.name'),
'displayformat': '{image_id} - {title} ({image-name})'
},
wp_misc: {
'orderby': '-download_count',
'displayattr': 'name'
},
wp_paste: {
'orderby': '-view_count',
'displayattr': ('paste_id', 'title'),
'displayformat': '{paste_id} - {title}'
},
wp_project: {
'orderby': '-download_count',
'displayattr': 'name'
}
}
context = {
'label': 'all models',
'stats': tools.get_models_info(modelinf),
}
return responses.clean_response(
'stats/index.html',
context=context,
request=request)