Beispiel #1
0
def update(article, content, user=None, message="", title=None):
    """
    Update an article, creating a new revision.

    Args:
        article (Article): the article object.
        content (str): the new content of the article.
        user (Account, optional): the user responsible for the update.
        message (str, optional): the message of the update.
        title (str, optional): the new article's title.

    Note:
        If `user` isn't set, get the account #1 (the superuser).
        If `title` is unset, will use the current article's title.

    """
    user = user or AccountDB.objects.get(id=1)
    current = article.current_revision
    title = title if title is not None else current.title
    revision = ArticleRevision()
    revision.inherit_predecessor(article)
    revision.title = title
    revision.content = content
    revision.user_message = message
    revision.deleted = False
    revision.ip_address = "127.0.0.1"
    article.add_revision(revision)
    return revision
Beispiel #2
0
    def form_valid(self, form):
        """Create a new article revision for the bot wiki page when the form is valid"""

        # If the article content is different, add a new revision
        if form.instance.wiki_article.current_revision.content != form.cleaned_data['wiki_article_content']:
            revision = ArticleRevision()
            revision.inherit_predecessor(form.instance.wiki_article)
            revision.title = form.instance.name
            revision.content = form.cleaned_data['wiki_article_content']
            # revision.user_message = form.cleaned_data['summary']
            revision.deleted = False
            revision.set_from_request(self.request)
            form.instance.wiki_article.add_revision(revision)
        return super(BotUpdate, self).form_valid(form)