]> git.openstreetmap.org Git - osqa.git/commitdiff
Shows user diamonds in some missing spots, and adds some improvements to module decor...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 29 Jun 2010 18:07:00 +0000 (18:07 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 29 Jun 2010 18:07:00 +0000 (18:07 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@474 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/modules/decorators.py
forum/skins/default/media/js/osqa.main.js
forum/skins/default/templates/users/users.html
forum/views/commands.py
forum/views/decorators.py
forum/views/users.py

index 8fbee7e30d4b19c9475a77da0b682051e6753e86..48bee43ce5994032d3454e79090eafbc939ac039 100644 (file)
@@ -100,6 +100,8 @@ def decorate(origin, needs_origin=True, mode=DecoratableObject.MODE_OVERRIDE):
     def decorator(fn):\r
         return fn\r
 \r
+    return decorator\r
+\r
 \r
 def _decorate_params(origin):\r
     return decorate(origin, mode=DecoratableObject.MODE_PARAMS)\r
@@ -110,3 +112,18 @@ def _decorate_result(origin):
     return decorate(origin, mode=DecoratableObject.MODE_RESULT)\r
 \r
 decorate.result = _decorate_result\r
+\r
+def _decorate_with(fn):\r
+    def decorator(origin):\r
+        if not isinstance(origin, DecoratableObject):\r
+            mod = inspect.getmodule(origin)\r
+\r
+            name = origin.__name__\r
+            origin = DecoratableObject(origin)\r
+\r
+        origin._decorate(fn, True, False)\r
+        return origin\r
+    return decorator\r
+\r
+\r
+decorate.withfn = _decorate_with
\ No newline at end of file
index 39ddd3b13b830bd1860bbe56b283e77ce78e968e..270a6b4ab985a213e6bd9cca28816419d7dc6c6b 100644 (file)
@@ -229,12 +229,11 @@ function show_message(evt, msg, callback) {
     });\r
 }\r
 \r
