|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
| 3 | +from dirtyfields import DirtyFieldsMixin |
3 | 4 | from django.db import models
|
4 | 5 | from django.utils.translation import ugettext_lazy as _
|
5 | 6 | from django.utils.encoding import python_2_unicode_compatible
|
6 |
| - |
| 7 | +from djangoplugins.signals import django_plugin_enabled, django_plugin_disabled |
7 | 8 | from .utils import get_plugin_name, get_plugin_from_string
|
8 | 9 |
|
9 | 10 | ENABLED = 0
|
|
16 | 17 | (REMOVED, _('Removed')),
|
17 | 18 | )
|
18 | 19 |
|
| 20 | +STATUS_CHOICES_ENABLED = (ENABLED,) |
| 21 | +STATUS_CHOICES_DISABLED = (DISABLED, REMOVED,) |
| 22 | + |
19 | 23 |
|
20 | 24 | class PluginPointManager(models.Manager):
|
21 | 25 | def get_point(self, point):
|
@@ -47,7 +51,7 @@ def get_by_natural_key(self, name):
|
47 | 51 |
|
48 | 52 |
|
49 | 53 | @python_2_unicode_compatible
|
50 |
| -class Plugin(models.Model): |
| 54 | +class Plugin(DirtyFieldsMixin, models.Model): |
51 | 55 | """
|
52 | 56 | Database representation of a plugin.
|
53 | 57 |
|
@@ -101,3 +105,14 @@ def is_active(self):
|
101 | 105 | def get_plugin(self):
|
102 | 106 | plugin_class = get_plugin_from_string(self.pythonpath)
|
103 | 107 | return plugin_class()
|
| 108 | + |
| 109 | + def save(self, *args, **kwargs): |
| 110 | + if "status" in self.get_dirty_fields().keys() and self.pk: |
| 111 | + if self.status in STATUS_CHOICES_ENABLED: |
| 112 | + django_plugin_enabled.send(sender=self.__class__, |
| 113 | + plugin=self.get_plugin()) |
| 114 | + else: |
| 115 | + django_plugin_disabled.send(sender=self.__class__, |
| 116 | + plugin=self.get_plugin()) |
| 117 | + |
| 118 | + return super(Plugin, self).save(*args, **kwargs) |
0 commit comments