diff --git a/orchestra/contrib/lists/models.py b/orchestra/contrib/lists/models.py index 75c01b53..cd5af8a6 100644 --- a/orchestra/contrib/lists/models.py +++ b/orchestra/contrib/lists/models.py @@ -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 diff --git a/orchestra/contrib/mailboxes/models.py b/orchestra/contrib/mailboxes/models.py index cb0630de..fd11e01e 100644 --- a/orchestra/contrib/mailboxes/models.py +++ b/orchestra/contrib/mailboxes/models.py @@ -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) diff --git a/orchestra/contrib/miscellaneous/admin.py b/orchestra/contrib/miscellaneous/admin.py index 91795a2b..1393034a 100644 --- a/orchestra/contrib/miscellaneous/admin.py +++ b/orchestra/contrib/miscellaneous/admin.py @@ -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 diff --git a/orchestra/contrib/miscellaneous/models.py b/orchestra/contrib/miscellaneous/models.py index eb4b8c86..82c0a5b6 100644 --- a/orchestra/contrib/miscellaneous/models.py +++ b/orchestra/contrib/miscellaneous/models.py @@ -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 diff --git a/orchestra/contrib/saas/models.py b/orchestra/contrib/saas/models.py index ab273ae7..b5b4e23e 100644 --- a/orchestra/contrib/saas/models.py +++ b/orchestra/contrib/saas/models.py @@ -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() diff --git a/orchestra/contrib/services/admin.py b/orchestra/contrib/services/admin.py index 5f1b2d49..b7ba6b12 100644 --- a/orchestra/contrib/services/admin.py +++ b/orchestra/contrib/services/admin.py @@ -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' diff --git a/orchestra/contrib/systemusers/models.py b/orchestra/contrib/systemusers/models.py index cbf26728..ebd15def 100644 --- a/orchestra/contrib/systemusers/models.py +++ b/orchestra/contrib/systemusers/models.py @@ -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() diff --git a/orchestra/contrib/vps/models.py b/orchestra/contrib/vps/models.py index 93441fac..d0a69f85 100644 --- a/orchestra/contrib/vps/models.py +++ b/orchestra/contrib/vps/models.py @@ -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',)) diff --git a/orchestra/contrib/websites/models.py b/orchestra/contrib/websites/models.py index aa31dc6d..6492bbd3 100644 --- a/orchestra/contrib/websites/models.py +++ b/orchestra/contrib/websites/models.py @@ -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 {