From 9c708988285e84c25e93e36bb955bf06eb94db14 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Sun, 20 Jan 2013 10:14:33 +0100 Subject: [PATCH] Clickable tags to filter identities. see #319 --- modoboa/admin/models.py | 57 +++---------------- modoboa/admin/static/admin/js/admin.js | 18 ++++++ .../templates/admin/identities_table.html | 4 +- modoboa/lib/templatetags/libextras.py | 10 ++++ modoboa/static/css/custom.css | 5 ++ 5 files changed, 42 insertions(+), 52 deletions(-) diff --git a/modoboa/admin/models.py b/modoboa/admin/models.py index 65c1961c6..bd7580013 100644 --- a/modoboa/admin/models.py +++ b/modoboa/admin/models.py @@ -181,9 +181,8 @@ class User(DUser): @property def tags(self): - ret = '%s' % _("account") - ret += ' %s' % self.group - return ret + return [{"name" : "account", "label" : _("account"), "type" : "idt"}, + {"name" : self.group, "label" : self.group, "type" : "grp", "color" : "info"}] @property def has_mailbox(self): @@ -265,7 +264,7 @@ class User(DUser): aliases = [] if not idtfilter or ("alias" in idtfilter or "forward" in idtfilter - or "distribution list" in idtfilter): + or "dlist" in idtfilter): alct = get_content_type(Alias) ids = self.objectaccess_set.filter(content_type=alct) \ .values_list('object_id', flat=True) @@ -772,51 +771,6 @@ class Mailbox(DatesAware): else: self.quota = value - def save(self, *args, **kwargs): - if not self.create_dir(): - raise AdminError(_("Failed to initialise mailbox, check permissions")) - try: - user = getattr(self, "user") - except User.DoesNotExist: - user = User() - user.email = "%s@%s" % (self.address, self.domain.name) - if kwargs.has_key("username"): - user.username = kwargs["username"] - else: - user.username = user.email - if kwargs.has_key("enabled"): - user.is_active = kwargs["enabled"] - if kwargs.has_key("name"): - try: - fname, lname = kwargs["name"].split() - except ValueError: - fname = kwargs["name"] - lname = "" - user.first_name = fname - user.last_name = lname - if kwargs.has_key("password"): - user.set_password(kwargs["password"]) - try: - user.save() - except IntegrityError, e: - raise AdminError(_("Account '%s' already exists" % user.username)) - self.user = user - - if user.groups.count() == 0: - user.groups.add(Group.objects.get(name="SimpleUsers")) - user.save() - - self.set_ownership() - if kwargs.has_key("quota"): - self.set_quota(kwargs["quota"]) - - for kw in ["username", "name", "enabled", "password", "quota"]: - try: - del kwargs[kw] - except KeyError: - pass - super(Mailbox, self).save(*args, **kwargs) - def save_from_user(self, localpart, domain, user, quota=None, owner=None): """Simple save method called for automatic creations @@ -901,12 +855,15 @@ class Alias(DatesAware): def tags(self): cpt = self.get_recipients_count() if cpt > 1: + name = "dlist" label = _("distribution list") elif self.extmboxes != "": + name = "forward" label = _("forward") else: + name = "alias" label = _("alias") - return '%s' % label + return [{"name" : name, "label" : label, "type" : "idt"}] def save(self, int_rcpts, ext_rcpts, *args, **kwargs): if len(ext_rcpts): diff --git a/modoboa/admin/static/admin/js/admin.js b/modoboa/admin/static/admin/js/admin.js index 4e6b872f5..116e6fa77 100644 --- a/modoboa/admin/static/admin/js/admin.js +++ b/modoboa/admin/static/admin/js/admin.js @@ -159,6 +159,8 @@ Identities.prototype = { list_cb: function(data) { Admin.prototype.list_cb.call(this, data); + $("a.filter").click($.proxy(this.filter_by_tag, this)); + $("a[name=delaccount]").confirm({ question: gettext("Delete this account?"), checkboxes: {keepdir: gettext("Do not delete mailbox directory")}, @@ -178,6 +180,22 @@ Identities.prototype = { }); }, + filter_by_tag: function(e) { + var $link = $(e.target); + e.preventDefault(); + + if ($link.hasClass("idt")) { + this.navobj.setparam("idtfilter", $link.attr("name")).update(); + return; + } + if ($link.hasClass("grp")) { + this.navobj + .setparam("idtfilter", "account") + .setparam("grpfilter", $link.attr("name")) + .update(); + } + }, + simpleuser_mode: function() { $("#id_username").autocompleter({ from_character: "@", diff --git a/modoboa/admin/templates/admin/identities_table.html b/modoboa/admin/templates/admin/identities_table.html index a1372c771..1d7024579 100644 --- a/modoboa/admin/templates/admin/identities_table.html +++ b/modoboa/admin/templates/admin/identities_table.html @@ -1,4 +1,4 @@ -{% load i18n admin_extras %} +{% load i18n admin_extras libextras %} @@ -13,7 +13,7 @@ - + {% endfor %} diff --git a/modoboa/lib/templatetags/libextras.py b/modoboa/lib/templatetags/libextras.py index 95710150a..40740fe03 100644 --- a/modoboa/lib/templatetags/libextras.py +++ b/modoboa/lib/templatetags/libextras.py @@ -208,3 +208,13 @@ def connected_users(parser, token): except ValueError: raise template.TemplateSyntaxError('connected_users usage: {% connected_users as users %}') return ConnectedUsers(varname) + +@register.simple_tag +def render_tags(tags): + t = Template("""{% for tag in tags %} + + {{ tag.label }} + +{% endfor %} +""") + return t.render(Context({"tags" : tags})) diff --git a/modoboa/static/css/custom.css b/modoboa/static/css/custom.css index f69fd5c25..caba69af7 100644 --- a/modoboa/static/css/custom.css +++ b/modoboa/static/css/custom.css @@ -91,4 +91,9 @@ body { .help-block { color: #999999; font-style: italic; +} + +.label a { + color: #FFFFFF; + text-decoration: none; } \ No newline at end of file
{% identity_modify_link ident %} {{ ident.name_or_rcpt }}{{ ident.tags|safe }}{% render_tags ident.tags %} {% identity_actions user ident %}