~netlandish/django-wiki

2ed231a7859f96cd6ca0843011c9485ba84efca6 — benjaoming 11 years ago c50e05f
Apply user info on the creater of the first revision of the root article
2 files changed, 8 insertions(+), 5 deletions(-)

M wiki/models/urlpath.py
M wiki/views/article.py
M wiki/models/urlpath.py => wiki/models/urlpath.py +6 -4
@@ 199,14 199,15 @@ class URLPath(MPTTModel):
        return reverse('wiki:get', kwargs={'path': self.path})
    
    @classmethod
    def create_root(cls, site=None, title="Root", **kwargs):
    def create_root(cls, site=None, title="Root", request=None, **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??)
            article = Article()
            article.add_revision(ArticleRevision(title=title, **kwargs),
                                 save=True)
            revision = ArticleRevision(title=title, **kwargs)
            if request: revision.set_from_request(request)
            article.add_revision(revision, save=True)
            article.save()
            root = cls.objects.create(site=site, article=article)
            article.add_object_relation(root)


@@ 218,7 219,8 @@ class URLPath(MPTTModel):
    def create_article(cls, parent, slug, site=None, title="Root", article_kwargs={}, **kwargs):
        """Utility function:
        Create a new urlpath with an article and a new revision for the article"""
        if not site: site = Site.objects.get_current()
        if not site:
            site = Site.objects.get_current()
        article = Article(**article_kwargs)
        article.add_revision(ArticleRevision(title=title, **kwargs),
                             save=True)

M wiki/views/article.py => wiki/views/article.py +2 -1
@@ 718,7 718,8 @@ def root_create(request):
        create_form = forms.CreateRootForm(request.POST)
        if create_form.is_valid():
            models.URLPath.create_root(title=create_form.cleaned_data["title"],
                                       content=create_form.cleaned_data["content"])
                                       content=create_form.cleaned_data["content"],
                                       request=request)
            return redirect("wiki:root")
    else:
        create_form = forms.CreateRootForm()