From 26dfcef9efd4401c0b77c7f61a3ea6ad02936eb5 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 24 Apr 2012 12:26:07 +0200 Subject: [PATCH] wip: UI refactoring * username max_lenght increased * Fixed an error into the creation wizard * The quarantine poller interval is now customizable see #204 --- admin/forms.py | 6 ++- admin/models.py | 57 ++++++++++++++---------- admin/views.py | 7 ++- extensions/amavis_quarantine/__init__.py | 7 ++- static/js/creation_wizard.js | 26 ++++++----- 5 files changed, 64 insertions(+), 39 deletions(-) diff --git a/admin/forms.py b/admin/forms.py index f6d9a4216..60996413a 100644 --- a/admin/forms.py +++ b/admin/forms.py @@ -209,13 +209,15 @@ class ImportDataForm(forms.Form): return str(self.cleaned_data["sepcar"]) class AccountFormGeneral(forms.ModelForm): + username = forms.CharField(max_length=254) role = forms.ChoiceField( - choices=[('', ugettext_noop("Choose"))] + choices=[('', ugettext_noop("Choose"))], + help_text=ugettext_noop("What level of permission this user will have") ) class Meta: model = User - fields = ("username", "first_name", "last_name", "role", "is_active") + fields = ("first_name", "last_name", "role", "is_active") def __init__(self, user, *args, **kwargs): super(AccountFormGeneral, self).__init__(*args, **kwargs) diff --git a/admin/models.py b/admin/models.py index a74a7808b..6861b418d 100644 --- a/admin/models.py +++ b/admin/models.py @@ -38,6 +38,17 @@ class User(DUser): password_expr = re.compile(r'\{(\w+)\}(.+)') + def __init__(self, *args, **kwargs): + """Constructor + + A little hack to increase the maximum length for the username + field. + """ + max_length = 254 + DUser._meta.get_field('username').max_length = max_length + DUser._meta.get_field('username').validators[0].limit_value = 254 + super(User, self).__init__(*args, **kwargs) + def __unicode__(self): return u"%s %s" % (self.first_name, self.last_name) @@ -549,6 +560,26 @@ class Mailbox(DatesAware): self.domain.name, self.address)) return True + def set_ownership(self): + # If we ever had numerical uid, don't resolve it + v_uid = parameters.get_admin("VIRTUAL_UID"); + if v_uid.isdigit(): + self.uid = v_uid + else: + try: + self.uid = pwd.getpwnam(v_uid).pw_uid + except KeyError: + raise AdminError(_("%s is not a valid uid/username" % v_uid)) + # Just the same for gid + v_gid = parameters.get_admin("VIRTUAL_GID") + if v_gid.isdigit(): + self.gid = v_gid + else: + try: + self.gid = pwd.getpwnam(v_gid).pw_gid + except KeyError: + raise AdminError(_("%s is not a valid gid/groupname" % v_gid)) + def save(self, *args, **kwargs): if not self.create_dir(): raise AdminError(_("Failed to initialise mailbox, check permissions")) @@ -583,18 +614,7 @@ class Mailbox(DatesAware): user.groups.add(Group.objects.get(name="SimpleUsers")) user.save() - # If we ever had numerical uid, don't resolve it - v_uid = parameters.get_admin("VIRTUAL_UID"); - if v_uid.isdigit(): - self.uid = v_uid - else: - self.uid = pwd.getpwnam(parameters.get_admin("VIRTUAL_UID")).pw_uid - # Just the same for gid - v_gid = parameters.get_admin("VIRTUAL_GID") - if v_gid.isdigit(): - self.gid = v_gid - else: - self.gid = pwd.getpwnam(parameters.get_admin("VIRTUAL_GID")).pw_gid + self.set_ownership() if kwargs.has_key("quota") and kwargs["quota"] is not None \ and int(kwargs["quota"]) < self.domain.quota: @@ -620,18 +640,7 @@ class Mailbox(DatesAware): self.user = user if not self.create_dir(): raise AdminError(_("Failed to initialise mailbox, check permissions")) - # If we ever had numerical uid, don't resolve it - v_uid = parameters.get_admin("VIRTUAL_UID"); - if v_uid.isdigit(): - self.uid = v_uid - else: - self.uid = pwd.getpwnam(parameters.get_admin("VIRTUAL_UID")).pw_uid - # Just the same for gid - v_gid = parameters.get_admin("VIRTUAL_GID") - if v_gid.isdigit(): - self.gid = v_gid - else: - self.gid = pwd.getpwnam(parameters.get_admin("VIRTUAL_GID")).pw_gid + self.set_ownership() self.quota = self.domain.quota if quota is None else quota super(Mailbox, self).save() diff --git a/admin/views.py b/admin/views.py index f6ae79024..6da0a4494 100644 --- a/admin/views.py +++ b/admin/views.py @@ -328,8 +328,11 @@ def newaccount(request, tplname='admin/newaccount.html'): if retcode == 2: messages.info(request, _("Account created")) return ajax_simple_response(dict(status="ok")) - ctx.update(steps=cwizard.steps) - return ajax_response(request, status="ko", template=tplname, **ctx) + + from modoboa.lib.templatetags.libextras import render_form + return ajax_simple_response(dict( + status="ko", stepid=data, form=render_form(cwizard.steps[data]["form"]) + )) cwizard.create_forms() ctx.update(steps=cwizard.steps) diff --git a/extensions/amavis_quarantine/__init__.py b/extensions/amavis_quarantine/__init__.py index a93a74156..3b35a28c9 100644 --- a/extensions/amavis_quarantine/__init__.py +++ b/extensions/amavis_quarantine/__init__.py @@ -42,6 +42,9 @@ def load(): parameters.register_admin("AM_PDP_SOCKET", type="string", deflt=_("/var/amavis/amavisd.sock"), help=_("Path to the PDP server socket (if unix mode)")) + parameters.register_admin("CHECK_REQUESTS_INTERVAL", type="int", + deflt=30, + help=_("Interval between two release requests checks")) parameters.register_admin("USER_CAN_RELEASE", type="list_yesno", deflt="no", help=_("Allow users to directly release their messages")) parameters.register_admin("SELF_SERVICE", type="list_yesno", deflt="no", @@ -105,6 +108,7 @@ def extra_static_content(user): tpl = Template("""""") url = reverse("modoboa.extensions.amavis_quarantine.views.nbrequests") - return [tpl.render(Context(dict(url=url)))] + interval = int(parameters.get_admin("CHECK_REQUESTS_INTERVAL")) * 1000 + return [tpl.render(Context(dict(url=url, interval=interval)))] @events.observe("TopNotifications") def display_requests(user): diff --git a/static/js/creation_wizard.js b/static/js/creation_wizard.js index 9777c29be..90714042f 100644 --- a/static/js/creation_wizard.js +++ b/static/js/creation_wizard.js @@ -1,16 +1,21 @@ (function($) { var Cwizard = function(element, options) { - this.$element = $(element); - this.options = $.extend({}, $.fn.cwizard.defaults, options); - this.$element.carousel({pause: true}); - this.$element.carousel("pause"); - this.setcallbacks(); + this.initialize(element, options); }; Cwizard.prototype = { constructor: Cwizard, - setcallbacks: function() { + initialize: function(element, options) { + this.$element = $(element); + this.options = $.extend({}, $.fn.cwizard.defaults, options); + this.$element.carousel({pause: true}); + this.$element.carousel("pause"); + this.listen(); + $('input:text:visible:first').focus(); + }, + + listen: function() { $(".next").one("click", $.proxy(this.next, this)); $(".prev").one("click", $.proxy(this.prev, this)); $(".submit").one("click", $.proxy(this.submit, this)); @@ -23,6 +28,7 @@ $.post($form.attr("action"), data, $.proxy(function(resp) { if (resp.status == "ok") { if (!last) { + $('input:text:visible:first').focus(); $(".modal-header").find("small").html(resp.title); this.$element.carousel('next'); } else { @@ -31,13 +37,13 @@ } return; } - if (resp.content) { - $(".modal").html(resp.content); + if (resp.stepid != undefined && resp.form != undefined) { + $("#step" + (resp.stepid + 1)).html(resp.form); } if (resp.respmsg) { $(".modal-body").prepend(build_error_alert(resp.respmsg)); } - this.setcallbacks(); + this.listen(); }, this)); }, @@ -56,7 +62,7 @@ evt.preventDefault(); this.$element.on('slid', this.update_buttons); this.$element.carousel('prev'); - this.setcallbacks(); + this.listen(); }, submit: function(evt) {