Example #1
0
 def create_article(cls, parent, slug, site=None, title="Root", **kwargs):
     if not site:
         site = Site.objects.get_current()
     newpath = cls.objects.create(site=site, parent=parent, slug=slug)
     article = Article(title=title)
     article.add_revision(ArticleRevision(title=title, **kwargs), save=True)
     article.add_object_relation(newpath)
     return newpath
Example #2
0
 def create_root(cls, site=None, title="Root", **kwargs):
     if not site:
         site = Site.objects.get_current()
     root_nodes = cls.objects.root_nodes().filter(site=site)
     if not root_nodes:
         # (get_or_create does not work for MPTT models??)
         root = cls.objects.create(site=site)
         article = Article(title=title)
         article.add_revision(ArticleRevision(title=title, **kwargs), save=True)
         article.add_object_relation(root)
     else:
         root = root_nodes[0]
     return root
Example #3
0
def on_article_delete(instance, *args, **kwargs):
    # If an article is deleted, then throw out its URLPaths
    # But move all descendants to a lost-and-found node.
    site = Site.objects.get_current()

    try:
        lost_and_found = URLPath.objects.get(slug=settings.LOST_AND_FOUND_SLUG, parent=URLPath.root(), site=site)
    except URLPath.DoesNotExist:
        lost_and_found = URLPath.objects.create(slug=settings.LOST_AND_FOUND_SLUG, parent=URLPath.root(), site=site)
        article = Article(
            title=_(u"Lost and found"), group_read=True, group_write=False, other_read=False, other_write=False
        )
        article.add_revision(
            ArticleRevision(content=_(u"Articles who lost their parents" "==============================="))
        )

    for urlpath in URLPath.objects.filter(articles__article=article, site=site):
        for child in urlpath.get_children():
            child.move_to(lost_and_found)