From 5a4e3ff1e2a0f2ed451bc191c1d44bcd694b8e75 Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 14 Nov 2011 15:39:57 +0100 Subject: [PATCH] Dot-Notation for Users.username --- mediagoblin/auth/lib.py | 4 ++-- mediagoblin/auth/views.py | 10 +++++----- mediagoblin/db/models.py | 8 ++++---- mediagoblin/decorators.py | 2 +- mediagoblin/edit/views.py | 2 +- mediagoblin/gmg_commands/users.py | 2 +- mediagoblin/listings/views.py | 2 +- mediagoblin/submit/views.py | 2 +- mediagoblin/templates/mediagoblin/base.html | 6 +++--- .../templates/mediagoblin/edit/edit_profile.html | 4 ++-- .../templates/mediagoblin/user_pages/media.html | 4 ++-- mediagoblin/tests/test_submission.py | 4 ++-- mediagoblin/tests/test_tests.py | 2 +- mediagoblin/user_pages/views.py | 4 ++-- 14 files changed, 28 insertions(+), 28 deletions(-) diff --git a/mediagoblin/auth/lib.py b/mediagoblin/auth/lib.py index cf4a2b83..ee1ce12d 100644 --- a/mediagoblin/auth/lib.py +++ b/mediagoblin/auth/lib.py @@ -105,7 +105,7 @@ def send_verification_email(user, request): """ rendered_email = render_template( request, 'mediagoblin/auth/verification_email.txt', - {'username': user['username'], + {'username': user.username, 'verification_url': EMAIL_VERIFICATION_TEMPLATE.format( host=request.host, uri=request.urlgen('mediagoblin.auth.verify_email'), @@ -140,7 +140,7 @@ def send_fp_verification_email(user, request): """ rendered_email = render_template( request, 'mediagoblin/auth/fp_verification_email.txt', - {'username': user['username'], + {'username': user.username, 'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format( host=request.host, uri=request.urlgen('mediagoblin.auth.verify_forgot_password'), diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index d01861d1..dab95b17 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -80,7 +80,7 @@ def register(request): if extra_validation_passes: # Create the user user = request.db.User() - user['username'] = username + user.username = username user['email'] = email user['pw_hash'] = auth_lib.bcrypt_gen_password_hash( request.POST['password']) @@ -98,7 +98,7 @@ def register(request): # message waiting for them to verify their email return redirect( request, 'mediagoblin.user_pages.user_home', - user=user['username']) + user=user.username) return render_to_response( request, @@ -186,7 +186,7 @@ def verify_email(request): return redirect( request, 'mediagoblin.user_pages.user_home', - user=user['username']) + user=user.username) def resend_activation(request): @@ -224,7 +224,7 @@ def resend_activation(request): _('Resent your verification email.')) return redirect( request, 'mediagoblin.user_pages.user_home', - user=request.user['username']) + user=request.user.username) def forgot_password(request): @@ -268,7 +268,7 @@ def forgot_password(request): return redirect( request, 'mediagoblin.user_pages.user_home', - user=user['username']) + user=user.username) # do not reveal whether or not there is a matching user return redirect(request, 'mediagoblin.auth.fp_email_sent') diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 265fe36d..4af996b8 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -268,12 +268,12 @@ class MediaEntry(Document): if self.get('slug'): return urlgen( 'mediagoblin.user_pages.media_home', - user=uploader['username'], + user=uploader.username, media=self['slug']) else: return urlgen( 'mediagoblin.user_pages.media_home', - user=uploader['username'], + user=uploader.username, media=unicode(self._id)) def url_to_prev(self, urlgen): @@ -286,7 +286,7 @@ class MediaEntry(Document): '_id', ASCENDING).limit(1) if cursor.count(): return urlgen('mediagoblin.user_pages.media_home', - user=self.get_uploader()['username'], + user=self.get_uploader().username, media=unicode(cursor[0]['slug'])) def url_to_next(self, urlgen): @@ -300,7 +300,7 @@ class MediaEntry(Document): if cursor.count(): return urlgen('mediagoblin.user_pages.media_home', - user=self.get_uploader()['username'], + user=self.get_uploader().username, media=unicode(cursor[0]['slug'])) def get_uploader(self): diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index 269b0c2e..d6a054f8 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -40,7 +40,7 @@ def require_active_login(controller): request.user.get('status') == u'needs_email_verification': return redirect( request, 'mediagoblin.user_pages.user_home', - user=request.user['username']) + user=request.user.username) elif not request.user or request.user.get('status') != u'active': return exc.HTTPFound( location="%s?next=%s" % ( diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index 673409bd..61a61d4c 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -147,7 +147,7 @@ def edit_attachments(request, media): def edit_profile(request): # admins may edit any user profile given a username in the querystring edit_username = request.GET.get('username') - if request.user['is_admin'] and request.user['username'] != edit_username: + if request.user['is_admin'] and request.user.username != edit_username: user = request.db.User.find_one({'username': edit_username}) # No need to warn again if admin just submitted an edited profile if request.method != 'POST': diff --git a/mediagoblin/gmg_commands/users.py b/mediagoblin/gmg_commands/users.py index b437e839..e8426272 100644 --- a/mediagoblin/gmg_commands/users.py +++ b/mediagoblin/gmg_commands/users.py @@ -50,7 +50,7 @@ def adduser(args): else: # Create the user entry = db.User() - entry['username'] = unicode(args.username.lower()) + entry.username = unicode(args.username.lower()) entry['email'] = unicode(args.email) entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash(args.password) entry['status'] = u'active' diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py index 5a09de43..6b83ffcf 100644 --- a/mediagoblin/listings/views.py +++ b/mediagoblin/listings/views.py @@ -86,7 +86,7 @@ def tag_atom_feed(request): feed.add(entry.get('title'), entry.get('description_html'), content_type='html', - author=entry.get_uploader()['username'], + author=entry.get_uploader().username, updated=entry.get('created'), url=entry.url_for_self(request.urlgen)) diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 3def44ce..6beb6b18 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -127,7 +127,7 @@ def submit_start(request): add_message(request, SUCCESS, _('Woohoo! Submitted!')) return redirect(request, "mediagoblin.user_pages.user_home", - user=request.user['username']) + user=request.user.username) except InvalidFileType, exc: submit_form.file.errors.append( _(u'Invalid file type.')) diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index 29639026..c06addd0 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -60,14 +60,14 @@ {# the following link should only appear when verification is needed #} {% if request.user.status == "needs_email_verification" %} {% trans %}Verify your email!{% endtrans %} {% endif %} - {{ request.user['username'] }} + user= request.user.username) }}"> + {{ request.user.username }} ({% trans %}log out{% endtrans %}) {% else %} diff --git a/mediagoblin/templates/mediagoblin/edit/edit_profile.html b/mediagoblin/templates/mediagoblin/edit/edit_profile.html index bf8fe5c1..2d5daa95 100644 --- a/mediagoblin/templates/mediagoblin/edit/edit_profile.html +++ b/mediagoblin/templates/mediagoblin/edit/edit_profile.html @@ -22,11 +22,11 @@ {% block mediagoblin_content %}

- {%- trans username=user['username'] -%} + {%- trans username=user.username -%} Editing {{ username }}'s profile {%- endtrans %}

diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index b811d161..7fc60c3f 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -80,8 +80,8 @@ {% endautoescape %} - {{ comment_author['username'] }} + user = comment_author.username) }}"> + {{ comment_author.username }} {% trans %}at{% endtrans %}