Skip to content

Commit 106636e

Browse files
committed
Create revision for initial question contribution
Without this fix, the initial contribution gets lost in the reversion history, and the first edit by a moderator is the first one to get logged, meaning we always lose the user's actual contributed version.
1 parent 6c5d20f commit 106636e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

quiz/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.core.exceptions import ValidationError
66
from django.db import models
77
from django.utils import timezone
8+
import reversion
89

910
from quiz import formatting
1011

@@ -13,6 +14,7 @@ def generate_preview_key():
1314
return ''.join(random.sample(string.ascii_lowercase + string.digits, 10))
1415

1516

17+
@reversion.register()
1618
class Question(models.Model):
1719
RESULT_CHOICES = (
1820
('OK', 'The program is guaranteed to output:'),

quiz/views.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from django.shortcuts import get_object_or_404, render
99
from django.views.decorators.cache import never_cache
1010

11+
import reversion
12+
1113
from quiz import fixed_quiz
1214
from quiz.answer import Answer
1315
from quiz.forms import QuestionForm
@@ -65,9 +67,11 @@ def create(request):
6567
if request.method == 'POST':
6668
form = QuestionForm(request.POST)
6769
if form.is_valid():
68-
form.save()
69-
mail_admins('Someone made a question!', 'https://' + request.get_host() + '/admin/quiz/question/?state=NEW')
70-
return HttpResponseRedirect('/quiz/created')
70+
with reversion.create_revision():
71+
form.save()
72+
reversion.set_comment("User contribution")
73+
mail_admins('Someone made a question!', 'https://' + request.get_host() + '/admin/quiz/question/?state=NEW')
74+
return HttpResponseRedirect('/quiz/created')
7175
else:
7276
form = QuestionForm()
7377
return render(request, 'quiz/create.html',

0 commit comments

Comments
 (0)