diff options
author | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2013-03-30 14:42:45 +0100 |
---|---|---|
committer | Elrond <elrond+mediagoblin.org@samba-tng.org> | 2013-03-30 14:42:45 +0100 |
commit | 4924b93bac328d9753f51ad9a3d3dd2dcb370871 (patch) | |
tree | 77a215d6be03d66f8a179d9f04e165a43f44a7d4 | |
parent | 047d8d5871ee8ee97ea52a78512fe5b2da51b8cc (diff) | |
parent | c5d341d79dc87b01c5804218ec24d20c1f0e9dac (diff) | |
download | mediagoblin-4924b93bac328d9753f51ad9a3d3dd2dcb370871.tar.lz mediagoblin-4924b93bac328d9753f51ad9a3d3dd2dcb370871.tar.xz mediagoblin-4924b93bac328d9753f51ad9a3d3dd2dcb370871.zip |
Merge remote-tracking branch 'JDShu/649_use_form_data_field'
* JDShu/649_use_form_data_field:
Use WTForms data field in user_pages/views.py
Use WTForms data field in auth/views.py
auth: whitespace cleanup in views.py
Use WTForms data field in plugins/oauth/views.py
Use WTForms data field in submit/views.py
Use WTForms data field in edit/views.py
-rw-r--r-- | mediagoblin/auth/views.py | 18 | ||||
-rw-r--r-- | mediagoblin/edit/views.py | 32 | ||||
-rw-r--r-- | mediagoblin/plugins/oauth/views.py | 8 | ||||
-rw-r--r-- | mediagoblin/submit/views.py | 12 | ||||
-rw-r--r-- | mediagoblin/user_pages/views.py | 2 |
5 files changed, 36 insertions, 36 deletions
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index d8ad7b51..354b48c1 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -78,7 +78,7 @@ def register(request): user.username = register_form.data['username'] user.email = register_form.data['email'] user.pw_hash = auth_lib.bcrypt_gen_password_hash( - request.form['password']) + register_form.password.data) user.verification_key = unicode(uuid.uuid4()) user.save() @@ -116,7 +116,7 @@ def login(request): if login_form.validate(): user = User.query.filter_by(username=login_form.data['username']).first() - if user and user.check_login(request.form['password']): + if user and user.check_login(login_form.password.data): # set up login in session request.session['user_id'] = unicode(user.id) request.session.save() @@ -196,7 +196,7 @@ def resend_activation(request): request, messages.ERROR, _('You must be logged in so we know who to send the email to!')) - + return redirect(request, 'mediagoblin.auth.login') if request.user.email_verified: @@ -204,12 +204,12 @@ def resend_activation(request): request, messages.ERROR, _("You've already verified your email address!")) - + return redirect(request, "mediagoblin.user_pages.user_home", user=request.user['username']) request.user.verification_key = unicode(uuid.uuid4()) request.user.save() - + email_debug_message(request) send_verification_email(request.user, request) @@ -241,11 +241,11 @@ def forgot_password(request): # has been sanitized. Store if a user was found by email. We should # not reveal if the operation was successful then as we don't want to # leak if an email address exists in the system. - found_by_email = '@' in request.form['username'] + found_by_email = '@' in fp_form.username.data if found_by_email: user = User.query.filter_by( - email = request.form['username']).first() + email = fp_form.username.data).first() # Don't reveal success in case the lookup happened by email address. success_message=_("If that email address (case sensitive!) is " "registered an email has been sent with instructions " @@ -253,7 +253,7 @@ def forgot_password(request): else: # found by username user = User.query.filter_by( - username = request.form['username']).first() + username = fp_form.username.data).first() if user is None: messages.add_message(request, @@ -317,7 +317,7 @@ def verify_forgot_password(request): if request.method == 'POST' and cp_form.validate(): user.pw_hash = auth_lib.bcrypt_gen_password_hash( - request.form['password']) + cp_form.password.data) user.fp_verification_key = None user.fp_token_expire = None user.save() diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py index cdb5c713..0b1cda98 100644 --- a/mediagoblin/edit/views.py +++ b/mediagoblin/edit/views.py @@ -26,7 +26,7 @@ from mediagoblin.auth import lib as auth_lib from mediagoblin.edit import forms from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import (require_active_login, active_user_from_url, - get_media_entry_by_id, + get_media_entry_by_id, user_may_alter_collection, get_user_collection) from mediagoblin.tools.response import render_to_response, redirect from mediagoblin.tools.translate import pass_to_ugettext as _ @@ -58,19 +58,19 @@ def edit_media(request, media): if request.method == 'POST' and form.validate(): # Make sure there isn't already a MediaEntry with such a slug # and userid. - slug = slugify(request.form['slug']) + slug = slugify(form.slug.data) slug_used = check_media_slug_used(media.uploader, slug, media.id) if slug_used: form.slug.errors.append( _(u'An entry with that slug already exists for this user.')) else: - media.title = request.form['title'] - media.description = request.form.get('description') + media.title = form.title.data + media.description = form.description.data media.tags = convert_to_tag_list_of_dicts( - request.form.get('tags')) + form.tags.data) - media.license = unicode(request.form.get('license', '')) or None + media.license = unicode(form.license.data) or None media.slug = slug media.save() @@ -142,7 +142,7 @@ def edit_attachments(request, media): request.files['attachment_file'].stream.close() media.attachment_files.append(dict( - name=request.form['attachment_name'] \ + name=form.attachment_name.data \ or request.files['attachment_file'].filename, filepath=attachment_public_filepath, created=datetime.utcnow(), @@ -153,7 +153,7 @@ def edit_attachments(request, media): messages.add_message( request, messages.SUCCESS, _("You added the attachment %s!") \ - % (request.form['attachment_name'] + % (form.attachment_name.data or request.files['attachment_file'].filename)) return redirect(request, @@ -194,8 +194,8 @@ def edit_profile(request, url_user=None): bio=user.bio) if request.method == 'POST' and form.validate(): - user.url = unicode(request.form['url']) - user.bio = unicode(request.form['bio']) + user.url = unicode(form.url.data) + user.bio = unicode(form.bio.data) user.save() @@ -309,25 +309,25 @@ def edit_collection(request, collection): # Make sure there isn't already a Collection with such a slug # and userid. slug_used = check_collection_slug_used(request.db, collection.creator, - request.form['slug'], collection.id) + form.slug.data, collection.id) # Make sure there isn't already a Collection with this title existing_collection = request.db.Collection.find_one({ 'creator': request.user.id, - 'title':request.form['title']}) + 'title':form.title.data}) if existing_collection and existing_collection.id != collection.id: messages.add_message( request, messages.ERROR, _('You already have a collection called "%s"!') % \ - request.form['title']) + form.title.data) elif slug_used: form.slug.errors.append( _(u'A collection with that slug already exists for this user.')) else: - collection.title = unicode(request.form['title']) - collection.description = unicode(request.form.get('description')) - collection.slug = unicode(request.form['slug']) + collection.title = unicode(form.title.data) + collection.description = unicode(form.description.data) + collection.slug = unicode(form.slug.data) collection.save() diff --git a/mediagoblin/plugins/oauth/views.py b/mediagoblin/plugins/oauth/views.py index c7b2a332..ea45c209 100644 --- a/mediagoblin/plugins/oauth/views.py +++ b/mediagoblin/plugins/oauth/views.py @@ -45,11 +45,11 @@ def register_client(request): if request.method == 'POST' and form.validate(): client = OAuthClient() - client.name = unicode(request.form['name']) - client.description = unicode(request.form['description']) - client.type = unicode(request.form['type']) + client.name = unicode(form.name.data) + client.description = unicode(form.description.data) + client.type = unicode(form.type.data) client.owner_id = request.user.id - client.redirect_uri = unicode(request.form['redirect_uri']) + client.redirect_uri = unicode(form.redirect_uri.data) client.generate_identifier() client.generate_secret() diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index 1e47d259..9d31c844 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -60,18 +60,18 @@ def submit_start(request): entry = request.db.MediaEntry() entry.media_type = unicode(media_type) entry.title = ( - unicode(request.form['title']) + unicode(submit_form.title.data) or unicode(splitext(filename)[0])) - entry.description = unicode(request.form.get('description')) + entry.description = unicode(submit_form.description.data) - entry.license = unicode(request.form.get('license', "")) or None + entry.license = unicode(submit_form.license.data) or None entry.uploader = request.user.id # Process the user's folksonomy "tags" entry.tags = convert_to_tag_list_of_dicts( - request.form.get('tags')) + submit_form.tags.data) # Generate a slug from the title entry.generate_slug() @@ -125,8 +125,8 @@ def add_collection(request, media=None): try: collection = request.db.Collection() - collection.title = unicode(request.form['title']) - collection.description = unicode(request.form.get('description')) + collection.title = unicode(submit_form.title.data) + collection.description = unicode(submit_form.description.data) collection.creator = request.user.id collection.generate_slug() diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 09ec7df9..61c23f16 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -204,7 +204,7 @@ def media_collect(request, media): # If we are here, method=POST and the form is valid, submit things. # If the user is adding a new collection, use that: - if request.form['collection_title']: + if form.collection_title.data: # Make sure this user isn't duplicating an existing collection existing_collection = Collection.query.filter_by( creator=request.user.id, |