add model features to hostingpackages

- add properties mailboxes, used_mailbox_count, mailbox_count and
  may_add_mailbox to CustomerHostingPackage class
- use new properties in template dashboard/user_dashboard.html
This commit is contained in:
Jan Dittberner 2015-01-24 22:26:27 +01:00
parent 8a84c9660a
commit 03e5c74d7a
2 changed files with 13 additions and 3 deletions

View file

@ -272,7 +272,12 @@ class CustomerHostingPackage(HostingPackageBase):
hard = soft * 105 / 100
return (soft, hard)
def get_used_mailboxes(self):
def get_mailboxes(self):
if self.osuser:
return Mailbox.objects.filter(osuser=self.osuser).all()
mailboxes = property(get_mailboxes)
def get_used_mailbox_count(self):
"""
Get the number of used mailboxes for this hosting package.
@ -280,8 +285,9 @@ class CustomerHostingPackage(HostingPackageBase):
if self.osuser:
return Mailbox.objects.filter(osuser=self.osuser).count()
return 0
used_mailbox_count = property(get_used_mailbox_count)
def get_mailboxes(self):
def get_mailbox_count(self):
"""
Get the number of mailboxes provided by this hosting package and all
of its mailbox options.
@ -293,6 +299,10 @@ class CustomerHostingPackage(HostingPackageBase):
mailbox_sum=models.Sum('number')
)
return self.mailboxcount + (result['mailbox_sum'] or 0)
mailbox_count = property(get_mailbox_count)
def may_add_mailbox(self):
return self.used_mailbox_count < self.mailbox_count
def get_databases(self):
"""