Fixed errors with systemuser form and serializer
This commit is contained in:
parent
fd6c7975a0
commit
66fb997f65
|
@ -194,12 +194,13 @@ class ChangePasswordAdminMixin(object):
|
||||||
related.append(user.account)
|
related.append(user.account)
|
||||||
else:
|
else:
|
||||||
account = user
|
account = user
|
||||||
for rel in account.get_related_passwords():
|
if account.username == username:
|
||||||
if not isinstance(user, type(rel)):
|
for rel in account.get_related_passwords():
|
||||||
related.append(rel)
|
if not isinstance(user, type(rel)):
|
||||||
|
related.append(rel)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = self.change_password_form(user, request.POST, related)
|
form = self.change_password_form(user, request.POST, related=related)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
form.save()
|
form.save()
|
||||||
change_message = self.construct_change_message(request, form, None)
|
change_message = self.construct_change_message(request, form, None)
|
||||||
|
@ -209,7 +210,7 @@ class ChangePasswordAdminMixin(object):
|
||||||
update_session_auth_hash(request, form.user) # This is safe
|
update_session_auth_hash(request, form.user) # This is safe
|
||||||
return HttpResponseRedirect('..')
|
return HttpResponseRedirect('..')
|
||||||
else:
|
else:
|
||||||
form = self.change_password_form(user, related)
|
form = self.change_password_form(user, related=related)
|
||||||
|
|
||||||
fieldsets = [
|
fieldsets = [
|
||||||
(user._meta.verbose_name.capitalize(), {
|
(user._meta.verbose_name.capitalize(), {
|
||||||
|
@ -224,7 +225,6 @@ class ChangePasswordAdminMixin(object):
|
||||||
}))
|
}))
|
||||||
|
|
||||||
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
|
adminForm = admin.helpers.AdminForm(form, fieldsets, {})
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'title': _('Change password: %s') % escape(username),
|
'title': _('Change password: %s') % escape(username),
|
||||||
'adminform': adminForm,
|
'adminform': adminForm,
|
||||||
|
|
|
@ -13,16 +13,18 @@ class Mailbox(models.Model):
|
||||||
CUSTOM = 'CUSTOM'
|
CUSTOM = 'CUSTOM'
|
||||||
|
|
||||||
name = models.CharField(_("name"), max_length=64, unique=True,
|
name = models.CharField(_("name"), max_length=64, unique=True,
|
||||||
help_text=_("Required. 30 characters or fewer. Letters, digits and "
|
help_text=_("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
|
||||||
"@/./+/-/_ only."),
|
validators=[
|
||||||
validators=[RegexValidator(r'^[\w.@+-]+$',
|
RegexValidator(r'^[\w.@+-]+$', _("Enter a valid mailbox name."))
|
||||||
_("Enter a valid mailbox name."), 'invalid')])
|
])
|
||||||
password = models.CharField(_("password"), max_length=128)
|
password = models.CharField(_("password"), max_length=128)
|
||||||
account = models.ForeignKey('accounts.Account', verbose_name=_("account"),
|
account = models.ForeignKey('accounts.Account', verbose_name=_("account"),
|
||||||
related_name='mailboxes')
|
related_name='mailboxes')
|
||||||
filtering = models.CharField(max_length=16,
|
filtering = models.CharField(max_length=16,
|
||||||
choices=[(k, v[0]) for k,v in settings.MAILBOXES_MAILBOX_FILTERINGS.iteritems()],
|
default=settings.MAILBOXES_MAILBOX_DEFAULT_FILTERING,
|
||||||
default=settings.MAILBOXES_MAILBOX_DEFAULT_FILTERING)
|
choices=[
|
||||||
|
(k, v[0]) for k,v in settings.MAILBOXES_MAILBOX_FILTERINGS.iteritems()
|
||||||
|
])
|
||||||
custom_filtering = models.TextField(_("filtering"), blank=True,
|
custom_filtering = models.TextField(_("filtering"), blank=True,
|
||||||
validators=[validators.validate_sieve],
|
validators=[validators.validate_sieve],
|
||||||
help_text=_("Arbitrary email filtering in sieve language. "
|
help_text=_("Arbitrary email filtering in sieve language. "
|
||||||
|
@ -110,15 +112,17 @@ class Address(models.Model):
|
||||||
# return ' '.join(destinations)
|
# return ' '.join(destinations)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.account:
|
if self.account_id:
|
||||||
errors = []
|
forward_errors = []
|
||||||
for mailbox in self.get_forward_mailboxes():
|
for mailbox in self.get_forward_mailboxes():
|
||||||
if mailbox.account == self.account:
|
if mailbox.account_id == self.account_id:
|
||||||
errors.append(ValidationError(
|
forward_errors.append(ValidationError(
|
||||||
_("Please use mailboxes field for '%s' mailbox.") % mailbox
|
_("Please use mailboxes field for '%s' mailbox.") % mailbox
|
||||||
))
|
))
|
||||||
if errors:
|
if forward_errors:
|
||||||
raise ValidationError({'forward': errors})
|
raise ValidationError({
|
||||||
|
'forward': forward_errors
|
||||||
|
})
|
||||||
|
|
||||||
def get_forward_mailboxes(self):
|
def get_forward_mailboxes(self):
|
||||||
for forward in self.forward.split():
|
for forward in self.forward.split():
|
||||||
|
|
|
@ -31,8 +31,8 @@ class SystemUserFormMixin(object):
|
||||||
self.fields['home'].widget = forms.HiddenInput()
|
self.fields['home'].widget = forms.HiddenInput()
|
||||||
self.fields['directory'].widget = forms.HiddenInput()
|
self.fields['directory'].widget = forms.HiddenInput()
|
||||||
elif self.instance.pk and (self.instance.get_base_home() == self.instance.home):
|
elif self.instance.pk and (self.instance.get_base_home() == self.instance.home):
|
||||||
self.fields['directory'].widget = forms.HiddenInput()
|
self.fields['directory'].widget = forms.HiddenInput()
|
||||||
if self.instance.pk and not self.instance.is_main:
|
if not self.instance.pk or not self.instance.is_main:
|
||||||
# Some javascript for hidde home/directory inputs when convinient
|
# Some javascript for hidde home/directory inputs when convinient
|
||||||
self.fields['shell'].widget.attrs = {
|
self.fields['shell'].widget.attrs = {
|
||||||
'onChange': textwrap.dedent("""\
|
'onChange': textwrap.dedent("""\
|
||||||
|
|
|
@ -79,7 +79,7 @@ class SystemUser(models.Model):
|
||||||
directory_error = None
|
directory_error = None
|
||||||
if self.has_shell:
|
if self.has_shell:
|
||||||
directory_error = _("Directory with shell users can not be specified.")
|
directory_error = _("Directory with shell users can not be specified.")
|
||||||
elif self.pk and self.is_main:
|
elif self.account_id and self.is_main:
|
||||||
directory_error = _("Directory with main system users can not be specified.")
|
directory_error = _("Directory with main system users can not be specified.")
|
||||||
elif self.home == self.get_base_home():
|
elif self.home == self.get_base_home():
|
||||||
directory_error = _("Directory on the user's base home is not allowed.")
|
directory_error = _("Directory on the user's base home is not allowed.")
|
||||||
|
|
Loading…
Reference in a new issue