Fixes on maildirsize monitoring
This commit is contained in:
parent
7479c47852
commit
ae7c5b7969
|
@ -12,8 +12,7 @@ from .models import Contact
|
||||||
|
|
||||||
class ContactAdmin(AccountAdminMixin, admin.ModelAdmin):
|
class ContactAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||||
list_display = (
|
list_display = (
|
||||||
'short_name', 'full_name', 'email', 'phone', 'phone2', 'country',
|
'dispaly_name', 'email', 'phone', 'phone2', 'country', 'account_link'
|
||||||
'account_link'
|
|
||||||
)
|
)
|
||||||
list_filter = ('email_usage',)
|
list_filter = ('email_usage',)
|
||||||
search_fields = (
|
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):
|
def formfield_for_dbfield(self, db_field, **kwargs):
|
||||||
""" Make value input widget bigger """
|
""" Make value input widget bigger """
|
||||||
if db_field.name == 'address':
|
if db_field.name == 'address':
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Contact(models.Model):
|
||||||
default=settings.CONTACTS_DEFAULT_COUNTRY)
|
default=settings.CONTACTS_DEFAULT_COUNTRY)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.short_name
|
return self.full_name or self.short_name
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
self.short_name = self.short_name.strip()
|
self.short_name = self.short_name.strip()
|
||||||
|
|
|
@ -31,6 +31,7 @@ class MailboxAdmin(ChangePasswordAdminMixin, SelectAccountAdminMixin, ExtendedMo
|
||||||
'name', 'account_link', 'filtering', 'display_addresses'
|
'name', 'account_link', 'filtering', 'display_addresses'
|
||||||
)
|
)
|
||||||
list_filter = (HasAddressListFilter, 'filtering')
|
list_filter = (HasAddressListFilter, 'filtering')
|
||||||
|
search_fields = ('account__username', 'account__short_name', 'account__full_name', 'name')
|
||||||
add_fieldsets = (
|
add_fieldsets = (
|
||||||
(None, {
|
(None, {
|
||||||
'fields': ('account_link', 'name', 'password1', 'password2', 'filtering'),
|
'fields': ('account_link', 'name', 'password1', 'password2', 'filtering'),
|
||||||
|
|
|
@ -213,14 +213,14 @@ class MaildirDisk(ServiceMonitor):
|
||||||
def monitor(self, mailbox):
|
def monitor(self, mailbox):
|
||||||
context = self.get_context(mailbox)
|
context = self.get_context(mailbox)
|
||||||
self.append(
|
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
|
"echo %(object_id)s ${SIZE:-0}" % context
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_context(self, mailbox):
|
def get_context(self, mailbox):
|
||||||
home = mailbox.get_home()
|
|
||||||
context = {
|
context = {
|
||||||
'maildir_path': os.path.join(home, 'Maildir/maildirsize'),
|
'home': mailbox.get_home(),
|
||||||
'object_id': mailbox.pk
|
'object_id': mailbox.pk
|
||||||
}
|
}
|
||||||
|
context['maildir_path'] = settings.MAILBOXES_MAILDIRSIZE_PATH % context
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -62,3 +62,6 @@ MAILBOXES_MAILBOX_FILTERINGS = getattr(settings, 'MAILBOXES_MAILBOX_FILTERINGS',
|
||||||
|
|
||||||
|
|
||||||
MAILBOXES_MAILBOX_DEFAULT_FILTERING = getattr(settings, 'MAILBOXES_MAILBOX_DEFAULT_FILTERING', 'REDIRECT')
|
MAILBOXES_MAILBOX_DEFAULT_FILTERING = getattr(settings, 'MAILBOXES_MAILBOX_DEFAULT_FILTERING', 'REDIRECT')
|
||||||
|
|
||||||
|
|
||||||
|
MAILBOXES_MAILDIRSIZE_PATH = getattr(settings, 'MAILBOXES_MAILDIRSIZE_PATH', '%(home)s/Maildir/maildirsize')
|
||||||
|
|
|
@ -90,6 +90,7 @@ class ResourceDataAdmin(ExtendedModelAdmin):
|
||||||
'resource_link', 'content_type', 'content_object_link', 'display_used', 'display_updated',
|
'resource_link', 'content_type', 'content_object_link', 'display_used', 'display_updated',
|
||||||
'allocated', 'display_unit'
|
'allocated', 'display_unit'
|
||||||
)
|
)
|
||||||
|
search_fields = ('object_id',)
|
||||||
readonly_fields = fields
|
readonly_fields = fields
|
||||||
actions = (run_monitor,)
|
actions = (run_monitor,)
|
||||||
change_view_actions = actions
|
change_view_actions = actions
|
||||||
|
|
|
@ -29,7 +29,7 @@ def compute_resource_usage(data):
|
||||||
has_result = True
|
has_result = True
|
||||||
result += sum(values)
|
result += sum(values)
|
||||||
elif resource.period == resource.LAST:
|
elif resource.period == resource.LAST:
|
||||||
dataset.value
|
result = dataset.value
|
||||||
has_result = True
|
has_result = True
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("%s support not implemented" % data.period)
|
raise NotImplementedError("%s support not implemented" % data.period)
|
||||||
|
|
|
@ -133,7 +133,7 @@ class ResourceData(models.Model):
|
||||||
resource = models.ForeignKey(Resource, related_name='dataset', verbose_name=_("resource"))
|
resource = models.ForeignKey(Resource, related_name='dataset', verbose_name=_("resource"))
|
||||||
content_type = models.ForeignKey(ContentType, verbose_name=_("content type"))
|
content_type = models.ForeignKey(ContentType, verbose_name=_("content type"))
|
||||||
object_id = models.PositiveIntegerField(_("object id"))
|
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)
|
editable=False)
|
||||||
updated_at = models.DateTimeField(_("updated"), null=True, editable=False)
|
updated_at = models.DateTimeField(_("updated"), null=True, editable=False)
|
||||||
allocated = models.DecimalField(_("allocated"), max_digits=8, decimal_places=2,
|
allocated = models.DecimalField(_("allocated"), max_digits=8, decimal_places=2,
|
||||||
|
|
|
@ -37,20 +37,10 @@ def monitor(resource_id, ids=None):
|
||||||
data = ResourceData.get_or_create(obj, resource)
|
data = ResourceData.get_or_create(obj, resource)
|
||||||
data.update()
|
data.update()
|
||||||
if not resource.disable_trigger:
|
if not resource.disable_trigger:
|
||||||
if data.used < data.allocated:
|
if data.used > data.allocated:
|
||||||
op = Operation.create(backend, obj, Operation.EXCEED)
|
op = Operation.create(backend, obj, Operation.EXCEED)
|
||||||
operations.append(op)
|
operations.append(op)
|
||||||
elif data.used < data.allocated:
|
elif data.used < data.allocated:
|
||||||
op = Operation.create(backend, obj, Operation.RECOVERY)
|
op = Operation.create(backend, obj, Operation.RECOVERY)
|
||||||
operations.append(op)
|
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)
|
Operation.execute(operations)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class WebAppOptionInline(admin.TabularInline):
|
||||||
|
|
||||||
|
|
||||||
class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
||||||
list_display = ('name', 'type', 'display_websites', 'account_link')
|
list_display = ('display_name', 'type', 'display_websites', 'account_link')
|
||||||
list_filter = ('type',)
|
list_filter = ('type',)
|
||||||
add_fields = ('account', 'name', 'type')
|
add_fields = ('account', 'name', 'type')
|
||||||
fields = ('account_link', 'name', 'type')
|
fields = ('account_link', 'name', 'type')
|
||||||
|
@ -52,6 +52,11 @@ class WebAppAdmin(AccountAdminMixin, ExtendedModelAdmin):
|
||||||
for k, v in settings.WEBAPPS_TYPES.iteritems()
|
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):
|
def display_websites(self, webapp):
|
||||||
websites = []
|
websites = []
|
||||||
for content in webapp.content_set.all():
|
for content in webapp.content_set.all():
|
||||||
|
|
Loading…
Reference in a new issue