-function load_prompt(evt, url) {\r
+function load_prompt(evt, el, url) {\r
     $.get(url, function(data) {\r
-        var $dialog = show_dialog({\r
-            html: data,\r
+        var doptions = {\r
+         html: data,\r
             extra_class: 'prompt',\r
-            event: evt,\r
             yes_callback: function() {\r
                 var postvars = {};\r
                 $dialog.find('input, textarea, select').each(function() {\r
@@ -248,7 +247,13 @@ function load_prompt(evt, url) {
                 }, 'json');\r
             },\r
             show_no: true\r
-        });\r
+        }\r
+\r
+        if (!el.is('.centered')) {\r
+            doptions.event = evt;\r
+        }\r
+\r
+        var $dialog = show_dialog(doptions);\r
     });\r
 }\r
 \r
@@ -297,12 +302,11 @@ $(function() {
         var el = $(this);\r
 \r
         if (el.is('.withprompt')) {\r
-            load_prompt(evt, el.attr('href'));\r
+            load_prompt(evt, el, el.attr('href'));\r
         } else if(el.is('.confirm')) {\r
-            $dialog = show_dialog({\r
+            var doptions = {\r
                 html: messages.confirm,\r
                 extra_class: 'confirm',\r
-                event: evt,\r
                 yes_callback: function() {\r
                     start_command();\r
                     $.getJSON(el.attr('href'), function(data) {\r
@@ -315,7 +319,12 @@ $(function() {
                 yes_text: messages.yes,\r
                 show_no: true,\r
                 no_text: messages.no\r
-            });\r
+            }\r
+\r
+            if (!el.is('.centered')) {\r
+                doptions.event = evt;\r
+            }\r
+            var $dialog = show_dialog(doptions);\r
         } else {\r
             start_command();\r
             $.getJSON(el.attr('href'), function(data) {\r
index 38f060e257413fd3a329e68a33fb425389770e91..2f08693fdc9e5348944f2300bf933c300e10df35 100644 (file)
@@ -47,7 +47,7 @@
                     <div class="user">
                         <ul>
                             <li class="thumb"><a href="{{ user.get_profile_url }} ">{% gravatar user 32 %}</a></li>
-                            <li><a {% if user.is_suspended %}class="suspended-user" {% endif %}href="{{ user.get_profile_url }}">{{ user.username }}</a></li>
+                            <li><a {% if user.is_suspended %}class="suspended-user" {% endif %}href="{{ user.get_profile_url }}">{{ user.decorated_name }}</a></li>
                             <li>{% get_score_badge user %}</li>
                         </ul>
                     </div>
index a8f6d426fe28b3592f465c9ec6c788e2e6b6d607..ed72bd1058d7799afd96cb0271cea7e9fd0b68e2 100644 (file)
@@ -13,6 +13,7 @@ from django.core.urlresolvers import reverse
 from django.contrib.auth.decorators import login_required
 from forum.utils.decorators import ajax_method, ajax_login_required
 from decorators import command, CommandException, RefreshPageCommand
+from forum.modules import decorate
 from forum import settings
 import logging
 
@@ -57,7 +58,7 @@ class CannotDoubleActionException(CommandException):
                 )
 
 
-@command
+@decorate.withfn(command)
 def vote_post(request, id, vote_type):
     post = get_object_or_404(Node, id=id).leaf
     user = request.user
@@ -113,7 +114,7 @@ def vote_post(request, id, vote_type):
 
     return response
 
-@command
+@decorate.withfn(command)
 def flag_post(request, id):
     if not request.POST:
         return render_to_response('node/report.html', {'types': settings.FLAG_TYPES})
@@ -149,7 +150,7 @@ def flag_post(request, id):
 
     return {'message': _("Thank you for your report. A moderator will review your submission shortly.")}
 
-@command
+@decorate.withfn(command)
 def like_comment(request, id):
     comment = get_object_or_404(Comment, id=id)
     user = request.user
@@ -179,7 +180,7 @@ def like_comment(request, id):
     }
     }
 
-@command
+@decorate.withfn(command)
 def delete_comment(request, id):
     comment = get_object_or_404(Comment, id=id)
     user = request.user
@@ -199,7 +200,7 @@ def delete_comment(request, id):
     }
     }
 
-@command
+@decorate.withfn(command)
 def mark_favorite(request, id):
     question = get_object_or_404(Question, id=id)
 
@@ -221,7 +222,7 @@ def mark_favorite(request, id):
     }
     }
 
-@command
+@decorate.withfn(command)
 def comment(request, id):
     post = get_object_or_404(Node, id=id)
     user = request.user
@@ -262,7 +263,7 @@ def comment(request, id):
         return {
         'commands': {
         'insert_comment': [
-                id, comment.id, comment.comment, user.username, user.get_profile_url(),
+                id, comment.id, comment.comment, user.decorated_name, user.get_profile_url(),
                 reverse('delete_comment', kwargs={'id': comment.id}),
                 reverse('node_markdown', kwargs={'id': comment.id})
                 ]
@@ -275,7 +276,7 @@ def comment(request, id):
         }
         }
 
-@command
+@decorate.withfn(command)
 def node_markdown(request, id):
     user = request.user
 
@@ -286,7 +287,7 @@ def node_markdown(request, id):
     return HttpResponse(node.body, mimetype="text/plain")
 
 
-@command
+@decorate.withfn(command)
 def accept_answer(request, id):
     user = request.user
 
@@ -316,7 +317,7 @@ def accept_answer(request, id):
 
     return {'commands': commands}
 
-@command
+@decorate.withfn(command)
 def delete_post(request, id):
     post = get_object_or_404(Node, id=id)
     user = request.user
@@ -339,7 +340,7 @@ def delete_post(request, id):
 
     return ret
 
-@command
+@decorate.withfn(command)
 def close(request, id, close):
     if close and not request.POST:
         return render_to_response('node/report.html', {'types': settings.CLOSE_TYPES})
@@ -368,7 +369,7 @@ def close(request, id, close):
 
     return RefreshPageCommand()
 
-@command
+@decorate.withfn(command)
 def wikify(request, id):
     node = get_object_or_404(Node, id=id)
     user = request.user
@@ -392,7 +393,7 @@ def wikify(request, id):
 
     return RefreshPageCommand()
 
-@command
+@decorate.withfn(command)
 def convert_to_comment(request, id):
     user = request.user
     answer = get_object_or_404(Answer, id=id)
@@ -425,7 +426,7 @@ def convert_to_comment(request, id):
 
     return RefreshPageCommand()
 
-@command
+@decorate.withfn(command)
 def subscribe(request, id):
     question = get_object_or_404(Question, id=id)
 
index 4eb832a4ab1ea7d6e03c796bcf9d149eeaead29b..a98f1be2902c48dfc9381192e2da6fed262820ae 100644 (file)
@@ -5,7 +5,7 @@ from django.shortcuts import render_to_response
 from django.core.urlresolvers import reverse\r
 from django.template import RequestContext\r
 from django.utils.translation import ungettext, ugettext as _\r
-from forum.modules import ui\r
+from forum.modules import ui, decorate\r
 import logging\r
 \r
 def render(template=None, tab=None, tab_title='', weight=500, tabbed=True):\r
@@ -87,35 +87,33 @@ class RefreshPageCommand(HttpResponse):
                 content=simplejson.dumps({'commands': {'refresh_page': []}, 'success': True}),\r
                 mimetype="application/json")\r
 \r
-def command(func):\r
-    def decorated(request, *args, **kwargs):\r
-        try:\r
-            response = func(request, *args, **kwargs)\r
-\r
-            if isinstance(response, HttpResponse):\r
-                return response\r
-\r
-            response['success'] = True\r
-        except Exception, e:\r
-            import traceback\r
-            #traceback.print_exc()\r
-\r
-            if isinstance(e, CommandException):\r
-                response = {\r
-                'success': False,\r
-                'error_message': e.message\r
-                }\r
-            else:\r
-                logging.error("%s: %s" % (func.__name__, str(e)))\r
-                logging.error(traceback.format_exc())\r
-                response = {\r
-                'success': False,\r
-                'error_message': _("We're sorry, but an unknown error ocurred.<br />Please try again in a while.")\r
-                }\r
-\r
-        if request.is_ajax():\r
-            return HttpResponse(simplejson.dumps(response), mimetype="application/json")\r
+def command(func, request, *args, **kwargs):\r
+    try:\r
+        response = func(request, *args, **kwargs)\r
+\r
+        if isinstance(response, HttpResponse):\r
+            return response\r
+\r
+        response['success'] = True\r
+    except Exception, e:\r
+        import traceback\r
+        #traceback.print_exc()\r
+\r
+        if isinstance(e, CommandException):\r
+            response = {\r
+            'success': False,\r
+            'error_message': e.message\r
+            }\r
         else:\r
-            return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))\r
+            logging.error("%s: %s" % (func.__name__, str(e)))\r
+            logging.error(traceback.format_exc())\r
+            response = {\r
+            'success': False,\r
+            'error_message': _("We're sorry, but an unknown error ocurred.<br />Please try again in a while.")\r
+            }\r
+\r
+    if request.is_ajax():\r
+        return HttpResponse(simplejson.dumps(response), mimetype="application/json")\r
+    else:\r
+        return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))\r
 \r
-    return decorated
\ No newline at end of file
index dee69cd839a458fe37d9c86f7e61177b230fcebf..dd31abb7fadf569f936abdc2fc73dbb78199edf2 100644 (file)
@@ -16,6 +16,7 @@ from django.utils import simplejson
 from django.core.urlresolvers import reverse, NoReverseMatch\r
 from forum.forms import *\r
 from forum.utils.html import sanitize_html\r
+from forum.modules import decorate\r
 from datetime import datetime, date\r
 import decorators\r
 from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction, SuspendAction\r
@@ -133,7 +134,7 @@ def user_powers(request, id, action, status):
     return HttpResponseRedirect(user.get_profile_url())\r
 \r
 \r
-@decorators.command\r
+@decorate.withfn(decorators.command)\r
 def award_points(request, id):\r
     if (not request.POST) and request.POST.get('points', None):\r
         raise decorators.CommandException(_("Invalid request type"))\r
@@ -151,7 +152,7 @@ def award_points(request, id):
     return dict(reputation=user.reputation)\r
 \r
 \r
-@decorators.command\r
+@decorate.withfn(decorators.command)\r
 def suspend(request, id):\r
     user = get_object_or_404(User, id=id)\r
 \r