Implemented enable admin action0

This commit is contained in:
Marc Aymerich 2016-03-31 16:18:38 +00:00
parent 4adfd4c83a
commit 908a4ca81d
9 changed files with 49 additions and 1 deletions

View file

@ -59,6 +59,10 @@ class List(models.Model):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def get_address_name(self):
return self.address_name or self.name

View file

@ -49,6 +49,10 @@ class Mailbox(models.Model):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def set_password(self, raw_password):
self.password = make_password(raw_password)

View file

@ -6,6 +6,7 @@ from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from orchestra.admin import ExtendedModelAdmin
from orchestra.admin.actions import disable, enable
from orchestra.admin.utils import admin_link
from orchestra.contrib.accounts.admin import AccountAdminMixin
from orchestra.contrib.accounts.filters import IsActiveListFilter
@ -33,6 +34,7 @@ class MiscServiceAdmin(ExtendedModelAdmin):
)
prepopulated_fields = {'name': ('verbose_name',)}
change_readonly_fields = ('name',)
actions = (disable, enable)
def num_instances(self, misc):
""" return num slivers as a link to slivers changelist view """
@ -61,6 +63,7 @@ class MiscellaneousAdmin(AccountAdminMixin, SelectPluginAdminMixin, admin.ModelA
list_filter = ('service__name', 'is_active')
list_select_related = ('service', 'account')
search_fields = ('identifier', 'description', 'account__username')
actions = (disable, enable)
plugin_field = 'service'
plugin = MiscServicePlugin

View file

@ -31,6 +31,14 @@ class MiscService(models.Model):
def get_verbose_name(self):
return self.verbose_name or self.name
def disable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
class Miscellaneous(models.Model):
@ -59,6 +67,14 @@ class Miscellaneous(models.Model):
def get_description(self):
return ' '.join((str(self.amount), self.service.description or self.service.verbose_name))
def disable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
@cached_property
def service_class(self):
return self.service

View file

@ -69,6 +69,10 @@ class SaaS(models.Model):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def clean(self):
if not self.pk:
self.name = self.name.lower()

View file

@ -7,6 +7,7 @@ from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from orchestra.admin import ChangeViewActionsMixin
from orchestra.admin.actions import disable, enable
from orchestra.core import services
from .actions import update_orders, view_help, clone
@ -37,7 +38,7 @@ class ServiceAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
'on_cancel', 'payment_style', 'tax', 'nominal_price')
}),
)
actions = (update_orders, clone)
actions = (update_orders, clone, disable, enable)
change_view_actions = actions + (view_help,)
change_form_template = 'admin/services/service/change_form.html'

View file

@ -87,6 +87,10 @@ class SystemUser(models.Model):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def get_description(self):
return self.get_shell_display()

View file

@ -30,3 +30,11 @@ class VPS(models.Model):
def get_username(self):
return self.hostname
def disable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))

View file

@ -55,6 +55,10 @@ class Website(models.Model):
self.is_active = False
self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def get_settings_context(self):
""" format settings strings """
return {