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.is_active = False
self.save(update_fields=('is_active',)) self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def get_address_name(self): def get_address_name(self):
return self.address_name or self.name return self.address_name or self.name

View File

@ -49,6 +49,10 @@ class Mailbox(models.Model):
self.is_active = False self.is_active = False
self.save(update_fields=('is_active',)) 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): def set_password(self, raw_password):
self.password = make_password(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 django.utils.translation import ugettext_lazy as _
from orchestra.admin import ExtendedModelAdmin from orchestra.admin import ExtendedModelAdmin
from orchestra.admin.actions import disable, enable
from orchestra.admin.utils import admin_link from orchestra.admin.utils import admin_link
from orchestra.contrib.accounts.admin import AccountAdminMixin from orchestra.contrib.accounts.admin import AccountAdminMixin
from orchestra.contrib.accounts.filters import IsActiveListFilter from orchestra.contrib.accounts.filters import IsActiveListFilter
@ -33,6 +34,7 @@ class MiscServiceAdmin(ExtendedModelAdmin):
) )
prepopulated_fields = {'name': ('verbose_name',)} prepopulated_fields = {'name': ('verbose_name',)}
change_readonly_fields = ('name',) change_readonly_fields = ('name',)
actions = (disable, enable)
def num_instances(self, misc): def num_instances(self, misc):
""" return num slivers as a link to slivers changelist view """ """ 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_filter = ('service__name', 'is_active')
list_select_related = ('service', 'account') list_select_related = ('service', 'account')
search_fields = ('identifier', 'description', 'account__username') search_fields = ('identifier', 'description', 'account__username')
actions = (disable, enable)
plugin_field = 'service' plugin_field = 'service'
plugin = MiscServicePlugin plugin = MiscServicePlugin

View File

@ -32,6 +32,14 @@ class MiscService(models.Model):
def get_verbose_name(self): def get_verbose_name(self):
return self.verbose_name or self.name 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): class Miscellaneous(models.Model):
service = models.ForeignKey(MiscService, verbose_name=_("service"), service = models.ForeignKey(MiscService, verbose_name=_("service"),
@ -59,6 +67,14 @@ class Miscellaneous(models.Model):
def get_description(self): def get_description(self):
return ' '.join((str(self.amount), self.service.description or self.service.verbose_name)) 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 @cached_property
def service_class(self): def service_class(self):
return self.service return self.service

View File

@ -69,6 +69,10 @@ class SaaS(models.Model):
self.is_active = False self.is_active = False
self.save(update_fields=('is_active',)) self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def clean(self): def clean(self):
if not self.pk: if not self.pk:
self.name = self.name.lower() 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 django.utils.translation import ugettext_lazy as _
from orchestra.admin import ChangeViewActionsMixin from orchestra.admin import ChangeViewActionsMixin
from orchestra.admin.actions import disable, enable
from orchestra.core import services from orchestra.core import services
from .actions import update_orders, view_help, clone from .actions import update_orders, view_help, clone
@ -37,7 +38,7 @@ class ServiceAdmin(ChangeViewActionsMixin, admin.ModelAdmin):
'on_cancel', 'payment_style', 'tax', 'nominal_price') 'on_cancel', 'payment_style', 'tax', 'nominal_price')
}), }),
) )
actions = (update_orders, clone) actions = (update_orders, clone, disable, enable)
change_view_actions = actions + (view_help,) change_view_actions = actions + (view_help,)
change_form_template = 'admin/services/service/change_form.html' change_form_template = 'admin/services/service/change_form.html'

View File

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

View File

@ -30,3 +30,11 @@ class VPS(models.Model):
def get_username(self): def get_username(self):
return self.hostname 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.is_active = False
self.save(update_fields=('is_active',)) self.save(update_fields=('is_active',))
def enable(self):
self.is_active = False
self.save(update_fields=('is_active',))
def get_settings_context(self): def get_settings_context(self):
""" format settings strings """ """ format settings strings """
return { return {