- # Always check modifications against the latest revision
- form = EditQuestionForm(question, latest_revision, request.POST)
- if form.is_valid():
- html = sanitize_html(markdowner.convert(form.cleaned_data['text']))
- if form.has_changed():
- edited_at = datetime.datetime.now()
- tags_changed = (latest_revision.tagnames !=
- form.cleaned_data['tags'])
-
- # Update the Question itself
- question.title = form.cleaned_data['title']
- question.last_edited_at = edited_at
- question.last_edited_by = request.user
- question.last_activity_at = edited_at
- question.last_activity_by = request.user
- question.tagnames = form.cleaned_data['tags']
- question.summary = strip_tags(html)[:120]
- question.html = html
-
- # only save when it's checked
- # because wiki doesn't allow to be edited if last version has been enabled already
- # and we make sure this in forms.
- if ('wiki' in form.cleaned_data and
- form.cleaned_data['wiki']):
- question.wiki = True
- question.wikified_at = edited_at
-
- question.save()
-
- # Create a new revision
- revision = QuestionRevision(
- question = question,
- title = form.cleaned_data['title'],
- author = request.user,
- revised_at = edited_at,
- tagnames = form.cleaned_data['tags'],
- text = form.cleaned_data['text'],
- )
- if form.cleaned_data['summary']:
- revision.summary = form.cleaned_data['summary']
+ form = EditQuestionForm(question, request.user, revision, data=request.POST)
+
+ if not 'select_revision' in request.POST and form.is_valid():
+ if form.has_changed():
+ action = action_class(user=request.user, node=question, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+
+ if settings.WIKI_ON:
+ if request.POST.get('wiki', False) and not question.nis.wiki:
+ question.nstate.wiki = action
+ elif question.nis.wiki and (not request.POST.get('wiki', False)) and request.user.can_cancel_wiki(question):
+ question.nstate.wiki = None
+ else:
+ if not revision == question.active_revision:
+ if allow_rollback:
+ RollbackAction(user=request.user, node=question).save(data=dict(activate=revision))