mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Better behaviour when a domain administrator uses the stats panel.
see #333
This commit is contained in:
@@ -6,6 +6,11 @@ import datetime
|
||||
from django.utils.translation import ugettext as _, ugettext_lazy
|
||||
from modoboa.lib import parameters
|
||||
|
||||
periods = [{"name" : "day", "label" : ugettext_lazy("Day")},
|
||||
{"name" : "week", "label" : ugettext_lazy("Week")},
|
||||
{"name" : "month", "label" : ugettext_lazy("Month")},
|
||||
{"name" : "year", "label" : ugettext_lazy("Year")}]
|
||||
|
||||
def str2Time(y, M, d, h="00", m="00", s="00"):
|
||||
"""Date conversion
|
||||
|
||||
@@ -47,7 +52,7 @@ class Grapher(object):
|
||||
for v, d in graph_tpl.vars.iteritems():
|
||||
defs += [str('DEF:%s=%s:%s:%s' % (v, rrdfile, v, graph_tpl.cf)),
|
||||
str('CDEF:%spm=%s,60,*' % (v, v)),
|
||||
str('VDEF:%s_total=%s,TOTAL' % (v, v)),]
|
||||
str('VDEF:%s_total=%s,TOTAL' % (v, v))]
|
||||
type = d.has_key("type") and d["type"] or "LINE"
|
||||
lines += [str("%s:%spm%s:%s:STACK" % (type, v, d["color"],
|
||||
(d["legend"].encode("utf8")).ljust(20)))]
|
||||
@@ -59,7 +64,7 @@ class Grapher(object):
|
||||
defs.append('GPRINT:%s_first:%s %%c:strftime' % (first_ds, "From"))
|
||||
defs.append('GPRINT:%s_last:%s %%c\\c:strftime' % (first_ds, "to"))
|
||||
defs.append('COMMENT:\\s')
|
||||
|
||||
|
||||
params = defs + lines
|
||||
rrdtool.graph(str(path),
|
||||
"--imgformat", "PNG",
|
||||
|
||||
@@ -9,11 +9,6 @@ from modoboa.lib.exceptions import *
|
||||
from modoboa.lib import events
|
||||
from graph_templates import *
|
||||
|
||||
periods = [{"name" : "day", "label" : ugettext_lazy("Day")},
|
||||
{"name" : "week", "label" : ugettext_lazy("Week")},
|
||||
{"name" : "month", "label" : ugettext_lazy("Month")},
|
||||
{"name" : "year", "label" : ugettext_lazy("Year")}]
|
||||
|
||||
@login_required
|
||||
@permission_required("admin.view_mailboxes")
|
||||
def index(request):
|
||||
@@ -22,9 +17,7 @@ def index(request):
|
||||
"""
|
||||
deflocation = "graphs/?gset=mailtraffic"
|
||||
if not request.user.is_superuser:
|
||||
if len(request.user.get_domains()):
|
||||
deflocation += "&searchquery=%s" % request.user.get_domains()[0].name
|
||||
else:
|
||||
if not len(request.user.get_domains()):
|
||||
raise ModoboaException(_("No statistics available"))
|
||||
|
||||
period = request.GET.get("period", "day")
|
||||
@@ -49,8 +42,12 @@ def graphs(request):
|
||||
tplvars = dict(graphs=[], period=period)
|
||||
if searchq in [None, "global"]:
|
||||
if not request.user.is_superuser:
|
||||
raise PermDeniedException
|
||||
tplvars.update(domain="global")
|
||||
if len(request.user.get_domains()):
|
||||
tplvars.update(domain=request.user.get_domains()[0].name)
|
||||
else:
|
||||
return ajax_simple_response({"status" : "ok"})
|
||||
else:
|
||||
tplvars.update(domain="global")
|
||||
else:
|
||||
domain = Domain.objects.filter(name__contains=searchq)
|
||||
if len(domain) != 1:
|
||||
|
||||
Reference in New Issue
Block a user