From 03e5c74d7a35c756e4c2ef2b690b7ada3f6dc7f3 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Sat, 24 Jan 2015 22:26:27 +0100 Subject: [PATCH] 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 --- gnuviechadmin/hostingpackages/models.py | 14 ++++++++++++-- .../templates/dashboard/user_dashboard.html | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gnuviechadmin/hostingpackages/models.py b/gnuviechadmin/hostingpackages/models.py index 044b755..ed9dc40 100644 --- a/gnuviechadmin/hostingpackages/models.py +++ b/gnuviechadmin/hostingpackages/models.py @@ -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): """ diff --git a/gnuviechadmin/templates/dashboard/user_dashboard.html b/gnuviechadmin/templates/dashboard/user_dashboard.html index 929a088..35a20c0 100644 --- a/gnuviechadmin/templates/dashboard/user_dashboard.html +++ b/gnuviechadmin/templates/dashboard/user_dashboard.html @@ -28,7 +28,7 @@ {{ diskspace|filesizeformat }} {% endwith %} - {% blocktrans with num=package.get_used_mailboxes total=package.get_mailboxes %}used {{ num }} of {{ total }}{% endblocktrans %} + {% blocktrans with num=package.used_mailbox_count total=package.mailbox_count %}used {{ num }} of {{ total }}{% endblocktrans %} {% for dbtype in package.get_databases %} {{ dbtype.number }} {% include "userdbs/snippets/db_type.html" with db_type=dbtype.db_type %} {% if not forloop.last %} / {% endif %}