From: hernani Date: Thu, 15 Apr 2010 23:46:20 +0000 (+0000) Subject: fix in flag and delete commands, and added the possibility for admins and post author... X-Git-Tag: live~1038 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/4e4b0b571da8e2156d8174e41ed79c0ecb0c0e7f fix in flag and delete commands, and added the possibility for admins and post authors to see the flag count on posts git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@36 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/reputation.py b/forum/reputation.py index 7bca665..fd5ce63 100644 --- a/forum/reputation.py +++ b/forum/reputation.py @@ -9,10 +9,10 @@ def on_flagged_item(instance, created, **kwargs): if not created: return - post = instance.content_object + post = instance.content_object.leaf question = (post.__class__ == Question) and post or post.question - user.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question, + post.author.reputes.create(value=-int(settings.REP_LOST_BY_FLAGGED), question=question, reputation_type=TYPE_REPUTATION_LOST_BY_FLAGGED) @@ -50,7 +50,7 @@ post_save.connect(on_answer_accepted_switch, sender=Answer) def on_vote(instance, created, **kwargs): if created and not instance.content_object.wiki: - post = instance.content_object + post = instance.content_object.leaf question = (post.__class__ == Question) and post or post.question if instance.vote == -1: @@ -71,7 +71,7 @@ post_save.connect(on_vote, sender=Vote) def on_vote_canceled(instance, **kwargs): if not instance.content_object.wiki: - post = instance.content_object + post = instance.content_object.leaf question = (post.__class__ == Question) and post or post.question if instance.vote == -1: diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index aa82c39..4b48f2e 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -69,11 +69,16 @@ def post_controls(post, user): controls.append(post_control(_('close'), reverse('close', kwargs={'id': post.id}))) if user.can_flag_offensive(post): - controls.append(post_control(_('flag'), reverse('flag_post', kwargs={'post_type': post_type, 'id': post.id}), + label = _('flag') + + if user.can_view_offensive_flags(post): + label = "%s (%d)" % (label, post.flaggeditems.count()) + + controls.append(post_control(label, reverse('flag_post', kwargs={'id': post.id}), command=True, title=_("report as offensive (i.e containing spam, advertising, malicious text, etc.)"))) if user.can_delete_post(post): - controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'post_type': post_type, 'id': post.id}), + controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'id': post.id}), command=True)) return {'controls': controls} diff --git a/forum/urls.py b/forum/urls.py index 653c6a7..3b9ce76 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -53,8 +53,8 @@ urlpatterns = patterns('', url(r'^%s(?P\d+)/$' % _('delete_comment/'), app.commands.delete_comment, name="delete_comment"), url(r'^%s(?P\d+)/$' % _('accept_answer/'), app.commands.accept_answer, name="accept_answer"), url(r'^%s(?P\d+)/$' % _('mark_favorite/'), app.commands.mark_favorite, name="mark_favorite"), - url(r'^%s(?P[a-z]+)/(?P\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'), - url(r'^%s(?P[a-z]+)/(?P\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'), + url(r'^%s(?P\d+)/' % _('flag/'), app.commands.flag_post, name='flag_post'), + url(r'^%s(?P\d+)/' % _('delete/'), app.commands.delete_post, name='delete_post'), url(r'^%s(?P\d+)/$' % _('subscribe/'), app.commands.subscribe, name="subscribe"), url(r'^%s(?P\d+)/%s$' % (_('questions/'), _('revisions/')), app.readers.revisions, name='question_revisions'), diff --git a/forum/views/commands.py b/forum/views/commands.py index da8f2c0..794ed49 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -113,8 +113,8 @@ def vote_post(request, id, vote_type): 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(): @@ -132,18 +132,13 @@ def flag_post(request, post_type, id): 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): @@ -297,8 +292,8 @@ def accept_answer(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(): @@ -311,7 +306,7 @@ def delete_post(request, post_type, id): return { 'commands': { - 'mark_deleted': [post_type, id] + 'mark_deleted': [post.node_type, id] } } diff --git a/forum/views/decorators.py b/forum/views/decorators.py index cf5f903..da51e1a 100644 --- a/forum/views/decorators.py +++ b/forum/views/decorators.py @@ -61,8 +61,8 @@ def command(func): response = func(request, *args, **kwargs) response['success'] = True except Exception, e: - #import sys, traceback - #traceback.print_exc(file=sys.stdout) + import sys, traceback + traceback.print_exc(file=sys.stdout) response = { 'success': False,