Merge remote-tracking branch 'refs/remotes/spaetz/521_license_preference' into mergetest

This commit is contained in:
Christopher Allan Webber 2013-01-22 13:43:02 -06:00
commit 79f7cfd900
6 changed files with 62 additions and 36 deletions

View File

@ -184,3 +184,15 @@ def fix_CollectionItem_v0_constraint(db_conn):
pass pass
db_conn.commit() db_conn.commit()
@RegisterMigration(8, MIGRATIONS)
def add_license_preference(db):
metadata = MetaData(bind=db.bind)
user_table = Table('core__users', metadata, autoload=True,
autoload_with=db.bind)
col = Column('license_preference', Unicode, default=u'')
col.create(user_table)
db.commit()

View File

@ -63,6 +63,7 @@ class User(Base, UserMixin):
# Intented to be nullable=False, but migrations would not work for it # Intented to be nullable=False, but migrations would not work for it
# set to nullable=True implicitly. # set to nullable=True implicitly.
wants_comment_notification = Column(Boolean, default=True) wants_comment_notification = Column(Boolean, default=True)
license_preference = Column(Unicode)
verification_key = Column(Unicode) verification_key = Column(Unicode)
is_admin = Column(Boolean, default=False, nullable=False) is_admin = Column(Boolean, default=False, nullable=False)
url = Column(Unicode) url = Column(Unicode)

View File

@ -65,8 +65,19 @@ class EditAccountForm(wtforms.Form):
"Enter your old password to prove you own this account.")) "Enter your old password to prove you own this account."))
new_password = wtforms.PasswordField( new_password = wtforms.PasswordField(
_('New password'), _('New password'),
[wtforms.validators.Length(min=6, max=30)], [
wtforms.validators.Optional(),
wtforms.validators.Length(min=6, max=30)
],
id="password") id="password")
license_preference = wtforms.SelectField(
_('License preference'),
[
wtforms.validators.Optional(),
wtforms.validators.AnyOf([lic[0] for lic in licenses_as_choices()]),
],
choices=licenses_as_choices(),
description=_('This will be your default license on upload forms.'))
wants_comment_notification = wtforms.BooleanField( wants_comment_notification = wtforms.BooleanField(
label=_("Email me when others comment on my media")) label=_("Email me when others comment on my media"))

View File

@ -218,45 +218,42 @@ def edit_profile(request, url_user=None):
def edit_account(request): def edit_account(request):
user = request.user user = request.user
form = forms.EditAccountForm(request.form, 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': if request.method == 'POST':
form_validated = form.validate() form_validated = form.validate()
#if the user has not filled in the new or old password fields if form_validated and \
if not form.new_password.data and not form.old_password.data: form.wants_comment_notification.validate(form):
if form.wants_comment_notification.validate(form): user.wants_comment_notification = \
user.wants_comment_notification = \ form.wants_comment_notification.data
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 if form_validated and \
else: form.new_password.data or form.old_password.data:
if form_validated: password_matches = auth_lib.bcrypt_check_password(
password_matches = auth_lib.bcrypt_check_password( form.old_password.data,
form.old_password.data, user.pw_hash)
user.pw_hash) if password_matches:
if password_matches: #the entire form validates and the password matches
#the entire form validates and the password matches user.pw_hash = auth_lib.bcrypt_gen_password_hash(
user.pw_hash = auth_lib.bcrypt_gen_password_hash( form.new_password.data)
form.new_password.data) else:
user.wants_comment_notification = \ form.old_password.errors.append(_('Wrong password'))
form.wants_comment_notification.data
user.save() if form_validated and \
messages.add_message(request, form.license_preference.validate(form):
messages.SUCCESS, user.license_preference = \
_("Account settings saved")) form.license_preference.data
return redirect(request,
'mediagoblin.user_pages.user_home', if form_validated and not form.errors:
user=user.username) user.save()
else: messages.add_message(request,
form.old_password.errors.append(_('Wrong password')) messages.SUCCESS,
_("Account settings saved"))
return redirect(request,
'mediagoblin.user_pages.user_home',
user=user.username)
return render_to_response( return render_to_response(
request, request,

View File

@ -40,7 +40,8 @@ def submit_start(request):
""" """
First view for submitting a file. First view for submitting a file.
""" """
submit_form = submit_forms.SubmitStartForm(request.form) submit_form = submit_forms.SubmitStartForm(request.form,
license=request.user.get('license_preference'))
if request.method == 'POST' and submit_form.validate(): if request.method == 'POST' and submit_form.validate():
if not ('file' in request.files if not ('file' in request.files

View File

@ -47,6 +47,10 @@
<p>{{ form.wants_comment_notification }} <p>{{ form.wants_comment_notification }}
{{ form.wants_comment_notification.label }}</p> {{ form.wants_comment_notification.label }}</p>
</div> </div>
<div class="form_field_input">
<p>{{ form.license_preference }}
{{ form.license_preference.label }}</p>
</div>
<div class="form_submit_buttons"> <div class="form_submit_buttons">
<input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" /> <input type="submit" value="{% trans %}Save changes{% endtrans %}" class="button_form" />
{{ csrf_token }} {{ csrf_token }}