]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/users.py
Added extra check to avoid empty tags been sent in notifications.
[osqa.git] / forum / views / users.py
index 9f039f790507516d0ddea0a7fe8119c29e995447..dc865a236ed3e8824903419c78b88fdb609ce9ba 100644 (file)
@@ -18,7 +18,7 @@ from forum.forms import *
 from forum.utils.html import sanitize_html\r
 from forum.modules import decorate, ReturnImediatelyException\r
 from datetime import datetime, date\r
-from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction, SuspendAction\r
+from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction, SuspendAction, ReportAction\r
 from forum.modules import ui\r
 from forum.utils import pagination\r
 from forum.views.readers import QuestionListPaginatorContext, AnswerPaginatorContext\r
@@ -33,13 +33,13 @@ class UserReputationSort(pagination.SimpleSort):
         return objects.order_by('-is_active', self.order_by)\r
 \r
 class UserListPaginatorContext(pagination.PaginatorContext):\r
-    def __init__(self, pagesizes=(20, 35, 60)):\r
+    def __init__(self, pagesizes=(20, 35, 60), default_pagesize=35):\r
         super (UserListPaginatorContext, self).__init__('USERS_LIST', sort_methods=(\r
             (_('reputation'), UserReputationSort(_('reputation'), '-reputation', _("sorted by reputation"))),\r
             (_('newest'), pagination.SimpleSort(_('recent'), '-date_joined', _("newest members"))),\r
             (_('last'), pagination.SimpleSort(_('oldest'), 'date_joined', _("oldest members"))),\r
             (_('name'), pagination.SimpleSort(_('by username'), 'username', _("sorted by username"))),\r
-        ), pagesizes=pagesizes)\r
+        ), pagesizes=pagesizes, default_pagesize=default_pagesize)\r
 \r
 class SubscriptionListPaginatorContext(pagination.PaginatorContext):\r
     def __init__(self):\r
@@ -131,7 +131,7 @@ def online_users(request):
     })\r
 \r
 \r
-def edit_user(request, id):\r
+def edit_user(request, id, slug):\r
     user = get_object_or_404(User, id=id)\r
     if not (request.user.is_superuser or request.user == user):\r
         return HttpResponseUnauthorized(request)\r
@@ -236,7 +236,7 @@ def suspend(request, id):
             return render_to_response('users/suspend_user.html')\r
 \r
     data = {\r
-        'bantype': request.POST.get('bantype', 'indefinetly').strip(),\r
+        'bantype': request.POST.get('bantype', 'Indefinitely').strip(),\r
         'publicmsg': request.POST.get('publicmsg', _('Bad behaviour')),\r
         'privatemsg': request.POST.get('privatemsg', None) or request.POST.get('publicmsg', ''),\r
         'suspended': user\r
@@ -252,6 +252,24 @@ def suspend(request, id):
 \r
     return decorators.RefreshPageCommand()\r
 \r
+@decorate.withfn(decorators.command)\r
+def report_user(request, id):\r
+    user = get_object_or_404(User, id=id)\r
+\r
+    if not request.POST.get('publicmsg', None):\r
+        return render_to_response('users/report_user.html')\r
+\r
+    data = {\r
+        'publicmsg': request.POST.get('publicmsg', _('N/A')),\r
+        'reported': user\r
+    }\r
+\r
+    ReportAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=data)\r
+\r
+\r
+    return decorators.RefreshPageCommand()\r
+\r
+\r
 \r
 def user_view(template, tab_name, tab_title, tab_description, private=False, tabbed=True, render_to=None, weight=500):\r
     def decorator(fn):\r
@@ -371,7 +389,7 @@ def user_reputation(request, user, **kwargs):
     redux = lambda x, y: x+y\r
 \r
     graph_data = simplejson.dumps([\r
-    (time.mktime(rep[i].date.timetuple()) * 1000, reduce(redux, values[:i], 0))\r
+    (time.mktime(rep[i].date.timetuple()) * 1000, reduce(redux, values[:i+1], 0))\r
     for i in range(len(values))\r
     ])\r
 \r
@@ -394,6 +412,9 @@ def user_favorites(request, user, **kwargs):
 \r
 @user_view('users/subscriptions.html', 'subscriptions', _('subscription'), _('subscriptions'), True, tabbed=False)\r
 def user_subscriptions(request, user, **kwargs):\r
+    return _user_subscriptions(request, user, **kwargs)\r
+\r
+def _user_subscriptions(request, user, **kwargs):\r
     enabled = True\r
 \r
     tab = request.GET.get('tab', "settings")\r