/
index.py
119 lines (101 loc) · 4.18 KB
/
index.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2009 Zuza Software Foundation
#
# This file is part of Pootle.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import locale
from django.conf import settings
from django.utils.translation import ugettext as _
from django.shortcuts import render_to_response
from django.template import RequestContext
from pootle_app.models import Directory
from pootle_app.models.permissions import (get_matching_permissions,
check_permission)
from pootle_app.views.language.item_dict import add_percentages
from pootle_app.views.top_stats import gentopstats_root
from pootle.i18n.gettext import tr_lang
from pootle_language.models import Language
from pootle_misc.stats import get_raw_stats
from pootle_project.models import Project
from pootle_profile.models import get_profile
from pootle_statistics.models import Submission
def get_items(request, model, get_last_action, name_func):
items = []
if not check_permission('view', request):
return items
for item in model.objects.iterator():
stats = get_raw_stats(item)
items.append({
'code': item.code,
'name': name_func(item.fullname),
'lastactivity': get_last_action(item),
'stats': stats,
'completed_title': _("%(percentage)d%% complete",
{'percentage': stats['translated']['percentage']}),
})
items.sort(lambda x, y: locale.strcoll(x['name'], y['name']))
return items
def getlanguages(request):
def get_last_action(item):
try:
return Submission.objects.filter(
translation_project__language=item).latest().as_html()
except Submission.DoesNotExist:
return ''
return get_items(request, Language, get_last_action, tr_lang)
def getprojects(request):
def get_last_action(item):
try:
return Submission.objects.filter(
translation_project__project=item).latest().as_html()
except Submission.DoesNotExist:
return ''
return get_items(request, Project, get_last_action, lambda name: name)
def view(request):
request.permissions = get_matching_permissions(get_profile(request.user), Directory.objects.root)
topstats = gentopstats_root()
languages = getlanguages(request)
templatevars = {
'description': _(settings.DESCRIPTION),
'keywords': [
'Pootle',
'translate',
'translation',
'localisation',
'localization',
'l10n',
'traduction',
'traduire',
],
'languages': languages,
'projects': getprojects(request),
'topstats': topstats,
'translationlegend': {'translated': _('Translations are complete'),
'fuzzy': _('Translations need to be checked (they are marked fuzzy)'),
'untranslated': _('Untranslated')},
'permissions': request.permissions,
}
visible_langs = [l for l in languages if l['stats']['total']['words'] != 0]
templatevars['moreprojects'] = len(templatevars['projects']) >\
len(visible_langs)
if request.user.is_superuser:
from pootle_misc.siteconfig import load_site_config
from pootle_app.forms import GeneralSettingsForm
siteconfig = load_site_config()
setting_form = GeneralSettingsForm(siteconfig)
templatevars['form'] = setting_form
return render_to_response('index/index.html', templatevars, RequestContext(request))