Use WTForms data field in edit/views.py
This commit is contained in:
parent
9924cd0fb6
commit
dc03850b7a
@ -26,7 +26,7 @@ from mediagoblin.auth import lib as auth_lib
|
|||||||
from mediagoblin.edit import forms
|
from mediagoblin.edit import forms
|
||||||
from mediagoblin.edit.lib import may_edit_media
|
from mediagoblin.edit.lib import may_edit_media
|
||||||
from mediagoblin.decorators import (require_active_login, active_user_from_url,
|
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)
|
user_may_alter_collection, get_user_collection)
|
||||||
from mediagoblin.tools.response import render_to_response, redirect
|
from mediagoblin.tools.response import render_to_response, redirect
|
||||||
from mediagoblin.tools.translate import pass_to_ugettext as _
|
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():
|
if request.method == 'POST' and form.validate():
|
||||||
# Make sure there isn't already a MediaEntry with such a slug
|
# Make sure there isn't already a MediaEntry with such a slug
|
||||||
# and userid.
|
# and userid.
|
||||||
slug = slugify(request.form['slug'])
|
slug = slugify(form.slug.data)
|
||||||
slug_used = check_media_slug_used(media.uploader, slug, media.id)
|
slug_used = check_media_slug_used(media.uploader, slug, media.id)
|
||||||
|
|
||||||
if slug_used:
|
if slug_used:
|
||||||
form.slug.errors.append(
|
form.slug.errors.append(
|
||||||
_(u'An entry with that slug already exists for this user.'))
|
_(u'An entry with that slug already exists for this user.'))
|
||||||
else:
|
else:
|
||||||
media.title = request.form['title']
|
media.title = form.title.data
|
||||||
media.description = request.form.get('description')
|
media.description = form.description.data
|
||||||
media.tags = convert_to_tag_list_of_dicts(
|
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.slug = slug
|
||||||
media.save()
|
media.save()
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ def edit_attachments(request, media):
|
|||||||
request.files['attachment_file'].stream.close()
|
request.files['attachment_file'].stream.close()
|
||||||
|
|
||||||
media.attachment_files.append(dict(
|
media.attachment_files.append(dict(
|
||||||
name=request.form['attachment_name'] \
|
name=form.attachment_name.data \
|
||||||
or request.files['attachment_file'].filename,
|
or request.files['attachment_file'].filename,
|
||||||
filepath=attachment_public_filepath,
|
filepath=attachment_public_filepath,
|
||||||
created=datetime.utcnow(),
|
created=datetime.utcnow(),
|
||||||
@ -153,7 +153,7 @@ def edit_attachments(request, media):
|
|||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.SUCCESS,
|
request, messages.SUCCESS,
|
||||||
_("You added the attachment %s!") \
|
_("You added the attachment %s!") \
|
||||||
% (request.form['attachment_name']
|
% (form.attachment_name.data
|
||||||
or request.files['attachment_file'].filename))
|
or request.files['attachment_file'].filename))
|
||||||
|
|
||||||
return redirect(request,
|
return redirect(request,
|
||||||
@ -194,8 +194,8 @@ def edit_profile(request, url_user=None):
|
|||||||
bio=user.bio)
|
bio=user.bio)
|
||||||
|
|
||||||
if request.method == 'POST' and form.validate():
|
if request.method == 'POST' and form.validate():
|
||||||
user.url = unicode(request.form['url'])
|
user.url = unicode(form.url.data)
|
||||||
user.bio = unicode(request.form['bio'])
|
user.bio = unicode(form.bio.data)
|
||||||
|
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
@ -309,25 +309,25 @@ def edit_collection(request, collection):
|
|||||||
# Make sure there isn't already a Collection with such a slug
|
# Make sure there isn't already a Collection with such a slug
|
||||||
# and userid.
|
# and userid.
|
||||||
slug_used = check_collection_slug_used(request.db, collection.creator,
|
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
|
# Make sure there isn't already a Collection with this title
|
||||||
existing_collection = request.db.Collection.find_one({
|
existing_collection = request.db.Collection.find_one({
|
||||||
'creator': request.user.id,
|
'creator': request.user.id,
|
||||||
'title':request.form['title']})
|
'title':form.title.data})
|
||||||
|
|
||||||
if existing_collection and existing_collection.id != collection.id:
|
if existing_collection and existing_collection.id != collection.id:
|
||||||
messages.add_message(
|
messages.add_message(
|
||||||
request, messages.ERROR,
|
request, messages.ERROR,
|
||||||
_('You already have a collection called "%s"!') % \
|
_('You already have a collection called "%s"!') % \
|
||||||
request.form['title'])
|
form.title.data)
|
||||||
elif slug_used:
|
elif slug_used:
|
||||||
form.slug.errors.append(
|
form.slug.errors.append(
|
||||||
_(u'A collection with that slug already exists for this user.'))
|
_(u'A collection with that slug already exists for this user.'))
|
||||||
else:
|
else:
|
||||||
collection.title = unicode(request.form['title'])
|
collection.title = unicode(form.title.data)
|
||||||
collection.description = unicode(request.form.get('description'))
|
collection.description = unicode(form.description.data)
|
||||||
collection.slug = unicode(request.form['slug'])
|
collection.slug = unicode(form.slug.data)
|
||||||
|
|
||||||
collection.save()
|
collection.save()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user