]> git.openstreetmap.org Git - osqa.git/commitdiff
fix in flag and delete commands, and added the possibility for admins and post author...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 15 Apr 2010 23:46:20 +0000 (23:46 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Thu, 15 Apr 2010 23:46:20 +0000 (23:46 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@36 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/reputation.py
forum/templatetags/node_tags.py
forum/urls.py
forum/views/commands.py
forum/views/decorators.py

index 7bca6659c97bee1062aea462d235da748aea2ba0..fd5ce633363ffc269b0b676cb31fc7f706dcd525 100644 (file)
@@ -9,10 +9,10 @@ def on_flagged_item(instance, created, **kwargs):
     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
@@ -50,7 +50,7 @@ post_save.connect(on_answer_accepted_switch, sender=Answer)
 \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
@@ -71,7 +71,7 @@ post_save.connect(on_vote, sender=Vote)
 \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
index aa82c3953b5fa02e3c7c34e1654a44117b03b4d1..4b48f2e7807ece0f38ff4b46f69ae64de7b5ecdf 100644 (file)
@@ -69,11 +69,16 @@ def post_controls(post, user):
                 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
index 653c6a7df274271600dca581b2024174b0c60cb3..3b9ce76451b6f4397269be9ce46dfa24a6a6f748 100644 (file)
@@ -53,8 +53,8 @@ urlpatterns = patterns('',
     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'),
index da8f2c0c3679eac18788af71ca74233d47f263b4..794ed49786fadbc63aeb8b1385e04b5a7039d79f 100644 (file)
@@ -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]
             }
     }
 
index cf5f90373288f5b5a7e45dca546a1bb88e0b4e67..da51e1a5b9247a8ab4ff3a9e14871fdfdb9b5b74 100644 (file)
@@ -61,8 +61,8 @@ def command(func):
             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