]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/users.py
Adds a user preferences page. Not much to see yet, only the preference to make sorts...
[osqa.git] / forum / views / users.py
index 8bea106278d27ffd89bf0fcf230f112dd6f4f528..7cb32249a907fda1cf5b0d3c368421cbae6d0d12 100644 (file)
@@ -46,7 +46,7 @@ class UserAnswersPaginatorContext(pagination.PaginatorContext):
             (_('oldest'), pagination.SimpleSort(_('oldest answers'), 'added_at', _("oldest answers will be shown first"))),\r
             (_('newest'), pagination.SimpleSort(_('newest answers'), '-added_at', _("newest answers will be shown first"))),\r
             (_('votes'), pagination.SimpleSort(_('popular answers'), '-score', _("most voted answers will be shown first"))),\r
-        ), default_sort=_('votes'), sticky_sort = True, pagesizes=(5, 10, 20), default_pagesize=20, prefix=_('answers'))\r
+        ), default_sort=_('votes'), pagesizes=(5, 10, 20), default_pagesize=20, prefix=_('answers'))\r
 \r
 USERS_PAGE_SIZE = 35# refactor - move to some constants file\r
 \r
@@ -55,7 +55,7 @@ def users(request):
     suser = request.REQUEST.get('q', "")\r
     users = User.objects.all()\r
 \r
-    if suser == "":\r
+    if suser != "":\r
         users = users.filter(username__icontains=suser)\r
 \r
     return pagination.paginated(request, ('users', UserListPaginatorContext()), {\r
@@ -321,6 +321,25 @@ def user_subscriptions(request, user):
 \r
     return {'view_user':user, 'notificatons_on': enabled, 'form':form}\r
 \r
+@user_view('users/preferences.html', 'preferences', _('preferences'), _('preferences'), True, tabbed=False)\r
+def user_preferences(request, user):\r
+    if request.POST:\r
+        form = UserPreferencesForm(request.POST)\r
+\r
+        if form.is_valid():\r
+            user.prop.preferences = form.cleaned_data\r
+            request.user.message_set.create(message=_('New preferences saved'))\r
+\r
+    else:\r
+        preferences = user.prop.preferences\r
+\r
+        if preferences:\r
+            form = UserPreferencesForm(initial=preferences)\r
+        else:\r
+            form = UserPreferencesForm()\r
+            \r
+    return {'view_user': user, 'form': form}\r
+\r
 @login_required\r
 def account_settings(request):\r
     logging.debug('')\r