Commit 942ecf79 authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Change comment ratings based on user feedback.

parent bfeda3cc
......@@ -24,8 +24,10 @@
<div class="form-group">
<div class="col-lg-12">
<input type="submit" name="comment_sub" class="btn btn-primary"
value="Submit Comment" />
<input type="submit" name="comment_sub_a" class="btn btn-primary"
value="Good Question" />
<input type="submit" name="comment_sub_b" class="btn btn-primary"
value="Needs Work" />
</div>
</div>
</fieldset>
......
......@@ -14,7 +14,7 @@ class Question( models.Model ):
rating = models.IntegerField(default=0)
class Meta:
ordering = ["rating"]
ordering = ["-rating"]
def get_comments(self):
comments = Comment.objects.filter(parent__pk=self.pk)
......@@ -28,7 +28,7 @@ class Question( models.Model ):
return anonymized( self )
def __unicode__(self):
return '%s, %s' % ( self.user, self.text[:50] )
return '%s (%s): %s' % ( self.user, self.rating, self.text[:50] )
class Comment( models.Model ):
user = models.ForeignKey(User)
......@@ -44,7 +44,7 @@ class Comment( models.Model ):
return anonymized( self )
def __unicode__(self):
return '%s, %s' % ( self.user, self.text[:50] )
return '%s: %s' % ( self.user, self.text[:50] )
class Reply( models.Model ):
user = models.ForeignKey(User)
......@@ -59,7 +59,7 @@ class Reply( models.Model ):
return anonymized( self )
def __unicode__(self):
return '%s, %s' % ( self.user, self.text[:50] )
return '%s: %s' % ( self.user, self.text[:50] )
def anonymized( obj ):
......@@ -72,9 +72,6 @@ def anonymized( obj ):
noun_hash = int(str(n)[:4])*2 # 4 digits *2 allows for 20 000 nouns
adj_hash = int(str(n)[4:6])*8 # 2 digits *8 allows for 800 users
print noun_hash
print adj_hash
adj = "Anonymous"
adjs = open(os.path.join(settings.MEDIA_ROOT, 'adjectives'), 'r')
for i, line in enumerate(adjs):
......
......@@ -104,6 +104,7 @@ def feedback(request):
@login_required
def view_question(request, slug):
question = Question.objects.get(id=slug)
comments = Comment.objects.filter(parent__pk=slug)
current_user = User.objects.get(id=request.user.id)
......@@ -114,13 +115,31 @@ def view_question(request, slug):
reply_forms[comment] = ReplyForm(prefix=comment.pk)
if request.method == 'POST':
# parse the comment form
if "comment_sub" in request.POST:
# parse the comment form (Good Rating)
if "comment_sub_a" in request.POST:
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
question.rating = question.rating + 1
question.save()
comment = comment_form.save(commit=False)
comment.user = current_user
comment.parent = question
comment.save()
return redirect('view_question', slug)
# parse the comment form (Bad Rating)
elif "comment_sub_b" in request.POST:
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
question.rating = question.rating - 1
question.save()
comment = comment_form.save(commit=False)
comment.user = current_user
comment.parent = Question.objects.get(id=slug)
comment.parent = question
comment.save()
return redirect('view_question', slug)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment