* Added pagination for admin pages (domains, mailboxes, etc.)

* Code refactoring

see #76
This commit is contained in:
Antoine Nguyen
2011-07-26 14:53:43 +02:00
parent ee6d9554af
commit 81a03d6c65
19 changed files with 381 additions and 226 deletions
+2
View File
@@ -17,3 +17,5 @@ parameters.register_admin("MAILDIR_ROOT", type="string", deflt=".maildir",
parameters.register_admin("PASSWORD_SCHEME", type="list", deflt="crypt", parameters.register_admin("PASSWORD_SCHEME", type="list", deflt="crypt",
values=[("crypt", "crypt"), ("md5", "md5"), ("clear", "clear")], values=[("crypt", "crypt"), ("md5", "md5"), ("clear", "clear")],
help=_("Scheme used to crypt mailbox passwords")) help=_("Scheme used to crypt mailbox passwords"))
parameters.register_admin("ITEMS_PER_PAGE", type="int", deflt=30,
help=_("Number of displayed items per page"))
+33
View File
@@ -62,6 +62,15 @@ class DatesAware(models.Model):
ObjectDates.set_for_object(self) ObjectDates.set_for_object(self)
super(DatesAware, self).save(*args, **kwargs) super(DatesAware, self).save(*args, **kwargs)
def __creation(self):
return self.dates.creation
def __last_modification(self):
return self.dates.last_modification
creation = property(__creation)
last_modification = property(__last_modification)
class Domain(DatesAware): class Domain(DatesAware):
name = models.CharField(_('name'), max_length=100, unique=True, name = models.CharField(_('name'), max_length=100, unique=True,
help_text=_("The domain name")) help_text=_("The domain name"))
@@ -157,6 +166,11 @@ class Mailbox(DatesAware):
full_address = property(__full_address) full_address = property(__full_address)
def __enabled(self):
return self.user.is_active
enabled = property(__enabled)
def create_dir(self): def create_dir(self):
relpath = "%s/%s" % (self.domain.name, self.address) relpath = "%s/%s" % (self.domain.name, self.address)
abspath = os.path.join(parameters.get_admin("STORAGE_PATH"), relpath) abspath = os.path.join(parameters.get_admin("STORAGE_PATH"), relpath)
@@ -273,6 +287,16 @@ class Alias(DatesAware):
("view_aliases", "View aliases"), ("view_aliases", "View aliases"),
) )
def __full_address(self):
return "%s@%s" % (self.address, self.domain.name)
full_address = property(__full_address)
def __targets(self):
ret = "<br/>".join(map(lambda m: str(m), self.mboxes.all()))
ret += "<br/>" + self.repr_extmboxes()
return ret
targets = property(__targets)
def save(self, int_targets, ext_targets, *args, **kwargs): def save(self, int_targets, ext_targets, *args, **kwargs):
if len(ext_targets): if len(ext_targets):
self.extmboxes = ",".join(ext_targets) self.extmboxes = ",".join(ext_targets)
@@ -320,6 +344,15 @@ class Alias(DatesAware):
""" """
return "<br/>".join(self.extmboxes.split(",")) return "<br/>".join(self.extmboxes.split(","))
def ui_disabled(self, user):
if user.is_superuser:
return False
usermb = Mailbox.objects.get(user=user.id)
for mb in self.mboxes.all():
if mb.domain.id != usermb.domain.id:
return True
return False
class Extension(models.Model): class Extension(models.Model):
name = models.CharField(max_length=150) name = models.CharField(max_length=150)
enabled = models.BooleanField(_('enabled'), enabled = models.BooleanField(_('enabled'),
+2 -2
View File
@@ -73,7 +73,7 @@ class SuperAdminsPerms(Permissions):
"full_name" : "%s %s" % (admin.first_name, admin.last_name), "full_name" : "%s %s" % (admin.first_name, admin.last_name),
"date_joined" : admin.date_joined, "date_joined" : admin.date_joined,
"enabled" : admin.is_active}] "enabled" : admin.is_active}]
return SuperAdminsTable(admins_list).render(request) return SuperAdminsTable(request, admins_list).render()
class DomainAdminsPerms(Permissions): class DomainAdminsPerms(Permissions):
@@ -123,7 +123,7 @@ class DomainAdminsPerms(Permissions):
domadmins_list = [] domadmins_list = []
for admin in domadmins: for admin in domadmins:
domadmins_list += [admin.tohash()] domadmins_list += [admin.tohash()]
return DomainAdminsTable(domadmins_list).render(request) return DomainAdminsTable(request, domadmins_list).render()
def get_perms_class(user, role): def get_perms_class(user, role):
"""Retrieves the class associated to a given role """Retrieves the class associated to a given role
+130
View File
@@ -0,0 +1,130 @@
# coding: utf-8
from django.utils.translation import ugettext as _
from modoboa.lib import tables
from templatetags.admin_extras import *
class DomsTable(tables.Table):
tableid = "objects_table"
idkey = "id"
name = tables.Column("name", label=_("Name"))
creation = tables.Column("creation", label=_("Created"), width="160px")
modified = tables.Column("last_modification", label=_("Last modified"),
width="160px")
domaliases = tables.Column("domainalias_set", label=_("Domain aliases"),
width="100px", align="center")
mboxes = tables.Column("mailbox_set", label=_("Mailboxes"),
width="100px", align="center")
mbaliases = tables.Column("mbalias_counter", label=_("Mailbox aliases"),
width="100px", align="center")
quota = tables.Column("quota", label=_("Quota"), width="50px", align="center")
enabled = tables.Column("enabled", label=_("Enabled"), width="50px",
align="center")
actions = tables.ActionColumn("actions", label=_("Actions"), width="50px",
align="center", defvalue=domain_actions)
cols_order = ["name", "creation", "modified",
"domaliases", "mboxes", "mbaliases",
"quota", "enabled", "actions"]
def __init__(self, request, doms):
super(DomsTable, self).__init__(request)
self.populate(self._rows_from_model(doms))
def parse_domainalias_set(self, value):
return len(value.all())
def parse_mailbox_set(self, value):
return len(value.all())
def parse_quota(self, value):
return "%s %s" % (value, _("MB"))
def parse_enabled(self, value):
return _("yes") if value else _("no")
class DomAliasesTable(tables.Table):
tableid = "objects_table"
idkey = "id"
name = tables.Column("name", label=_("Name"))
target = tables.Column("target", label=_("Targeted domain"))
creation = tables.Column("creation", label=_("Created"), width="170px")
modified = tables.Column("last_modification", label=_("Last modified"),
width="170px")
enabled = tables.Column("enabled", label=_("Enabled"), width="50px",
align="center")
actions = tables.ActionColumn("actions", label=_("Actions"), width="50px",
align="center", defvalue=domalias_actions)
cols_order = ["name", "target", "creation",
"modified", "enabled", "actions"]
def __init__(self, request, domaliases):
super(DomAliasesTable, self).__init__(request)
self.populate(self._rows_from_model(domaliases))
def parse_enabled(self, value):
return _("yes") if value else _("no")
class MailboxesTable(tables.Table):
tableid = "objects_table"
idkey = "id"
address = tables.Column("address", label=_("Address"))
name = tables.Column("name", label=_("Name"))
creation = tables.Column("creation", label=_("Created"), width="160px")
modified = tables.Column("last_modification", label=_("Last modified"),
width="160px")
aliases = tables.Column("alias_set", label=_("Aliases"), width="70px",
align="center")
quota = tables.Column("quota", label=_("Quota"), width="50px", align="center")
enabled = tables.Column("enabled", label=gender("Enabled", "f"), width="50px",
align="center")
actions = tables.ActionColumn("actions", label=_("Actions"), width="70px",
align="center", defvalue=mailbox_actions)
cols_order = ["address", "name", "creation", "modified", "aliases",
"quota", "enabled", "actions"]
def __init__(self, request, mailboxes):
super(MailboxesTable, self).__init__(request)
self.populate(self._rows_from_model(mailboxes))
def parse_alias_set(self, value):
return len(value.all())
def parse_quota(self, value):
return "%s %s" % (value, _("MB"))
def parse_enabled(self, value):
return _("yes") if value else _("no")
class MbAliasesTable(tables.Table):
tableid = "objects_table"
idkey = "id"
address = tables.Column("full_address", label=_("Address"))
targets = tables.Column("targets", label=_("Target(s)"), safe=True)
creation = tables.Column("creation", label=_("Created"), width="170px")
modified = tables.Column("last_modification", label=_("Last modified"),
width="170px")
enabled = tables.Column("enabled", label=gender("Enabled", "m"), width="50px",
align="center")
actions = tables.ActionColumn("actions", label=_("Actions"), width="50px",
align="center", defvalue=mbalias_actions)
cols_order = ["address", "targets", "creation", "modified", "enabled", "actions"]
def __init__(self, request, aliases):
super(MbAliasesTable, self).__init__(request)
self.populate(self._rows_from_model(aliases))
def rowoptions(self, request, alias):
return "{ui_disabled : '%s'}" % alias.ui_disabled(request.user)
def parse_enabled(self, value):
return _("yes") if value else _("no")
+10 -5
View File
@@ -170,26 +170,31 @@ def domalias_actions(user, aid):
return render_actions(actions) return render_actions(actions)
@register.simple_tag @register.simple_tag
def mailbox_actions(user, mbox): def mailbox_actions(user, mboxid):
actions = [ actions = [
{"name" : "editmailbox", {"name" : "editmailbox",
"url" : reverse(admin.views.editmailbox, args=[mbox.id]), "url" : reverse(admin.views.editmailbox, args=[mboxid]),
"img" : static_url("pics/edit.png"), "img" : static_url("pics/edit.png"),
"title" : _("Edit mailbox"), "title" : _("Edit mailbox"),
"class" : "boxed", "class" : "boxed",
"rel" : "{handler:'iframe',size:{x:300,y:320}}"}, "rel" : "{handler:'iframe',size:{x:300,y:320}}"},
{"name" : "aliases", {"name" : "aliases",
"url" : reverse(admin.views.mbaliases) + "?mbid=%d" % mbox.id, "url" : reverse(admin.views.mbaliases) + "?mbid=%d" % mboxid,
"img" : static_url("pics/alias.png"), "img" : static_url("pics/alias.png"),
"title" : _("View this mailbox aliases")}, "title" : _("View this mailbox aliases")},
] ]
return render_actions(actions) return render_actions(actions)
@register.simple_tag @register.simple_tag
def mbalias_actions(user, alias): def mbalias_actions(user, aliasid):
from admin.models import Alias
alias = Alias.objects.get(pk=aliasid)
if alias.ui_disabled(user):
return "--"
actions = [ actions = [
{"name" : "editmbalias", {"name" : "editmbalias",
"url" : reverse(admin.views.editmbalias, args=[alias.id]), "url" : reverse(admin.views.editmbalias, args=[aliasid]),
"img" : static_url("pics/edit.png"), "img" : static_url("pics/edit.png"),
"title" : _("Edit mailbox alias"), "title" : _("Edit mailbox alias"),
"class" : "boxed", "class" : "boxed",
+49 -24
View File
@@ -10,11 +10,13 @@ from django.db.models import Q
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django.contrib import messages from django.contrib import messages
from django.db import transaction, IntegrityError from django.db import transaction, IntegrityError
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from lib import * from lib import *
from modoboa import admin, userprefs from modoboa import admin, userprefs
from models import * from models import *
from admin.permissions import * from admin.permissions import *
from admin.tables import *
from modoboa.lib import crypt_password from modoboa.lib import crypt_password
from modoboa.lib import _render, ajax_response, ajax_simple_response, \ from modoboa.lib import _render, ajax_response, ajax_simple_response, \
getctx, events, parameters getctx, events, parameters
@@ -22,14 +24,28 @@ from modoboa.lib.emailutils import split_mailbox
from modoboa.lib.models import Parameter from modoboa.lib.models import Parameter
import copy import copy
def render_domains_page(request, page, **kwargs): def render_domains_page(request, objtype, tblclass, tplname="admin/listing.html",
template = "admin/%s.html" % page **kwargs):
if request.GET.has_key("domid"): if request.GET.has_key("domid"):
kwargs["domid"] = request.GET["domid"] kwargs["domid"] = request.GET["domid"]
else: else:
kwargs["domid"] = "" kwargs["domid"] = ""
kwargs["selection"] = page kwargs["selection"] = objtype
return _render(request, template, kwargs) paginator = Paginator(kwargs["objects"],
int(parameters.get_admin("ITEMS_PER_PAGE")))
try:
page = request.GET.get("page", "1")
except ValueError:
page = 1
try:
kwargs["objects"] = paginator.page(page)
except (EmptyPage, PageNotAnInteger):
kwargs["objects"] = paginator.page(paginator.num_pages)
kwargs["last_page"] = paginator.num_pages
kwargs["total"] = paginator.count
kwargs["table"] = tblclass(request, kwargs["objects"].object_list).render()
return _render(request, tplname, kwargs)
@login_required @login_required
def domains(request): def domains(request):
@@ -43,8 +59,12 @@ def domains(request):
for dom in domains: for dom in domains:
dom.mbalias_counter = len(Alias.objects.filter(domain=dom.id)) dom.mbalias_counter = len(Alias.objects.filter(domain=dom.id))
deloptions = {"keepdir" : _("Do not delete domain directory")} deloptions = {"keepdir" : _("Do not delete domain directory")}
return render_domains_page(request, "domains", return render_domains_page(request, "domains", DomsTable,
domains=domains, "admin/domains.html",
title=_("Available domains"),
emptymsg=_("No domain defined."),
objects=domains,
rel="310 190",
deloptions=deloptions) deloptions=deloptions)
def _validate_domain(request, form, successmsg, commonctx, def _validate_domain(request, form, successmsg, commonctx,
@@ -137,8 +157,11 @@ def domaliases(request):
else: else:
domain = None domain = None
domaliases = DomainAlias.objects.all() domaliases = DomainAlias.objects.all()
return render_domains_page(request, "domaliases", return render_domains_page(request, "domaliases", DomAliasesTable,
domaliases=domaliases, domain=domain) title=_("Domain aliases"),
emptymsg=_("No domain alias defined."),
rel="310 190",
objects=domaliases)
@login_required @login_required
@good_domain @good_domain
@@ -227,8 +250,11 @@ def mailboxes(request):
mboxes = Mailbox.objects.all() mboxes = Mailbox.objects.all()
domain = None domain = None
deloptions = {"keepdir" : _("Do not delete mailbox directory")} deloptions = {"keepdir" : _("Do not delete mailbox directory")}
return render_domains_page(request, "mailboxes", return render_domains_page(request, "mailboxes", MailboxesTable,
mailboxes=mboxes, domain=domain, deloptions=deloptions) title=_("Available mailboxes"),
emptymsg=_("No mailbox defined."),
rel="310 320",
objects=mboxes, domain=domain, deloptions=deloptions)
@login_required @login_required
@good_domain @good_domain
@@ -360,15 +386,12 @@ def mbaliases(request):
aliases = Alias.objects.filter(mboxes__id=request.GET["mbid"]).distinct() aliases = Alias.objects.filter(mboxes__id=request.GET["mbid"]).distinct()
else: else:
aliases = Alias.objects.all() aliases = Alias.objects.all()
if not request.user.is_superuser:
usermb = Mailbox.objects.get(user=request.user.id) return render_domains_page(request, "mbaliases", MbAliasesTable,
for al in aliases: title=_("Mailbox aliases"),
al.ui_disabled = False emptymsg=_("No mailbox alias defined."),
for mb in al.mboxes.all(): rel="320 300",
if mb.domain.id != usermb.domain.id: objects=aliases)
al.ui_disabled = True
break
return render_domains_page(request, "mbaliases", aliases=aliases)
def _validate_mbalias(request, form, successmsg, tplname, commonctx): def _validate_mbalias(request, form, successmsg, tplname, commonctx):
"""Mailbox alias validation """Mailbox alias validation
@@ -546,9 +569,11 @@ def viewextensions(request, tplname='admin/extensions.html'):
class ExtensionsTable(tables.Table): class ExtensionsTable(tables.Table):
idkey = "id" idkey = "id"
selection = tables.SelectionColumn("selection", width="4%", first=True) selection = tables.SelectionColumn("selection", width="4%", first=True)
_1_name = tables.Column("name", label=_("Name"), width="15%") name = tables.Column("name", label=_("Name"), width="15%")
_2_version = tables.Column("version", label=_("Version"), width="6%") version = tables.Column("version", label=_("Version"), width="6%")
_3_descr = tables.Column("description", label=_("Description")) descr = tables.Column("description", label=_("Description"))
cols_order = ["selection", "name", "version", "descr"]
exts = list_extensions() exts = list_extensions()
for ext in exts: for ext in exts:
@@ -562,9 +587,9 @@ def viewextensions(request, tplname='admin/extensions.html'):
dbext.save() dbext.save()
ext["selection"] = False ext["selection"] = False
tbl = ExtensionsTable(exts) tbl = ExtensionsTable(request, exts)
return _render(request, tplname, { return _render(request, tplname, {
"extensions" : tbl.render(request) "extensions" : tbl.render()
}) })
@login_required @login_required
+21 -18
View File
@@ -2,29 +2,27 @@
from datetime import datetime from datetime import datetime
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from modoboa.lib import tables, db from modoboa.lib import tables, db, static_url
from modoboa.lib.email_listing import MBconnector, EmailListing from modoboa.lib.email_listing import MBconnector, EmailListing
from modoboa.lib.emailutils import * from modoboa.lib.emailutils import *
class Qtable(tables.Table): class Qtable(tables.Table):
tableid = "emails" tableid = "emails"
idkey = "mailid" idkey = "mailid"
#selection = tables.SelectionColumn("selection", first=True)
_1_type = tables.Column("type", align="center", width="30px", type = tables.Column("type", align="center", width="30px",
label="<input type='checkbox' name='toggleselect' id='toggleselect' />") label="<input type='checkbox' name='toggleselect' id='toggleselect' />")
_2_from_ = tables.Column("from", label=_("From")) rstatus = tables.ImgColumn("rstatus", width='25px')
_3_subject = tables.Column("subject", label=_("Subject")) from_ = tables.Column("from", label=_("From"), limit=30)
_4_time = tables.Column("date", label=_("Date")) subject = tables.Column("subject", label=_("Subject"), limit=40)
time = tables.Column("date", label=_("Date"))
to = tables.Column("to", label=_("To"), limit=30)
cols_order = ['type', 'rstatus', 'to', 'from_', 'subject', 'time']
def parse_date(self, value): def parse_date(self, value):
return datetime.fromtimestamp(value) return datetime.fromtimestamp(value)
def parse(self, header, value):
try:
return getattr(self, "parse_%s" % header)(value)
except AttributeError:
return value
class SQLconnector(MBconnector): class SQLconnector(MBconnector):
def __init__(self, filter=None): def __init__(self, filter=None):
self.conn = db.getconnection("amavis_quarantine") self.conn = db.getconnection("amavis_quarantine")
@@ -77,10 +75,13 @@ LIMIT %d,%d
emails = [] emails = []
rows = cursor.fetchall() rows = cursor.fetchall()
for row in rows: for row in rows:
emails.append({"from" : row[0], "to" : row[1], m = {"from" : row[0], "to" : row[1],
"subject" : row[2], "content" : row[3], "subject" : row[2], "content" : row[3],
"mailid" : row[4], "date" : row[5], "mailid" : row[4], "date" : row[5],
"type" : row[6]}) "type" : row[6]}
if row[7] == "R":
m["img_rstatus"] = static_url("pics/release.png");
emails.append(m)
return emails return emails
class SQLlisting(EmailListing): class SQLlisting(EmailListing):
@@ -90,7 +91,9 @@ class SQLlisting(EmailListing):
defcallback = "updatelisting" defcallback = "updatelisting"
reset_wm_url = True reset_wm_url = True
def __init__(self, filter, **kwargs): def __init__(self, user, filter, **kwargs):
if not user.is_superuser:
Qtable.cols_order.remove('to')
self.mbc = SQLconnector(filter) self.mbc = SQLconnector(filter)
EmailListing.__init__(self, **kwargs) EmailListing.__init__(self, **kwargs)
+2 -1
View File
@@ -52,7 +52,7 @@ def _listing(request, internal=False, filter=None):
pageid = request.GET.has_key("page") and int(request.GET["page"]) or 1 pageid = request.GET.has_key("page") and int(request.GET["page"]) or 1
request.session["page"] = pageid # ?? nécessaire request.session["page"] = pageid # ?? nécessaire
lst = SQLlisting(filter, baseurl="listing/", empty=internal, lst = SQLlisting(request.user, filter, baseurl="listing/", empty=internal,
elems_per_page=int(parameters.get_user(request.user, elems_per_page=int(parameters.get_user(request.user,
"MESSAGES_PER_PAGE"))) "MESSAGES_PER_PAGE")))
if internal: if internal:
@@ -165,6 +165,7 @@ WHERE msgrcpt.mail_id=msgs.mail_id AND msgrcpt.rid=maddr.id AND msgs.mail_id IN
result = amr.sendreq(k, values["secret"], *values["rcpts"]) result = amr.sendreq(k, values["secret"], *values["rcpts"])
if result: if result:
count += 1 count += 1
db.execute(conn, "UPDATE msgrcpt SET rs='R' WHERE mail_id='%s'" % k)
else: else:
error = result error = result
break break
@@ -119,12 +119,6 @@ textarea:hover {
} }
/* Progress bar */ /* Progress bar */
#footer {
color: white;
font-weight: bold;
font-size: 1em;
}
#quotalabel { #quotalabel {
float: left; float: left;
padding: 7px 2px 0 5px; padding: 7px 2px 0 5px;
+3 -2
View File
@@ -107,14 +107,15 @@ class EmailListing:
return render_to_string("common/navbar.html", context) return render_to_string("common/navbar.html", context)
def fetch(self, request, id_start, id_stop): def fetch(self, request, id_start, id_stop):
table = self.tbltype(self.mbc.fetch(start=id_start, stop=id_stop, table = self.tbltype(request,
self.mbc.fetch(start=id_start, stop=id_stop,
folder=self.folder, folder=self.folder,
nbelems=self.elems_per_page)) nbelems=self.elems_per_page))
tpl = Template(""" tpl = Template("""
<form method="POST" id="listingform"> <form method="POST" id="listingform">
{{ table }} {{ table }}
</form>""") </form>""")
return tpl.render(Context({"table" : table.render(request)})) return tpl.render(Context({"table" : table.render()}))
def render(self, request, pageid=1, **kwargs): def render(self, request, pageid=1, **kwargs):
listing = "" listing = ""
+71 -7
View File
@@ -48,22 +48,46 @@ class DivColumn(Column):
def render(self): def render(self):
return "<div>&nbsp;</div>" return "<div>&nbsp;</div>"
class ActionColumn(Column):
def render(self, fct, user, rowid):
return fct(user, rowid)
class Table(object): class Table(object):
tableid = "" tableid = ""
def __init__(self, rows={}): def __init__(self, request, rows={}):
self.columns = [] self.columns = []
for m in inspect.getmembers(self): self.request = request
if isinstance(m[1], Column): try:
order = getattr(self, "cols_order")
except AttributeError:
for m in inspect.getmembers(self):
if isinstance(m[1], Column):
try:
if getattr(m[1], "first"):
self.columns = [m[1]] + self.columns
except AttributeError:
self.columns += [m[1]]
else:
for colname in order:
try: try:
if getattr(m[1], "first"): col = getattr(self, colname)
self.columns = [m[1]] + self.columns
except AttributeError: except AttributeError:
self.columns += [m[1]] continue
if not isinstance(col, Column):
continue
self.columns += [col]
if rows != {}:
self.populate(rows)
def populate(self, rows):
self.rows = [] self.rows = []
trcpt = 0 trcpt = 0
for row in rows: for row in rows:
nrow = {"id" : row[self.idkey], "cols" : [], "trcpt" : trcpt} nrow = {"id" : row[self.idkey], "cols" : [], "trcpt" : trcpt}
if row.has_key("options"):
nrow["options"] = row["options"]
for c in self.columns: for c in self.columns:
newcol = {"name" : c.name} newcol = {"name" : c.name}
for key in ["width", "align", "cssclass"]: for key in ["width", "align", "cssclass"]:
@@ -88,6 +112,9 @@ class Table(object):
elif isinstance(c, DivColumn): elif isinstance(c, DivColumn):
newcol["value"] = c.render() newcol["value"] = c.render()
newcol["safe"] = True newcol["safe"] = True
elif isinstance(c, ActionColumn):
newcol["value"] = c.render(c.defvalue, self.request.user, nrow["id"])
newcol["safe"] = True
elif row.has_key(c.name): elif row.has_key(c.name):
if "class" in row.keys(): if "class" in row.keys():
newcol["cssclass"] += newcol["cssclass"] != "" \ newcol["cssclass"] += newcol["cssclass"] != "" \
@@ -96,11 +123,48 @@ class Table(object):
newcol["value"] = self.parse(c.name, row[c.name]) newcol["value"] = self.parse(c.name, row[c.name])
except AttributeError: except AttributeError:
newcol["value"] = row[c.name] newcol["value"] = row[c.name]
try:
limit = getattr(c, "limit")
if len(newcol["value"]) > limit:
newcol["value"] = newcol["value"][0:limit] + "..."
except AttributeError:
pass
try:
newcol["safe"] = getattr(c, "safe")
except AttributeError:
pass
nrow["cols"] += [newcol] nrow["cols"] += [newcol]
self.rows += [nrow] self.rows += [nrow]
trcpt += 1 trcpt += 1
def render(self, request): def _rows_from_model(self, objects):
rows = []
for obj in objects:
nrow = {}
try:
idkey = getattr(self, "idkey")
nrow[idkey] = getattr(obj, idkey)
except AttributeError:
pass
for c in self.columns:
try:
nrow[c.name] = getattr(obj, c.name)
except AttributeError:
pass
try:
nrow["options"] = getattr(self, "rowoptions")(self.request, obj)
except AttributeError:
pass
rows += [nrow]
return rows
def parse(self, header, value):
try:
return getattr(self, "parse_%s" % header)(value)
except AttributeError:
return value
def render(self):
if len(self.rows): if len(self.rows):
t = Template(""" t = Template("""
<table id="{{ tableid }}"> <table id="{{ tableid }}">
+21
View File
@@ -34,6 +34,27 @@ div#footer {
height: 30px; height: 30px;
bottom: 0px; bottom: 0px;
border-top: 5px solid #333; border-top: 5px solid #333;
color: white;
font-weight: bold;
font-size: 1em;
}
#navbar {
float: right;
padding: 0;
margin: 0;
text-align: right;
}
#navbar label {
color: white;
margin-right: 5px;
font-weight: bold;
}
#navbar img {
margin-top: 5px;
margin-right: 5px;
} }
#menubar { #menubar {
+1 -35
View File
@@ -1,4 +1,4 @@
{% extends "admin/domains_header.html" %} {% extends "admin/listing.html" %}
{% load i18n admin_extras libextras %} {% load i18n admin_extras libextras %}
{% block html_head %} {% block html_head %}
{{ block.super }} {{ block.super }}
@@ -9,37 +9,3 @@
}); });
</script> </script>
{% endblock %} {% endblock %}
{% block middletitle %}{% trans "Available domains" %}{% endblock %}
{% block subcontent %}
<div id="objects" name="domains" rel="310 190">
{% if not domains %}<div class="info">{% trans "No domain defined." %}</div>
{% else %}
<table id="objects_table">
<tr>
<th>{% trans "Name" %}</th>
<th width="160px">{% trans "Created" %}</th>
<th width="160px">{% trans "Last modified" %}</th>
<th width="100px" class="center">{% trans "Domain aliases" %}</th>
<th width="100px" class="center">{% trans "Mailboxes" %}</th>
<th width="100px" class="center">{% trans "Mailbox aliases" %}</th>
<th width="50px" class="center">{% trans "Quota" %}</th>
<th width="50px" class="center">{% trans "Enabled" %}</th>
<th width="50px" class="center">{% trans "Actions" %}</th>
</tr>
{% for dom in domains %}
<tr class="{% cycle 'odd' 'even' %}" id="{{ dom.id }}">
<td>{{ dom.name }}</td>
<td>{{ dom.dates.creation }}</td>
<td>{{ dom.dates.last_modification }}</td>
<td class="center">{{ dom.domainalias_set.all|length }}</td>
<td class="center">{{ dom.mailbox_set.all|length }}</td>
<td class="center">{{ dom.mbalias_counter }}</td>
<td class="center">{{ dom.quota }} {% trans "MB" %}</td>
<td class="center">{{ dom.enabled|yesno:_("yes,no") }}</td>
<td class="center">{% domain_actions user dom.id %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endblock %}
-31
View File
@@ -1,31 +0,0 @@
{% extends "admin/domains_header.html" %}
{% load i18n admin_extras libextras %}
{% block pagetitle %}{% trans "Domain aliases" %}{% endblock %}
{% block subcontent %}
<div id="objects" name="domaliases" rel="310 190">
{% if not domaliases %}
<div class="info">{% trans "No domain alias defined." %}</div>
{% else %}
<table id="objects_table">
<tr>
<th>{% trans "Name" %}</th>
<th>{% trans "Targeted domain" %}</th>
<th width="170px">{% trans "Created" %}</th>
<th width="170px">{% trans "Last modified" %}</th>
<th width="50px" class="center">{% trans "Enabled" %}</th>
<th width="50px" class="center">{% trans "Actions" %}</th>
</tr>
{% for domalias in domaliases %}
<tr class="{% cycle 'odd' 'even' %}" id="{{ domalias.id }}">
<td>{{ domalias.name }}</td>
<td>{{ domalias.target.name }}</td>
<td>{{ domalias.dates.creation }}</td>
<td>{{ domalias.dates.last_modification }}</td>
<td class="center">{{ domalias.enabled|yesno }}</td>
<td class="center">{% domalias_actions user domalias.id %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endblock %}
+34
View File
@@ -0,0 +1,34 @@
{% extends "admin/domains_header.html" %}
{% load i18n %}
{% block middletitle %}{{ title }}{% endblock %}
{% block subcontent %}
<div id="objects" name="{{ selection }}" rel="{{ rel }}">
{% if not objects %}<div class="info">{{ emptymsg }}</div>
{% else %}
{{ table }}
{% endif %}
</div>
{% endblock %}
{% block footer %}
<div id="navbar">
{% if total %}
<label>{% trans "Items" %} {{ objects.start_index }} {% trans "to" %} {{ objects.end_index }} {% trans "of" %} {{ total }}</label>
{% endif %}
{% if objects.has_previous %}
<a href="?page=1">
<img src="{{ MEDIA_URL }}pics/first.png" border="0" title="{% trans "First" %}" />
</a>
<a href="?page={{ objects.previous_page_number }}">
<img src="{{ MEDIA_URL }}pics/back.png" border="0" title="{% trans "Previous" %}" />
</a>
{% endif %}
{% if objects.has_next %}
<a href="?page={{ objects.next_page_number }}">
<img src="{{ MEDIA_URL }}pics/next.png" border="0" title="{% trans "Next" %}" />
</a>
<a href="?page={{ page.last_page }}">
<img src="{{ MEDIA_URL }}pics/last.png" border="0" title="{% trans "Last" %}" />
</a>
{% endif %}
</div>
{% endblock %}
-35
View File
@@ -1,35 +0,0 @@
{% extends "admin/domains_header.html" %}
{% load i18n admin_extras %}
{% block pagetitle %}{% trans "Available mailboxes" %}{% endblock %}
{% block subcontent %}
<div id="objects" name="mailboxes" rel="310 320">
{% if not mailboxes %}
<div class="info">{% trans "No mailbox defined." %}</div>
{% else %}
<table id="objects_table">
<tr>
<th>{% trans "Address" %}</th>
<th>{% trans "Name" %}</th>
<th width="160px">{% trans "Created" %}</th>
<th width="160px">{% trans "Last modified" %}</th>
<th width="70px" class="center">{% trans "Aliases" %}</th>
<th width="50px" class="center">{% trans "Quota" %}</th>
<th width="50px" class="center">{{ "Enabled"|gender:"f" }}</th>
<th width="70px" class="center">{% trans "Actions" %}</th>
</tr>
{% for mb in mailboxes %}
<tr class="{% cycle 'odd' 'even' %}" id="{{ mb.id }}">
<td>{{ mb.full_address }}</td>
<td>{{ mb.name }}</td>
<td>{{ mb.dates.creation }}</td>
<td>{{ mb.dates.last_modification }}</td>
<td class="center">{{ mb.alias_set.all|length }}</td>
<td class="center">{{ mb.quota }} {% trans "MB" %}</td>
<td class="center">{{ mb.user.is_active|yesno:_("yes,no") }}</td>
<td class="center">{% mailbox_actions user mb %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endblock %}
-39
View File
@@ -1,39 +0,0 @@
{% extends "admin/domains_header.html" %}
{% load i18n admin_extras %}
{% block pagetitle %}{% trans "Mailbox aliases" %}{% endblock %}
{% block subcontent %}
<div id="objects" name="mbaliases" rel="320 300">
{% if not aliases %}
<div class="info">{% trans "No mailbox alias defined." %}</div>
{% else %}
<table id="objects_table">
<tr>
<th>{% trans "Address" %}</th>
<th>{% trans "Target(s)" %}</th>
<th width="170px">{% trans "Created" %}</th>
<th width="170px">{% trans "Last modified" %}</th>
<th width="50px" class="center">{% trans "Enabled" %}</th>
<th width="50px" class="center">{% trans "Actions" %}</th>
</tr>
{% for alias in aliases %}
<tr class="{% cycle 'odd' 'even' %}" id="{{ alias.id }}"
rel="{ui_disabled : '{{ alias.ui_disabled }}'}">
<td>{{ alias.address }}@{{ alias.domain }}</td>
<td>
{% for mb in alias.mboxes.all %}
{{ mb.full_address }}<br/>
{% endfor %}
{{ alias.repr_extmboxes|safe }}
</td>
<td>{{ alias.dates.creation }}</td>
<td>{{ alias.dates.last_modification }}</td>
<td class="center">{{ alias.enabled|yesno }}</td>
<td class="center">
{% if alias.ui_disabled %}--{% else %}{% mbalias_actions user alias %}{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% endif %}
</div>
{% endblock %}
-20
View File
@@ -7,26 +7,6 @@
<script type="text/javascript" src="{{ MEDIA_URL }}js/ProgressBar.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}js/ProgressBar.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/email_listing.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}js/email_listing.js"></script>
{% block css %}{% endblock %} {% block css %}{% endblock %}
<style type="text/css">
#navbar {
float: right;
padding: 0;
margin: 0;
text-align: right;
}
#navbar label {
color: white;
margin-right: 5px;
font-weight: bold;
}
#navbar img{
margin-top: 5px;
margin-right: 5px;
}
</style>
<script type="text/javascript"> <script type="text/javascript">
var current_anchor = new AnchorNavigation("{{ deflocation }}"); var current_anchor = new AnchorNavigation("{{ deflocation }}");
+2 -1
View File
@@ -1,6 +1,7 @@
<tbody> <tbody>
{% for row in table.rows %} {% for row in table.rows %}
<tr id="{{ row.id }}" class="{% cycle 'odd' 'even' %}" name="{{ row.trcpt }}"> <tr id="{{ row.id }}" class="{% cycle 'odd' 'even' %}" name="{{ row.trcpt }}"
rel="{{ row.options }}">
{% for cell in row.cols %} {% for cell in row.cols %}
<td name="{{ cell.name }}" width="{{ cell.width }}" align="{{ cell.align }}" class="{{ cell.cssclass }}"> <td name="{{ cell.name }}" width="{{ cell.width }}" align="{{ cell.align }}" class="{{ cell.cssclass }}">
{% if cell.safe %}{{ cell.value|safe }}{% else %}{{ cell.value }}{% endif %} {% if cell.safe %}{{ cell.value|safe }}{% else %}{{ cell.value }}{% endif %}