wip: UI refactoring

* username max_lenght increased
* Fixed an error into the creation wizard
* The quarantine poller interval is now customizable

see #204
This commit is contained in:
Antoine Nguyen
2012-04-24 12:26:07 +02:00
parent ddf3c2dad4
commit 26dfcef9ef
5 changed files with 64 additions and 39 deletions
+4 -2
View File
@@ -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)
+33 -24
View File
@@ -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()
+5 -2
View File
@@ -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)
+6 -1
View File
@@ -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("""<script type="text/javascript">
$(document).ready(function() {
var poller = new Poller("{{ url }}", {
interval: {{ interval }},
success_cb: function(data) {
var $link = $("#nbrequests");
if (data.requests > 0) {
@@ -118,7 +122,8 @@ $(document).ready(function() {
});
</script>""")
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):
+16 -10
View File
@@ -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) {