]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/users.py
Adds a couple of options to manage the "accepting answers" workflow.
[osqa.git] / forum / views / users.py
index fa575421d71acc9942ff6f751aae2e19c52569a8..306747a6d746570ccaa117d45fbc8f8c20b4cb84 100644 (file)
@@ -22,6 +22,7 @@ import decorators
 from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction, SuspendAction\r
 from forum.modules import ui\r
 from forum.utils import pagination\r
+from forum.views.readers import QuestionListPaginatorContext, AnswerPaginatorContext\r
 \r
 import time\r
 import decorators\r
@@ -39,6 +40,14 @@ class UserListPaginatorContext(pagination.PaginatorContext):
             (_('name'), pagination.SimpleSort(_('by username'), 'username', _("sorted by username"))),\r
         ), pagesizes=(20, 35, 60))\r
 \r
+class UserAnswersPaginatorContext(pagination.PaginatorContext):\r
+    def __init__(self):\r
+        super (UserAnswersPaginatorContext, self).__init__('USER_ANSWER_LIST', sort_methods=(\r
+            (_('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'), pagesizes=(5, 10, 20), default_pagesize=20, prefix=_('answers'))\r
+\r
 USERS_PAGE_SIZE = 35# refactor - move to some constants file\r
 \r
 @decorators.render('users/users.html', 'users', _('users'), weight=200)\r
@@ -46,10 +55,10 @@ 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
+    return pagination.paginated(request, ('users', UserListPaginatorContext()), {\r
         "users" : users,\r
         "suser" : suser,\r
     })\r
@@ -69,6 +78,12 @@ def edit_user(request, id):
                 user.email = new_email\r
                 user.email_isvalid = False\r
 \r
+                try:\r
+                    hash = ValidationHash.objects.get(user=request.user, type='email')\r
+                    hash.delete()\r
+                except:\r
+                    pass\r
+\r
             if settings.EDITABLE_SCREEN_NAME:\r
                 user.username = sanitize_html(form.cleaned_data['username'])\r
             user.real_name = sanitize_html(form.cleaned_data['realname'])\r
@@ -231,7 +246,9 @@ def user_profile(request, user):
     awards = [(Badge.objects.get(id=b['id']), b['count']) for b in\r
               Badge.objects.filter(awards__user=user).values('id').annotate(count=Count('cls')).order_by('-count')]\r
 \r
-    return {\r
+    return pagination.paginated(request, (\r
+    ('questions', QuestionListPaginatorContext('USER_QUESTION_LIST', _('questions'), 15)),\r
+    ('answers', UserAnswersPaginatorContext())), {\r
     "view_user" : user,\r
     "questions" : questions,\r
     "answers" : answers,\r
@@ -243,7 +260,7 @@ def user_profile(request, user):
     "user_tags" : user_tags[:50],\r
     "awards": awards,\r
     "total_awards" : len(awards),\r
-    }\r
+    })\r
     \r
 @user_view('users/recent.html', 'recent', _('recent activity'), _('recent user activity'))\r
 def user_recent(request, user):\r
@@ -310,6 +327,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