Skip to content

Commit

Permalink
MailSubscriptionAbstract.get_final_slug method refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ilstreltsov committed Jul 6, 2017
1 parent e50a750 commit 04d631b
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions dbmail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,17 +846,21 @@ def notify(cls, slug, user_id=None, sub_filter=None, **kwargs):
def update_notify_kwargs(self, **kwargs):
return kwargs

def get_final_slug(self, slug, short_type):
extra_slug = '%s-%s' % (slug, short_type)
use_slug = slug
def get_final_slug(self, slug, _):
for extra_slug in self.get_extra_slugs(slug):
try:
if MailTemplate.get_template(slug=extra_slug):
slug = extra_slug
break
except MailTemplate.DoesNotExist:
pass

try:
if MailTemplate.get_template(slug=extra_slug):
use_slug = extra_slug
except MailTemplate.DoesNotExist:
pass
return slug

return use_slug
def get_extra_slugs(self, slug):
return [
u'{}-{}'.format(slug, self.get_short_type()),
]

def get_short_type(self):
return self.backend.split('.')[-1]
Expand Down

0 comments on commit 04d631b

Please sign in to comment.