]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/users.py
Removes a few remaining usages of old django decorators and replace them by OSQA...
[osqa.git] / forum / views / users.py
index 836b62172ef5829f07aff78931221290eb4e1b3f..d95b3027259624e2ff4d95560d3aaea95f1358a0 100644 (file)
@@ -1,4 +1,3 @@
-from django.contrib.auth.decorators import login_required\r
 from forum.models import User\r
 from django.db.models import Q, Count\r
 from django.core.paginator import Paginator, EmptyPage, InvalidPage\r
 from forum.models import User\r
 from django.db.models import Q, Count\r
 from django.core.paginator import Paginator, EmptyPage, InvalidPage\r
@@ -26,6 +25,7 @@ from forum.views.readers import QuestionListPaginatorContext, AnswerPaginatorCon
 import time\r
 import datetime\r
 import decorators\r
 import time\r
 import datetime\r
 import decorators\r
+import unicodedata\r
 \r
 class UserReputationSort(pagination.SimpleSort):\r
     def apply(self, objects):\r
 \r
 class UserReputationSort(pagination.SimpleSort):\r
     def apply(self, objects):\r
@@ -82,7 +82,6 @@ def online_users(request):
     })\r
 \r
 \r
     })\r
 \r
 \r
-@login_required\r
 def edit_user(request, id):\r
     user = get_object_or_404(User, id=id)\r
     if not (request.user.is_superuser or request.user == user):\r
 def edit_user(request, id):\r
     user = get_object_or_404(User, id=id)\r
     if not (request.user.is_superuser or request.user == user):\r
@@ -320,51 +319,68 @@ def user_favorites(request, user):
 @user_view('users/subscriptions.html', 'subscriptions', _('subscription'), _('subscriptions'), True, tabbed=False)\r
 def user_subscriptions(request, user):\r
     enabled = user.subscription_settings.enable_notifications\r
 @user_view('users/subscriptions.html', 'subscriptions', _('subscription'), _('subscriptions'), True, tabbed=False)\r
 def user_subscriptions(request, user):\r
     enabled = user.subscription_settings.enable_notifications\r
-    auto = request.GET.get('auto', 'True')\r
-    show_auto = True\r
-    manage_open = False\r
-    \r
-    if len(request.GET) > 0:\r
-        manage_open = True\r
-        \r
-    if auto == 'True':\r
-        show_auto = True\r
-        subscriptions = user.subscriptions.all().order_by('-questionsubscription__last_view')\r
-    else:\r
-        show_auto = False\r
-        subscriptions = user.subscriptions.filter(questionsubscription__auto_subscription=False).order_by('-questionsubscription__last_view')\r
 \r
 \r
-    if request.method == 'POST':\r
+    tab = request.GET.get('tab', "settings")\r
+\r
+    if tab == 'settings':\r
         manage_open = False\r
         manage_open = False\r
-        form = SubscriptionSettingsForm(data=request.POST, instance=user.subscription_settings)\r
+        if request.method == 'POST':\r
+            manage_open = False\r
+            form = SubscriptionSettingsForm(data=request.POST, instance=user.subscription_settings)\r
+\r
+            if form.is_valid():\r
+                form.save()\r
+                message = _('New subscription settings are now saved')\r
+\r
+                if 'notswitch' in request.POST:\r
+                    enabled = not enabled\r
+\r
+                    if enabled:\r
+                        message = _('Notifications are now enabled')\r
+                    else:\r
+                        message = _('Notifications are now disabled')\r
+\r
+                user.subscription_settings.enable_notifications = enabled\r
+                user.subscription_settings.save()\r
+\r
+                request.user.message_set.create(message=message)\r
+        else:\r
+            form = SubscriptionSettingsForm(instance=user.subscription_settings)\r
+\r
+        return {\r
+            'view_user':user,\r
+            'notificatons_on': enabled,\r
+            'form':form,\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
-        if form.is_valid():\r
-            form.save()\r
-            message = _('New subscription settings are now saved')\r
 \r
 \r
-            if 'notswitch' in request.POST:\r
-                enabled = not enabled\r
 \r
 \r
-                if enabled:\r
-                    message = _('Notifications are now enabled')\r
-                else:\r
-                    message = _('Notifications are now disabled')\r
 \r
 \r
-            user.subscription_settings.enable_notifications = enabled\r
-            user.subscription_settings.save()\r
 \r
 \r
-            request.user.message_set.create(message=message)\r
-    else:\r
-        form = SubscriptionSettingsForm(instance=user.subscription_settings)\r
-\r
-    return pagination.paginated(request, ('subscriptions', SubscriptionListPaginatorContext()), {\r
-        'subscriptions':subscriptions,\r
-        'view_user':user,\r
-        'notificatons_on': enabled,\r
-        'form':form,\r
-        "auto":show_auto,\r
-        "manage_open":manage_open\r
-    })\r
 \r
 @user_view('users/preferences.html', 'preferences', _('preferences'), _('preferences'), True, tabbed=False)\r
 def user_preferences(request, user):\r
 \r
 @user_view('users/preferences.html', 'preferences', _('preferences'), _('preferences'), True, tabbed=False)\r
 def user_preferences(request, user):\r
@@ -385,13 +401,4 @@ def user_preferences(request, user):
             \r
     return {'view_user': user, 'form': form}\r
 \r
             \r
     return {'view_user': user, 'form': form}\r
 \r
-@login_required\r
-def account_settings(request):\r
-    logging.debug('')\r
-    msg = request.GET.get('msg', '')\r
-    is_openid = False\r
 \r
 \r
-    return render_to_response('account_settings.html', {\r
-    'msg': msg,\r
-    'is_openid': is_openid\r
-    }, context_instance=RequestContext(request))\r