]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/users.py
make user subscriptions view decoratable
[osqa.git] / forum / views / users.py
index 82e817560cfbc9b3b053b847752c7394e1e8399e..84f1cdf2ad222e182161a658a620d8f01953cc46 100644 (file)
@@ -33,13 +33,13 @@ class UserReputationSort(pagination.SimpleSort):
         return objects.order_by('-is_active', self.order_by)\r
 \r
 class UserListPaginatorContext(pagination.PaginatorContext):\r
         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
         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
 \r
 class SubscriptionListPaginatorContext(pagination.PaginatorContext):\r
     def __init__(self):\r
@@ -131,7 +131,7 @@ def online_users(request):
     })\r
 \r
 \r
     })\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
     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
             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
         'publicmsg': request.POST.get('publicmsg', _('Bad behaviour')),\r
         'privatemsg': request.POST.get('privatemsg', None) or request.POST.get('publicmsg', ''),\r
         'suspended': user\r
@@ -371,7 +371,7 @@ def user_reputation(request, user, **kwargs):
     redux = lambda x, y: x+y\r
 \r
     graph_data = simplejson.dumps([\r
     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
     for i in range(len(values))\r
     ])\r
 \r
@@ -394,11 +394,33 @@ 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
 \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
 \r
     enabled = True\r
 \r
     tab = request.GET.get('tab', "settings")\r
 \r
-    if tab == 'settings':\r
+    # Manage tab\r
+    if tab == 'manage':\r
+        manage_open = True\r
+\r
+        auto = request.GET.get('auto', 'True')\r
+        if auto == 'True':\r
+            show_auto = True\r
+            subscriptions = QuestionSubscription.objects.filter(user=user).order_by('-last_view')\r
+        else:\r
+            show_auto = False\r
+            subscriptions = QuestionSubscription.objects.filter(user=user, auto_subscription=False).order_by('-last_view')\r
+\r
+        return pagination.paginated(request, ('subscriptions', SubscriptionListPaginatorContext()), {\r
+            'subscriptions':subscriptions,\r
+            'view_user':user,\r
+            "auto":show_auto,\r
+            'manage_open':manage_open,\r
+        })\r
+    # Settings Tab and everything else\r
+    else:\r
         manage_open = False\r
         if request.method == 'POST':\r
             manage_open = False\r
         manage_open = False\r
         if request.method == 'POST':\r
             manage_open = False\r
@@ -422,34 +444,6 @@ def user_subscriptions(request, user, **kwargs):
             'manage_open':manage_open,\r
         }\r
 \r
             'manage_open':manage_open,\r
         }\r
 \r
-    elif tab == 'manage':\r
-        manage_open = True\r
-\r
-        auto = request.GET.get('auto', 'True')\r
-        if auto == 'True':\r
-            show_auto = True\r
-            subscriptions = QuestionSubscription.objects.filter(user=user).order_by('-last_view')\r
-        else:\r
-            show_auto = False\r
-            subscriptions = QuestionSubscription.objects.filter(user=user, auto_subscription=False).order_by('-last_view')\r
-\r
-        return pagination.paginated(request, ('subscriptions', SubscriptionListPaginatorContext()), {\r
-            'subscriptions':subscriptions,\r
-            'view_user':user,\r
-            "auto":show_auto,\r
-            'manage_open':manage_open,\r
-        })\r
-\r
-    # else:\r
-        # todo: probably want to throw an error\r
-        # error = "error to throw"\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
 @user_view('users/preferences.html', 'preferences', _('preferences'), _('preferences'), True, tabbed=False)\r
 def user_preferences(request, user, **kwargs):\r
     if request.POST:\r
 @user_view('users/preferences.html', 'preferences', _('preferences'), _('preferences'), True, tabbed=False)\r
 def user_preferences(request, user, **kwargs):\r
     if request.POST:\r