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
(_('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
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
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
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
"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
\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