if not created:\r
return\r
\r
- post = instance.content_object\r
+ post = instance.content_object.leaf\r
question = (post.__class__ == Question) and post or post.question\r
\r
- user.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question,\r
+ post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question,\r
reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED)\r
\r
\r
\r
def on_vote(instance, created, **kwargs):\r
if created and not instance.content_object.wiki:\r
- post = instance.content_object\r
+ post = instance.content_object.leaf\r
question = (post.__class__ == Question) and post or post.question\r
\r
if instance.vote == -1:\r
\r
def on_vote_canceled(instance, **kwargs):\r
if not instance.content_object.wiki:\r
- post = instance.content_object\r
+ post = instance.content_object.leaf\r
question = (post.__class__ == Question) and post or post.question\r
\r
if instance.vote == -1:\r
controls.append(post_control(_('close'), reverse('close', kwargs={'id': post.id})))\r
\r
if user.can_flag_offensive(post):\r
- controls.append(post_control(_('flag'), reverse('flag_post', kwargs={'post_type': post_type, 'id': post.id}), \r
+ label = _('flag')\r
+ \r
+ if user.can_view_offensive_flags(post):\r
+ label = "%s (%d)" % (label, post.flaggeditems.count())\r
+\r
+ controls.append(post_control(label, reverse('flag_post', kwargs={'id': post.id}),\r
command=True, title=_("report as offensive (i.e containing spam, advertising, malicious text, etc.)")))\r
\r
if user.can_delete_post(post):\r
- controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'post_type': post_type, 'id': post.id}),\r
+ controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'id': post.id}),\r
command=True))\r
\r
return {'controls': controls}\r
url(r'^%s(?P<id>\d+)/$' % _('delete_comment/'), app.commands.delete_comment, name="delete_comment"),
url(r'^%s(?P<id>\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer"),
url(r'^%s(?P<id>\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite"),
- url(r'^%s(?P<post_type>[a-z]+)/(?P<id>\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'),
- url(r'^%s(?P<post_type>[a-z]+)/(?P<id>\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'),
+ url(r'^%s(?P<id>\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'),
+ url(r'^%s(?P<id>\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'),
url(r'^%s(?P<id>\d+)/$' % _('subscribe/'), app.commands.subscribe, name="subscribe"),
url(r'^%s(?P<id>\d+)/%s$' % (_('questions/'), _('revisions/')), app.readers.revisions, name='question_revisions'),
return response
@command
-def flag_post(request, post_type, id):
- post = get_object_or_404(post_type == "question" and Question or Answer, id=id)
+def flag_post(request, id):
+ post = get_object_or_404(Node, id=id)
user = request.user
if not user.is_authenticated():
raise NotEnoughLeftException(_('flags'), str(settings.MAX_FLAGS_PER_DAY))
try:
- post.flagged_items.get(user=user)
+ post.flaggeditems.get(user=user)
raise CannotDoubleActionException(_('flag'))
except ObjectDoesNotExist:
- #there is no vote yet
flag = FlaggedItem(user=user, content_object=post)
flag.save()
- response = {
-
- }
-
- return response
+ return {}
@command
def like_comment(request, id):
return {'commands': commands}
@command
-def delete_post(request, post_type, id):
- post = get_object_or_404(post_type == "question" and Question or Answer, id=id)
+def delete_post(request, id):
+ post = get_object_or_404(Node, id=id)
user = request.user
if not user.is_authenticated():
return {
'commands': {
- 'mark_deleted': [post_type, id]
+ 'mark_deleted': [post.node_type, id]
}
}
response = func(request, *args, **kwargs)\r
response['success'] = True\r
except Exception, e:\r
- #import sys, traceback\r
- #traceback.print_exc(file=sys.stdout)\r
+ import sys, traceback\r
+ traceback.print_exc(file=sys.stdout)\r
\r
response = {\r
'success': False,\r