diff options
-rw-r--r-- | askbot/management/commands/send_email_alerts.py | 11 | ||||
-rw-r--r-- | askbot/models/__init__.py | 10 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 12 | ||||
-rw-r--r-- | askbot/urls.py | 9 | ||||
-rw-r--r-- | askbot/views/users.py | 11 |
5 files changed, 44 insertions, 9 deletions
diff --git a/askbot/management/commands/send_email_alerts.py b/askbot/management/commands/send_email_alerts.py index f92aff63..330e1cc9 100644 --- a/askbot/management/commands/send_email_alerts.py +++ b/askbot/management/commands/send_email_alerts.py @@ -1,5 +1,6 @@ import datetime from django.core.management.base import NoArgsCommand +from django.core.urlresolvers import reverse from django.db import connection from django.db.models import Q, F from askbot.models import User, Question, Answer, Tag, QuestionRevision @@ -14,6 +15,7 @@ from django.utils.datastructures import SortedDict from django.contrib.contenttypes.models import ContentType from askbot import const from askbot.utils import mail +from askbot.utils.slug import slugify DEBUG_THIS_COMMAND = False @@ -476,7 +478,14 @@ class Command(NoArgsCommand): 'before - due to a technicality that will eventually go away. ' ) - link = url_prefix + user.get_profile_url() + '?sort=email_subscriptions' + link = url_prefix + reverse( + 'user_subscriptions', + kwargs = { + 'id': user.id, + 'slug': slugify(user.username) + } + ) + text += _( 'go to %(email_settings_link)s to change ' 'frequency of email updates or ' diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 74211c23..73adcf34 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2029,8 +2029,14 @@ def format_instant_notification_email( site_url = askbot_settings.APP_URL origin_post = post.get_origin_post() #todo: create a better method to access "sub-urls" in user views - user_subscriptions_url = site_url + to_user.get_absolute_url() + \ - '?sort=email_subscriptions' + user_subscriptions_url = site_url + \ + reverse( + 'user_subscriptions', + kwargs = { + 'id': to_user.id, + 'slug': slugify(to_user.username) + } + ) if update_type == 'question_comment': assert(isinstance(post, Comment)) diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 36f65c71..9c8f685e 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -299,3 +299,15 @@ class PageLoadTests(PageLoadTestCase): status_code=404, template='404.html' ) + + def test_user_urls_logged_in(self): + user = models.User.objects.get(id=2) + name_slug = slugify(user.username) + #works only with builtin django_authopenid + self.client.login(method = 'force', user_id = 2) + self.try_url( + 'user_subscriptions', + kwargs = {'id': 2, 'slug': name_slug}, + template = 'user_profile/user_email_subscriptions.html' + ) + self.client.logout() diff --git a/askbot/urls.py b/askbot/urls.py index 873a7103..877e0beb 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -181,6 +181,15 @@ urlpatterns = patterns('', name='edit_user' ), url( + r'^%s(?P<id>\d+)/(?P<slug>.+)/%s$' % ( + _('users/'), + _('subscriptions/'), + ), + views.users.user, + kwargs = {'tab_name': 'email_subscriptions'}, + name = 'user_subscriptions' + ), + url( r'^%s(?P<id>\d+)/(?P<slug>.+)/$' % _('users/'), views.users.user, name='user_profile' diff --git a/askbot/views/users.py b/askbot/views/users.py index 94b3e997..324a4e8f 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -941,7 +941,7 @@ user_view_call_table = { 'moderation': user_moderate, } #todo: rename this function - variable named user is everywhere -def user(request, id, slug=None): +def user(request, id, slug=None, tab_name=None): """Main user view function that works as a switchboard id - id of the profile owner @@ -949,12 +949,12 @@ def user(request, id, slug=None): todo: decide what to do with slug - it is not used in the code in any way """ - profile_owner = get_object_or_404(models.User, id = id) - #sort CGI parameter tells us which tab in the user - #profile to show, the default one is 'stats' - tab_name = request.GET.get('sort', 'stats') + if tab_name is None: + #sort CGI parameter tells us which tab in the user + #profile to show, the default one is 'stats' + tab_name = request.GET.get('sort', 'stats') if tab_name in user_view_call_table: #get the actual view function @@ -966,5 +966,4 @@ def user(request, id, slug=None): 'view_user': profile_owner, 'user_follow_feature_on': ('followit' in django_settings.INSTALLED_APPS), } - return user_view_func(request, profile_owner, context) |