diff --git a/orchestra/apps/contacts/admin.py b/orchestra/apps/contacts/admin.py index 0c8feeb9..04aa387f 100644 --- a/orchestra/apps/contacts/admin.py +++ b/orchestra/apps/contacts/admin.py @@ -12,8 +12,7 @@ from .models import Contact class ContactAdmin(AccountAdminMixin, admin.ModelAdmin): list_display = ( - 'short_name', 'full_name', 'email', 'phone', 'phone2', 'country', - 'account_link' + 'dispaly_name', 'email', 'phone', 'phone2', 'country', 'account_link' ) list_filter = ('email_usage',) search_fields = ( @@ -57,6 +56,11 @@ class ContactAdmin(AccountAdminMixin, admin.ModelAdmin): }), ) + def dispaly_name(self, contact): + return unicode(contact) + dispaly_name.short_description = _("Name") + dispaly_name.admin_order_field = 'short_name' + def formfield_for_dbfield(self, db_field, **kwargs): """ Make value input widget bigger """ if db_field.name == 'address': diff --git a/orchestra/apps/contacts/models.py b/orchestra/apps/contacts/models.py index afaae3ae..7a4d1494 100644 --- a/orchestra/apps/contacts/models.py +++ b/orchestra/apps/contacts/models.py @@ -56,7 +56,7 @@ class Contact(models.Model): default=settings.CONTACTS_DEFAULT_COUNTRY) def __unicode__(self): - return self.short_name + return self.full_name or self.short_name def clean(self): self.short_name = self.short_name.strip() diff --git a/orchestra/apps/mailboxes/admin.py b/orchestra/apps/mailboxes/admin.py index 04b50ac7..549a7851 100644 --- a/orchestra/apps/mailboxes/admin.py +++ b/orchestra/apps/mailboxes/admin.py @@ -31,6 +31,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo 'name', 'account_link', 'filtering', 'display_addresses' ) list_filter = (HasAddressListFilter, 'filtering') + search_fields = ('account__username', 'account__short_name', 'account__full_name', 'name') add_fieldsets = ( (None, { 'fields': ('account_link', 'name', 'password1', 'password2', 'filtering'), diff --git a/orchestra/apps/mailboxes/backends.py b/orchestra/apps/mailboxes/backends.py index 0ad80e50..86bfddb7 100644 --- a/orchestra/apps/mailboxes/backends.py +++ b/orchestra/apps/mailboxes/backends.py @@ -213,14 +213,14 @@ class MaildirDisk(ServiceMonitor): def monitor(self, mailbox): context = self.get_context(mailbox) self.append( - "SIZE=$(sed -n '2p' %(maildir_path)s | cut -d' ' -f1)\n" + "SIZE=$(awk 'NR>1 {s+=$1} END {print s}' %(maildir_path)s)\n" "echo %(object_id)s ${SIZE:-0}" % context ) def get_context(self, mailbox): - home = mailbox.get_home() context = { - 'maildir_path': os.path.join(home, 'Maildir/maildirsize'), + 'home': mailbox.get_home(), 'object_id': mailbox.pk } + context['maildir_path'] = settings.MAILBOXES_MAILDIRSIZE_PATH % context return context diff --git a/orchestra/apps/mailboxes/settings.py b/orchestra/apps/mailboxes/settings.py index 750c99b1..5ca32e30 100644 --- a/orchestra/apps/mailboxes/settings.py +++ b/orchestra/apps/mailboxes/settings.py @@ -62,3 +62,6 @@ MAILBOXES_MAILBOX_FILTERINGS = getattr(settings, 'MAILBOXES_MAILBOX_FILTERINGS', MAILBOXES_MAILBOX_DEFAULT_FILTERING = getattr(settings, 'MAILBOXES_MAILBOX_DEFAULT_FILTERING', 'REDIRECT') + + +MAILBOXES_MAILDIRSIZE_PATH = getattr(settings, 'MAILBOXES_MAILDIRSIZE_PATH', '%(home)s/Maildir/maildirsize') diff --git a/orchestra/apps/resources/admin.py b/orchestra/apps/resources/admin.py index 65ba6a37..7034c6b4 100644 --- a/orchestra/apps/resources/admin.py +++ b/orchestra/apps/resources/admin.py @@ -90,6 +90,7 @@ class ResourceDataAdmin(ExtendedModelAdmin): 'resource_link', 'content_type', 'content_object_link', 'display_used', 'display_updated', 'allocated', 'display_unit' ) + search_fields = ('object_id',) readonly_fields = fields actions = (run_monitor,) change_view_actions = actions diff --git a/orchestra/apps/resources/helpers.py b/orchestra/apps/resources/helpers.py index e2ab03b1..f2c95de3 100644 --- a/orchestra/apps/resources/helpers.py +++ b/orchestra/apps/resources/helpers.py @@ -29,7 +29,7 @@ def compute_resource_usage(data): has_result = True result += sum(values) elif resource.period == resource.LAST: - dataset.value + result = dataset.value has_result = True else: raise NotImplementedError("%s support not implemented" % data.period) diff --git a/orchestra/apps/resources/models.py b/orchestra/apps/resources/models.py index b65f9505..f783e163 100644 --- a/orchestra/apps/resources/models.py +++ b/orchestra/apps/resources/models.py @@ -133,7 +133,7 @@ class ResourceData(models.Model): resource = models.ForeignKey(Resource, related_name='dataset', verbose_name=_("resource")) content_type = models.ForeignKey(ContentType, verbose_name=_("content type")) object_id = models.PositiveIntegerField(_("object id")) - used = models.DecimalField(_("used"), max_digits=16, decimal_places=2, null=True, + used = models.DecimalField(_("used"), max_digits=16, decimal_places=3, null=True, editable=False) updated_at = models.DateTimeField(_("updated"), null=True, editable=False) allocated = models.DecimalField(_("allocated"), max_digits=8, decimal_places=2, diff --git a/orchestra/apps/resources/tasks.py b/orchestra/apps/resources/tasks.py index 8ffb05c0..6c650a63 100644 --- a/orchestra/apps/resources/tasks.py +++ b/orchestra/apps/resources/tasks.py @@ -37,20 +37,10 @@ def monitor(resource_id, ids=None): data = ResourceData.get_or_create(obj, resource) data.update() if not resource.disable_trigger: - if data.used < data.allocated: + if data.used > data.allocated: op = Operation.create(backend, obj, Operation.EXCEED) operations.append(op) elif data.used < data.allocated: op = Operation.create(backend, obj, Operation.RECOVERY) operations.append(op) -# data = ResourceData.get_or_create(obj, resource) -# current = data.get_used() -# if not resource.disable_trigger: -# if data.used < data.allocated and current > data.allocated: -# op = Operation.create(backend, obj, Operation.EXCEED) -# operations.append(op) -# elif data.used > data.allocated and current < data.allocated: -# op = Operation.create(backend, obj, Operation.RECOVERY) -# operation.append(op) -# data.update(current=current) Operation.execute(operations) diff --git a/orchestra/apps/webapps/admin.py b/orchestra/apps/webapps/admin.py index 711f0573..25797ace 100644 --- a/orchestra/apps/webapps/admin.py +++ b/orchestra/apps/webapps/admin.py @@ -38,7 +38,7 @@ class WebAppOptionInline(admin.TabularInline): class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin): - list_display = ('name', 'type', 'display_websites', 'account_link') + list_display = ('display_name', 'type', 'display_websites', 'account_link') list_filter = ('type',) add_fields = ('account', 'name', 'type') fields = ('account_link', 'name', 'type') @@ -52,6 +52,11 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin): for k, v in settings.WEBAPPS_TYPES.iteritems() } + def display_name(self, webapp): + return webapp.get_name() + display_name.short_description = _("Name") + display_name.admin_order_field = 'name' + def display_websites(self, webapp): websites = [] for content in webapp.content_set.all():