Commit 6e472422 by benjaoming

Fix #191 - introduce DRY in plugins.notifications default_url

parent 363f50ac
...@@ -193,7 +193,7 @@ class ArticleForObject(models.Model): ...@@ -193,7 +193,7 @@ class ArticleForObject(models.Model):
verbose_name=_('content type'), verbose_name=_('content type'),
related_name="content_type_set_for_%(class)s") related_name="content_type_set_for_%(class)s")
object_id = models.PositiveIntegerField(_('object ID')) object_id = models.PositiveIntegerField(_('object ID'))
content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_id") content_object = generic.GenericForeignKey("content_type", "object_id")
is_mptt = models.BooleanField(default=False, editable=False) is_mptt = models.BooleanField(default=False, editable=False)
......
...@@ -33,11 +33,19 @@ class URLPath(MPTTModel): ...@@ -33,11 +33,19 @@ class URLPath(MPTTModel):
objects = managers.URLPathManager() objects = managers.URLPathManager()
_default_manager = objects _default_manager = objects
articles = generic.GenericRelation(ArticleForObject) articles = generic.GenericRelation(
ArticleForObject,
content_type_field='content_type',
object_id_field='object_id',
)
# Do NOT modify this field - it is updated with signals whenever ArticleForObject is changed. # Do NOT modify this field - it is updated with signals whenever ArticleForObject is changed.
article = models.ForeignKey(Article, on_delete=models.CASCADE, editable=False, article = models.ForeignKey(
verbose_name=_(u'Cache lookup value for articles')) Article,
on_delete=models.CASCADE,
editable=False,
verbose_name=_(u'Cache lookup value for articles'),
)
SLUG_MAX_LENGTH = 50 SLUG_MAX_LENGTH = 50
......
...@@ -26,13 +26,10 @@ class ArticleSubscription(ArticlePlugin, Subscription): ...@@ -26,13 +26,10 @@ class ArticleSubscription(ArticlePlugin, Subscription):
def default_url(article, urlpath=None): def default_url(article, urlpath=None):
try: if urlpath:
if not urlpath: return reverse('wiki:get', kwargs={'path': urlpath.path})
urlpath = wiki_models.URLPath.objects.get(articles=article) return article.get_absolute_url()
url = reverse('wiki:get', kwargs={'path': urlpath.path})
except wiki_models.URLPath.DoesNotExist:
url = reverse('wiki:get', kwargs={'article_id': article.id})
return url
def post_article_revision_save(**kwargs): def post_article_revision_save(**kwargs):
instance = kwargs['instance'] instance = kwargs['instance']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment