add inline editing for mail address targets
- move active flag into managemails.models.ActivateAbleMixin - refactor Mailbox and Mailaddress to use ActivateAbleMixin - implement managemails.models.Mailbox.__str__ - add managemails.admin.ActivationChangeMixin to provide activate and deactivate actions for model admin classes - add activate and deactivate actions for managemails.admin.MailboxAdmin - add managemails.admin.MailAddressAdmin and inlines for MailAddressMailbox and MailAddressForward management on the MailAddress management admin page
This commit is contained in:
parent
b044fe2dd9
commit
ee46a61e6d
2 changed files with 52 additions and 7 deletions
|
@ -5,9 +5,11 @@ from django.forms.util import flatatt
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
|
MailAddress,
|
||||||
|
MailAddressForward,
|
||||||
|
MailAddressMailbox,
|
||||||
MailDomain,
|
MailDomain,
|
||||||
Mailbox,
|
Mailbox,
|
||||||
MailAddress
|
|
||||||
)
|
)
|
||||||
|
|
||||||
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
PASSWORD_MISMATCH_ERROR = _("Passwords don't match")
|
||||||
|
@ -89,7 +91,18 @@ class MailboxChangeForm(forms.ModelForm):
|
||||||
return self.initial['password']
|
return self.initial['password']
|
||||||
|
|
||||||
|
|
||||||
class MailboxAdmin(admin.ModelAdmin):
|
class ActivationChangeMixin(object):
|
||||||
|
def activate(self, request, queryset):
|
||||||
|
queryset.update(active=True)
|
||||||
|
|
||||||
|
def deactivate(self, request, queryset):
|
||||||
|
queryset.update(active=False)
|
||||||
|
|
||||||
|
activate.short_description = _('Activate')
|
||||||
|
deactivate.short_description = _('Deactivate')
|
||||||
|
|
||||||
|
|
||||||
|
class MailboxAdmin(ActivationChangeMixin, admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
Custom admin page for mailboxes.
|
Custom admin page for mailboxes.
|
||||||
|
|
||||||
|
@ -97,6 +110,8 @@ class MailboxAdmin(admin.ModelAdmin):
|
||||||
form = MailboxChangeForm
|
form = MailboxChangeForm
|
||||||
add_form = MailboxCreationForm
|
add_form = MailboxCreationForm
|
||||||
|
|
||||||
|
actions = ['activate', 'deactivate']
|
||||||
|
|
||||||
list_display = ('username', 'active')
|
list_display = ('username', 'active')
|
||||||
list_filter = ('active',)
|
list_filter = ('active',)
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
|
@ -134,6 +149,23 @@ class MailboxAdmin(admin.ModelAdmin):
|
||||||
return super(MailboxAdmin, self).get_form(request, obj, **defaults)
|
return super(MailboxAdmin, self).get_form(request, obj, **defaults)
|
||||||
|
|
||||||
|
|
||||||
|
class MailAddressMailboxInline(admin.TabularInline):
|
||||||
|
model = MailAddressMailbox
|
||||||
|
|
||||||
|
|
||||||
|
class MailAddressForwardInline(admin.TabularInline):
|
||||||
|
model = MailAddressForward
|
||||||
|
|
||||||
|
|
||||||
|
class MailAddressAdmin(ActivationChangeMixin, admin.ModelAdmin):
|
||||||
|
actions = ['activate', 'deactivate']
|
||||||
|
|
||||||
|
list_display = ('__str__', 'active')
|
||||||
|
list_filter = ('active',)
|
||||||
|
|
||||||
|
inlines = [MailAddressMailboxInline, MailAddressForwardInline]
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(MailDomain)
|
admin.site.register(MailDomain)
|
||||||
admin.site.register(Mailbox, MailboxAdmin)
|
admin.site.register(Mailbox, MailboxAdmin)
|
||||||
admin.site.register(MailAddress)
|
admin.site.register(MailAddress, MailAddressAdmin)
|
||||||
|
|
|
@ -16,13 +16,24 @@ class MailDomain(models.Model):
|
||||||
return self.domain
|
return self.domain
|
||||||
|
|
||||||
|
|
||||||
class Mailbox(models.Model):
|
class ActivateAbleMixin(models.Model):
|
||||||
|
"""
|
||||||
|
Mixin for model classes that can be active or inactive.
|
||||||
|
|
||||||
|
"""
|
||||||
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
@python_2_unicode_compatible
|
||||||
|
class Mailbox(ActivateAbleMixin, models.Model):
|
||||||
username = models.CharField(max_length=128, unique=True)
|
username = models.CharField(max_length=128, unique=True)
|
||||||
password = models.CharField(max_length=255)
|
password = models.CharField(max_length=255)
|
||||||
home = models.CharField(max_length=255)
|
home = models.CharField(max_length=255)
|
||||||
uid = models.PositiveSmallIntegerField()
|
uid = models.PositiveSmallIntegerField()
|
||||||
gid = models.PositiveSmallIntegerField()
|
gid = models.PositiveSmallIntegerField()
|
||||||
active = models.BooleanField(default=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Mailbox')
|
verbose_name = _('Mailbox')
|
||||||
|
@ -31,12 +42,14 @@ class Mailbox(models.Model):
|
||||||
def set_password(self, password):
|
def set_password(self, password):
|
||||||
self.password = sha512_crypt.encrypt(password)
|
self.password = sha512_crypt.encrypt(password)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.username
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class MailAddress(models.Model):
|
class MailAddress(ActivateAbleMixin, models.Model):
|
||||||
localpart = models.CharField(max_length=128)
|
localpart = models.CharField(max_length=128)
|
||||||
domain = models.ForeignKey(MailDomain)
|
domain = models.ForeignKey(MailDomain)
|
||||||
active = models.BooleanField(default=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('localpart', 'domain')
|
unique_together = ('localpart', 'domain')
|
||||||
|
|
Loading…
Reference in a new issue