]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/views/users.py
Adds custom header and footer, and a preview mechanism.
[osqa.git] / forum / views / users.py
index 55a16099693250b4810c6e74a7f76f1da0b5e6f6..da556be2654706cf0124786f99bd6b7663142f7e 100644 (file)
@@ -15,7 +15,7 @@ from django.utils import simplejson
 from django.core.urlresolvers import reverse\r
 from forum.forms import *\r
 from forum.utils.html import sanitize_html\r
-from datetime import date\r
+from datetime import datetime, date\r
 import decorators\r
 from forum.actions import EditProfileAction, FavoriteAction, BonusRepAction\r
 \r
@@ -96,9 +96,9 @@ def edit_user(request, id):
             user.real_name = sanitize_html(form.cleaned_data['realname'])\r
             user.website = sanitize_html(form.cleaned_data['website'])\r
             user.location = sanitize_html(form.cleaned_data['city'])\r
-            user.date_of_birth = sanitize_html(form.cleaned_data['birthday'])\r
+            user.date_of_birth = form.cleaned_data['birthday']\r
             if user.date_of_birth == "None":\r
-                user.date_of_birth = '1900-01-01'\r
+                user.date_of_birth = datetime(1900, 1, 1, 0, 0)\r
             user.about = sanitize_html(form.cleaned_data['about'])\r
 \r
             user.save()\r
@@ -174,8 +174,8 @@ def user_view(template, tab_name, tab_description, page_title, private=False):
 \r
 @user_view('users/stats.html', 'stats', _('user profile'), _('user overview'))\r
 def user_stats(request, user):\r
-    questions = Question.objects.filter(author=user, deleted=None).order_by('-added_at')\r
-    answers = Answer.objects.filter(author=user, deleted=None).order_by('-added_at')\r
+    questions = Question.objects.filter_state(deleted=False).filter(author=user).order_by('-added_at')\r
+    answers = Answer.objects.filter_state(deleted=False).filter(author=user).order_by('-added_at')\r
 \r
     up_votes = user.vote_up_count\r
     down_votes = user.vote_down_count\r
@@ -204,14 +204,14 @@ def user_stats(request, user):
 \r
 @user_view('users/recent.html', 'recent', _('recent user activity'), _('recent activity'))\r
 def user_recent(request, user):\r
-    activities = user.actions.exclude(action_type__in=("voteup", "votedown", "voteupcomment", "flag")).order_by('-action_date')[:USERS_PAGE_SIZE]\r
+    activities = user.actions.exclude(action_type__in=("voteup", "votedown", "voteupcomment", "flag", "newpage", "editpage")).order_by('-action_date')[:USERS_PAGE_SIZE]\r
 \r
     return {"view_user" : user, "activities" : activities}\r
 \r
 \r
 @user_view('users/votes.html', 'votes', _('user vote record'), _('votes'), True)\r
 def user_votes(request, user):\r
-    votes = user.votes.filter(node__deleted=None, node__node_type__in=("question", "answer")).order_by('-voted_at')[:USERS_PAGE_SIZE]\r
+    votes = user.votes.exclude(node__state_string__contains="(deleted").filter(node__node_type__in=("question", "answer")).order_by('-voted_at')[:USERS_PAGE_SIZE]\r
 \r
     return {"view_user" : user, "votes" : votes}\r
 \r
@@ -233,7 +233,7 @@ def user_reputation(request, user):
 \r
 @user_view('users/questions.html', 'favorites', _('favorite questions'),  _('favorite questions'))\r
 def user_favorites(request, user):\r
-    favorites = FavoriteAction.objects.filter(user=user)\r
+    favorites = FavoriteAction.objects.filter(canceled=False, user=user)\r
 \r
     return {"favorites" : favorites, "view_user" : user}\r
 \r
@@ -250,13 +250,13 @@ def user_subscriptions(request, user):
                 request.user.message_set.create(message=_('Notifications are now enabled'))\r
             else:\r
                 request.user.message_set.create(message=_('Notifications are now disabled'))\r
-        else:\r
-            form.is_valid()\r
-            for k,v in form.cleaned_data.items():\r
-                setattr(user.subscription_settings, k, v)\r
 \r
-            user.subscription_settings.save()\r
-            request.user.message_set.create(message=_('New subscription settings are now saved'))\r
+        form.is_valid()\r
+        for k,v in form.cleaned_data.items():\r
+            setattr(user.subscription_settings, k, v)\r
+\r
+        user.subscription_settings.save()\r
+        request.user.message_set.create(message=_('New subscription settings are now saved'))\r
     else:\r
         form = SubscriptionSettingsForm(user.subscription_settings.__dict__)\r
 \r