improve managemails app

- add managemails.apps to give a more meaningful title in the admin site
- add verbose names to MailAddressMailbox fields
- implement managemails.models.Mailbox.get_mailaddresses and a corresponding
  property mailaddresses
This commit is contained in:
Jan Dittberner 2015-01-24 20:58:20 +01:00
parent 47abaa6d62
commit e04132bd24
5 changed files with 71 additions and 3 deletions

View file

@ -11,6 +11,13 @@
:members: :members:
:py:mod:`apps <managemails.apps>`
-----------------------------------
.. automodule:: managemails.apps
:members:
:py:mod:`models <managemails.models>` :py:mod:`models <managemails.models>`
------------------------------------- -------------------------------------

View file

@ -0,0 +1,5 @@
"""
This app takes care of mailboxes and mail addresses.
"""
default_app_config = 'managemails.apps.ManageMailsAppConfig'

View file

@ -0,0 +1,17 @@
"""
This module contains the :py:class:`django.apps.AppConfig` instance for the
:py:mod:`managemails` app.
"""
from __future__ import unicode_literals
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
class ManageMailsAppConfig(AppConfig):
"""
AppConfig for the :py:mod:`managemails` app.
"""
name = 'managemails'
verbose_name = _('Mailboxes and Mail Addresses')

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('managemails', '0002_auto_20150117_1238'),
]
operations = [
migrations.AlterField(
model_name='mailaddressmailbox',
name='mailaddress',
field=models.OneToOneField(primary_key=True, serialize=False, to='managemails.MailAddress', verbose_name='mailaddress'),
preserve_default=True,
),
migrations.AlterField(
model_name='mailaddressmailbox',
name='mailbox',
field=models.ForeignKey(verbose_name='mailbox', to='managemails.Mailbox'),
preserve_default=True,
),
]

View file

@ -63,7 +63,7 @@ class MailboxManager(models.Manager):
@python_2_unicode_compatible @python_2_unicode_compatible
class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model): class Mailbox(ActivateAbleMixin, TimeStampedModel):
""" """
This is the model class for a mailbox. This is the model class for a mailbox.
@ -96,6 +96,18 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model):
delete_file_mailbox.delay(self.osuser.username, self.username).get() delete_file_mailbox.delay(self.osuser.username, self.username).get()
super(Mailbox, self).delete(*args, **kwargs) super(Mailbox, self).delete(*args, **kwargs)
def get_mailaddresses(self):
"""
Get a list of mail addresses assigned to this mailbox.
"""
addrs = [
mbadr.mailaddress for mbadr in
self.mailaddressmailbox_set.all()
]
return addrs
mailaddresses = property(get_mailaddresses)
def __str__(self): def __str__(self):
return self.username return self.username
@ -125,8 +137,9 @@ class MailAddressMailbox(TimeStampedModel, models.Model):
This is the model class to assign a mail address to a mailbox. This is the model class to assign a mail address to a mailbox.
""" """
mailaddress = models.OneToOneField(MailAddress, primary_key=True) mailaddress = models.OneToOneField(
mailbox = models.ForeignKey(Mailbox) MailAddress, verbose_name=_('mailaddress'), primary_key=True)
mailbox = models.ForeignKey(Mailbox, verbose_name=_('mailbox'))
class Meta: class Meta:
unique_together = ('mailaddress', 'mailbox') unique_together = ('mailaddress', 'mailbox')