From 2ed231a7859f96cd6ca0843011c9485ba84efca6 Mon Sep 17 00:00:00 2001 From: benjaoming Date: Sun, 3 Feb 2013 14:31:08 +0100 Subject: [PATCH] Apply user info on the creater of the first revision of the root article --- wiki/models/urlpath.py | 10 ++++++---- wiki/views/article.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/wiki/models/urlpath.py b/wiki/models/urlpath.py index 72e565fd..27703cb7 100644 --- a/wiki/models/urlpath.py +++ b/wiki/models/urlpath.py @@ -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) diff --git a/wiki/views/article.py b/wiki/views/article.py index 4375217f..01761633 100644 --- a/wiki/views/article.py +++ b/wiki/views/article.py @@ -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() -- 2.45.2