From: qw3rty Date: Fri, 16 Jul 2010 20:37:51 +0000 (+0000) Subject: made some changes to the subscriptions view. works much better now. I was doing... X-Git-Tag: live~590 X-Git-Url: https://git.openstreetmap.org./osqa.git/commitdiff_plain/eee8a70aabdda52352e90b6470e150c919b9ae83 made some changes to the subscriptions view. works much better now. I was doing something real stupid before and am now doing something less stupid. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@544 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- diff --git a/forum/skins/default/templates/users/subscriptions.html b/forum/skins/default/templates/users/subscriptions.html index d115ae2..573bb0a 100644 --- a/forum/skins/default/templates/users/subscriptions.html +++ b/forum/skins/default/templates/users/subscriptions.html @@ -32,16 +32,22 @@

- - + + {% if not manage_open %} +
+ {% include "users/subscriptions_settings.html" %} +
+ {% endif %} + + {% if manage_open %} +
+ {% include "users/subscriptions_management.html" %} +
+ {% endif %} {% endblock %} diff --git a/forum/skins/default/templates/users/subscriptions_management.html b/forum/skins/default/templates/users/subscriptions_management.html index 2e918dd..a0d921e 100644 --- a/forum/skins/default/templates/users/subscriptions_management.html +++ b/forum/skins/default/templates/users/subscriptions_management.html @@ -6,9 +6,9 @@ {% trans "Manage your current subscriptions" %} {% if auto %} - {% trans "don't show auto-subscribe" %} + {% trans "don't show auto-subscribe" %} {% else %} - {% trans "show auto-subscribe" %} + {% trans "show auto-subscribe" %} {% endif %} diff --git a/forum/views/users.py b/forum/views/users.py index 60ad885..025fd8c 100644 --- a/forum/views/users.py +++ b/forum/views/users.py @@ -26,6 +26,7 @@ from forum.views.readers import QuestionListPaginatorContext, AnswerPaginatorCon import time import datetime import decorators +import unicodedata class UserReputationSort(pagination.SimpleSort): def apply(self, objects): @@ -320,52 +321,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 auto == 'True': - manage_open = True - show_auto = True - subscriptions = QuestionSubscription.objects.filter(user=user).order_by('-last_view') - # subscriptions = user.subscriptions.all().order_by('-questionsubscription__last_view') - else: - manage_open = True - show_auto = False - subscriptions = QuestionSubscription.objects.filter(user=user, auto_subscription=False).order_by('-last_view') - # 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') + 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):