aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/edit/views.py
diff options
context:
space:
mode:
authorMark Holmquist <mtraceur@member.fsf.org>2012-11-10 16:59:37 -0800
committerSebastian Spaeth <Sebastian@SSpaeth.de>2013-01-17 21:34:04 +0100
commitdc4dfbde350fdd9eac50448e42f2c8b209dd6ea8 (patch)
treee46b401ad1cfb2aab400658491ed2975f23ff61a /mediagoblin/edit/views.py
parent49745d5138540af8f7cbce318767172f4c560881 (diff)
downloadmediagoblin-dc4dfbde350fdd9eac50448e42f2c8b209dd6ea8.tar.lz
mediagoblin-dc4dfbde350fdd9eac50448e42f2c8b209dd6ea8.tar.xz
mediagoblin-dc4dfbde350fdd9eac50448e42f2c8b209dd6ea8.zip
Add a license preference field
This feature is absolutely necessary. Now a user can simply define their default license and quickly go through a form, as opposed to stopping to click on the select and choosing the same option over and over again. Also added DB migration for the field, so that's working now, too. Rebased by Sebastian and made the default value to be unicode. Reviewed-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
Diffstat (limited to 'mediagoblin/edit/views.py')
-rw-r--r--mediagoblin/edit/views.py67
1 files changed, 32 insertions, 35 deletions
diff --git a/mediagoblin/edit/views.py b/mediagoblin/edit/views.py
index c656c63f..88af22d8 100644
--- a/mediagoblin/edit/views.py
+++ b/mediagoblin/edit/views.py
@@ -219,45 +219,42 @@ def edit_profile(request, url_user=None):
def edit_account(request):
user = request.user
form = forms.EditAccountForm(request.form,
- wants_comment_notification=user.get('wants_comment_notification'))
+ wants_comment_notification=user.get('wants_comment_notification'),
+ license_preference=user.get('license_preference'))
if request.method == 'POST':
form_validated = form.validate()
- #if the user has not filled in the new or old password fields
- if not form.new_password.data and not form.old_password.data:
- if form.wants_comment_notification.validate(form):
- user.wants_comment_notification = \
- form.wants_comment_notification.data
- user.save()
- messages.add_message(request,
- messages.SUCCESS,
- _("Account settings saved"))
- return redirect(request,
- 'mediagoblin.user_pages.user_home',
- user=user.username)
-
- #so the user has filled in one or both of the password fields
- else:
- if form_validated:
- password_matches = auth_lib.bcrypt_check_password(
- form.old_password.data,
- user.pw_hash)
- if password_matches:
- #the entire form validates and the password matches
- user.pw_hash = auth_lib.bcrypt_gen_password_hash(
- form.new_password.data)
- user.wants_comment_notification = \
- form.wants_comment_notification.data
- user.save()
- messages.add_message(request,
- messages.SUCCESS,
- _("Account settings saved"))
- return redirect(request,
- 'mediagoblin.user_pages.user_home',
- user=user.username)
- else:
- form.old_password.errors.append(_('Wrong password'))
+ if form_validated and \
+ form.wants_comment_notification.validate(form):
+ user.wants_comment_notification = \
+ form.wants_comment_notification.data
+
+ if form_validated and \
+ form.new_password.data or form.old_password.data:
+ password_matches = auth_lib.bcrypt_check_password(
+ form.old_password.data,
+ user.pw_hash)
+ if password_matches:
+ #the entire form validates and the password matches
+ user.pw_hash = auth_lib.bcrypt_gen_password_hash(
+ form.new_password.data)
+ else:
+ form.old_password.errors.append(_('Wrong password'))
+
+ if form_validated and \
+ form.license_preference.validate(form):
+ user.license_preference = \
+ form.license_preference.data
+
+ if form_validated and not form.errors:
+ user.save()
+ messages.add_message(request,
+ messages.SUCCESS,
+ _("Account settings saved"))
+ return redirect(request,
+ 'mediagoblin.user_pages.user_home',
+ user=user.username)
return render_to_response(
request,