~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wiki/forms.py

  • Committer: Timo Wingender
  • Date: 2010-09-28 21:26:23 UTC
  • mto: This revision was merged to the branch mainline in revision 218.
  • Revision ID: timo.wingender@gmx.de-20100928212623-awo0wh3hcaptc0oj
add field to choose between markdown and bbcode as markup

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
 
61
61
        return self.cleaned_data
62
62
 
63
 
    def cache_old_content(self):
64
 
        if self.instance.id is None:
65
 
            self.old_title = self.old_content = self.old_markup = ''
66
 
            self.is_new = True
67
 
        else:
68
 
            self.old_title = self.instance.title
69
 
            self.old_content = self.instance.content
70
 
            self.old_markup = self.instance.markup
71
 
            self.is_new = False
72
 
 
73
 
    def save(self, *args, **kwargs):
 
63
    def save(self):
74
64
        # 0 - Extra data
75
65
        editor_ip = self.cleaned_data['user_ip']
76
66
        comment = self.cleaned_data['comment']
77
67
 
 
68
        # 1 - Get the old stuff before saving
 
69
        if self.instance.id is None:
 
70
            old_title = old_content = old_markup = ''
 
71
            new = True
 
72
        else:
 
73
            old_title = self.instance.title
 
74
            old_content = self.instance.content
 
75
            old_markup = self.instance.markup
 
76
            new = False
 
77
 
78
78
        # 2 - Save the Article
79
 
        article = super(ArticleForm, self).save(*args, **kwargs)
 
79
        article = super(ArticleForm, self).save()
80
80
 
81
81
        # 3 - Set creator and group
82
82
        editor = getattr(self, 'editor', None)
83
83
        group = getattr(self, 'group', None)
84
 
        if self.is_new:
 
84
        if new:
85
85
            article.creator_ip = editor_ip
86
86
            if editor is not None:
87
87
                article.creator = editor
88
88
                article.group = group
89
 
            article.save(*args, **kwargs)
 
89
            article.save()
90
90
 
91
91
        # 4 - Create new revision
92
92
        changeset = article.new_revision(
93
 
            self.old_content, self.old_title, self.old_markup,
 
93
            old_content, old_title, old_markup,
94
94
            comment, editor_ip, editor)
95
95
 
96
96
        return article, changeset