X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/6d3c659143d605696fe95af0de7261754e38593a..243cb773ed9d1c4c7b3fa1c4ba7fb79ef6dc5ec0:/forum/views/users.py diff --git a/forum/views/users.py b/forum/views/users.py index 836b621..d95b302 100644 --- a/forum/views/users.py +++ b/forum/views/users.py @@ -1,4 +1,3 @@ -from django.contrib.auth.decorators import login_required from forum.models import User from django.db.models import Q, Count from django.core.paginator import Paginator, EmptyPage, InvalidPage @@ -26,6 +25,7 @@ from forum.views.readers import QuestionListPaginatorContext, AnswerPaginatorCon import time import datetime import decorators +import unicodedata class UserReputationSort(pagination.SimpleSort): def apply(self, objects): @@ -82,7 +82,6 @@ def online_users(request): }) -@login_required def edit_user(request, id): user = get_object_or_404(User, id=id) if not (request.user.is_superuser or request.user == user): @@ -320,51 +319,68 @@ def user_favorites(request, user): @user_view('users/subscriptions.html', 'subscriptions', _('subscription'), _('subscriptions'), True, tabbed=False) def user_subscriptions(request, user): enabled = user.subscription_settings.enable_notifications - auto = request.GET.get('auto', 'True') - show_auto = True - manage_open = False - - if len(request.GET) > 0: - manage_open = True - - if auto == 'True': - show_auto = True - subscriptions = user.subscriptions.all().order_by('-questionsubscription__last_view') - else: - show_auto = False - subscriptions = user.subscriptions.filter(questionsubscription__auto_subscription=False).order_by('-questionsubscription__last_view') - if request.method == 'POST': + tab = request.GET.get('tab', "settings") + + if tab == 'settings': manage_open = False - form = SubscriptionSettingsForm(data=request.POST, instance=user.subscription_settings) + if request.method == 'POST': + manage_open = False + form = SubscriptionSettingsForm(data=request.POST, instance=user.subscription_settings) + + if form.is_valid(): + form.save() + message = _('New subscription settings are now saved') + + if 'notswitch' in request.POST: + enabled = not enabled + + if enabled: + message = _('Notifications are now enabled') + else: + message = _('Notifications are now disabled') + + user.subscription_settings.enable_notifications = enabled + user.subscription_settings.save() + + request.user.message_set.create(message=message) + else: + form = SubscriptionSettingsForm(instance=user.subscription_settings) + + return { + 'view_user':user, + 'notificatons_on': enabled, + 'form':form, + 'manage_open':manage_open, + } + + elif tab == 'manage': + manage_open = True + + auto = request.GET.get('auto', 'True') + if auto == 'True': + show_auto = True + subscriptions = QuestionSubscription.objects.filter(user=user).order_by('-last_view') + else: + show_auto = False + subscriptions = QuestionSubscription.objects.filter(user=user, auto_subscription=False).order_by('-last_view') + + return pagination.paginated(request, ('subscriptions', SubscriptionListPaginatorContext()), { + 'subscriptions':subscriptions, + 'view_user':user, + "auto":show_auto, + 'manage_open':manage_open, + }) + + # else: + # todo: probably want to throw an error + # error = "error to throw" + - if form.is_valid(): - form.save() - message = _('New subscription settings are now saved') - if 'notswitch' in request.POST: - enabled = not enabled - if enabled: - message = _('Notifications are now enabled') - else: - message = _('Notifications are now disabled') - user.subscription_settings.enable_notifications = enabled - user.subscription_settings.save() - request.user.message_set.create(message=message) - else: - form = SubscriptionSettingsForm(instance=user.subscription_settings) - - return pagination.paginated(request, ('subscriptions', SubscriptionListPaginatorContext()), { - 'subscriptions':subscriptions, - 'view_user':user, - 'notificatons_on': enabled, - 'form':form, - "auto":show_auto, - "manage_open":manage_open - }) @user_view('users/preferences.html', 'preferences', _('preferences'), _('preferences'), True, tabbed=False) def user_preferences(request, user): @@ -385,13 +401,4 @@ def user_preferences(request, user): return {'view_user': user, 'form': form} -@login_required -def account_settings(request): - logging.debug('') - msg = request.GET.get('msg', '') - is_openid = False - return render_to_response('account_settings.html', { - 'msg': msg, - 'is_openid': is_openid - }, context_instance=RequestContext(request))