Add natural key support to the user mailer model.
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
8
mayan/apps/mailer/managers.py
Normal file
8
mayan/apps/mailer/managers.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
class UserMailerManager(models.Manager):
|
||||
def get_by_natural_key(self, label):
|
||||
return self.get(label=label)
|
||||
@@ -11,6 +11,7 @@ from django.utils.html import strip_tags
|
||||
from django.utils.module_loading import import_string
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from .managers import UserMailerManager
|
||||
from .utils import split_recipient_list
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -51,6 +52,8 @@ class UserMailer(models.Model):
|
||||
blank=True, verbose_name=_('Backend data')
|
||||
)
|
||||
|
||||
objects = UserMailerManager()
|
||||
|
||||
class Meta:
|
||||
ordering = ('label',)
|
||||
verbose_name = _('User mailer')
|
||||
@@ -77,6 +80,9 @@ class UserMailer(models.Model):
|
||||
def loads(self):
|
||||
return json.loads(self.backend_data)
|
||||
|
||||
def natural_key(self):
|
||||
return (self.label,)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.default:
|
||||
UserMailer.objects.select_for_update().exclude(pk=self.pk).update(
|
||||
|
||||
Reference in New Issue
Block a user