本文整理汇总了Python中mediagoblin.tools.response.redirect_obj函数的典型用法代码示例。如果您正苦于以下问题:Python redirect_obj函数的具体用法?Python redirect_obj怎么用?Python redirect_obj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect_obj函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: media_post_comment
def media_post_comment(request, media):
"""
recieves POST from a MediaEntry() comment form, saves the comment.
"""
if not request.method == "POST":
raise MethodNotAllowed()
comment = request.db.MediaComment()
comment.media_entry = media.id
comment.author = request.user.id
print request.form["comment_content"]
comment.content = unicode(request.form["comment_content"])
# Show error message if commenting is disabled.
if not mg_globals.app_config["allow_comments"]:
messages.add_message(request, messages.ERROR, _("Sorry, comments are disabled."))
elif not comment.content.strip():
messages.add_message(request, messages.ERROR, _("Oops, your comment was empty."))
else:
comment.save()
messages.add_message(request, messages.SUCCESS, _("Your comment has been posted!"))
trigger_notification(comment, media, request)
add_comment_subscription(request.user, media)
return redirect_obj(request, media)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:28,代码来源:views.py
示例2: media_post_comment
def media_post_comment(request, media):
"""
recieves POST from a MediaEntry() comment form, saves the comment.
"""
if not request.method == 'POST':
raise MethodNotAllowed()
comment = request.db.MediaComment()
comment.media_entry = media.id
comment.author = request.user.id
comment.content = six.text_type(request.form['comment_content'])
# Show error message if commenting is disabled.
if not mg_globals.app_config['allow_comments']:
messages.add_message(
request,
messages.ERROR,
_("Sorry, comments are disabled."))
elif not comment.content.strip():
messages.add_message(
request,
messages.ERROR,
_("Oops, your comment was empty."))
else:
create_activity("post", comment, comment.author, target=media)
add_comment_subscription(request.user, media)
comment.save()
messages.add_message(
request, messages.SUCCESS,
_('Your comment has been posted!'))
trigger_notification(comment, media, request)
return redirect_obj(request, media)
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:34,代码来源:views.py
示例3: media_confirm_delete
def media_confirm_delete(request, media):
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == "POST" and form.validate():
if form.confirm.data is True:
username = media.get_uploader.username
# Delete MediaEntry and all related files, comments etc.
media.delete()
messages.add_message(request, messages.SUCCESS, _("You deleted the media."))
location = media.url_to_next(request.urlgen)
if not location:
location = media.url_to_prev(request.urlgen)
if not location:
location = request.urlgen("mediagoblin.user_pages.user_home", user=username)
return redirect(request, location=location)
else:
messages.add_message(
request, messages.ERROR, _("The media was not deleted because you didn't check that you were sure.")
)
return redirect_obj(request, media)
if request.user.is_admin and request.user.id != media.uploader:
messages.add_message(
request, messages.WARNING, _("You are about to delete another user's media. " "Proceed with caution.")
)
return render_to_response(
request, "mediagoblin/user_pages/media_confirm_delete.html", {"media": media, "form": form}
)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:31,代码来源:views.py
示例4: media_confirm_delete
def media_confirm_delete(request, media):
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == 'POST' and form.validate():
if form.confirm.data is True:
username = media.get_uploader.username
# Delete MediaEntry and all related files, comments etc.
media.delete()
messages.add_message(
request, messages.SUCCESS, _('You deleted the media.'))
return redirect(request, "mediagoblin.user_pages.user_home",
user=username)
else:
messages.add_message(
request, messages.ERROR,
_("The media was not deleted because you didn't check that you were sure."))
return redirect_obj(request, media)
if ((request.user.is_admin and
request.user.id != media.uploader)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete another user's media. "
"Proceed with caution."))
return render_to_response(
request,
'mediagoblin/user_pages/media_confirm_delete.html',
{'media': media,
'form': form})
开发者ID:joar,项目名称:mediagoblin,代码行数:32,代码来源:views.py
示例5: media_post_comment
def media_post_comment(request, media):
"""
recieves POST from a MediaEntry() comment form, saves the comment.
"""
assert request.method == 'POST'
comment = request.db.MediaComment()
comment.media_entry = media.id
comment.author = request.user.id
comment.content = unicode(request.form['comment_content'])
if not comment.content.strip():
messages.add_message(
request,
messages.ERROR,
_("Oops, your comment was empty."))
else:
comment.save()
messages.add_message(
request, messages.SUCCESS,
_('Your comment has been posted!'))
media_uploader = media.get_uploader
#don't send email if you comment on your own post
if (comment.author != media_uploader and
media_uploader.wants_comment_notification):
send_comment_email(media_uploader, comment, media, request)
return redirect_obj(request, media)
开发者ID:praveen97uma,项目名称:goblin,代码行数:30,代码来源:views.py
示例6: media_confirm_delete
def media_confirm_delete(request):
allowed_state = [u'failed', u'processed']
media = None
for media_state in allowed_state:
media = request.db.MediaEntry.query.filter_by(id=request.matchdict['media_id'], state=media_state).first()
if media:
break
if not media:
return render_404(request)
given_username = request.matchdict.get('user')
if given_username and (given_username != media.get_uploader.username):
return render_404(request)
uploader_id = media.uploader
if not (request.user.is_admin or
request.user.id == uploader_id):
raise Forbidden()
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == 'POST' and form.validate():
if form.confirm.data is True:
username = media.get_uploader.username
# Delete MediaEntry and all related files, comments etc.
media.delete()
messages.add_message(
request, messages.SUCCESS, _('You deleted the media.'))
location = media.url_to_next(request.urlgen)
if not location:
location=media.url_to_prev(request.urlgen)
if not location:
location=request.urlgen("mediagoblin.user_pages.user_home",
user=username)
return redirect(request, location=location)
else:
messages.add_message(
request, messages.ERROR,
_("The media was not deleted because you didn't check that you were sure."))
return redirect_obj(request, media)
if ((request.user.is_admin and
request.user.id != media.uploader)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete another user's media. "
"Proceed with caution."))
return render_to_response(
request,
'mediagoblin/user_pages/media_confirm_delete.html',
{'media': media,
'form': form})
开发者ID:spaetz,项目名称:mediagoblin_blog,代码行数:56,代码来源:views.py
示例7: media_confirm_delete
def media_confirm_delete(request, media):
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == 'POST' and form.validate():
if form.confirm.data is True:
username = media.get_actor.username
# This probably is already filled but just in case it has slipped
# through the net somehow, we need to try and make sure the
# MediaEntry has a public ID so it gets properly soft-deleted.
media.get_public_id(request.urlgen)
# Decrement the users uploaded quota.
media.get_actor.uploaded = media.get_actor.uploaded - \
media.file_size
media.get_actor.save()
# Delete MediaEntry and all related files, comments etc.
media.delete()
messages.add_message(
request,
messages.SUCCESS,
_('You deleted the media.'))
location = media.url_to_next(request.urlgen)
if not location:
location=media.url_to_prev(request.urlgen)
if not location:
location=request.urlgen("mediagoblin.user_pages.user_home",
user=username)
return redirect(request, location=location)
else:
messages.add_message(
request,
messages.ERROR,
_("The media was not deleted because you didn't check "
"that you were sure."))
return redirect_obj(request, media)
if ((request.user.has_privilege(u'admin') and
request.user.id != media.actor)):
messages.add_message(
request,
messages.WARNING,
_("You are about to delete another user's media. "
"Proceed with caution."))
return render_to_response(
request,
'mediagoblin/user_pages/media_confirm_delete.html',
{'media': media,
'form': form})
开发者ID:ausbin,项目名称:mediagoblin,代码行数:53,代码来源:views.py
示例8: collection_confirm_delete
def collection_confirm_delete(request, collection):
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == 'POST' and form.validate():
username = collection.get_actor.username
if form.confirm.data is True:
collection_title = collection.title
# Firstly like with the MediaEntry delete, lets ensure the
# public_id is populated as this is really important!
collection.get_public_id(request.urlgen)
# Delete all the associated collection items
for item in collection.get_collection_items():
obj = item.get_object()
obj.save()
item.delete()
collection.delete()
messages.add_message(
request,
messages.SUCCESS,
_('You deleted the collection "%s"') %
collection_title)
return redirect(request, "mediagoblin.user_pages.user_home",
user=username)
else:
messages.add_message(
request,
messages.ERROR,
_("The collection was not deleted because you didn't "
"check that you were sure."))
return redirect_obj(request, collection)
if ((request.user.has_privilege(u'admin') and
request.user.id != collection.actor)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete another user's collection. "
"Proceed with caution."))
return render_to_response(
request,
'mediagoblin/user_pages/collection_confirm_delete.html',
{'collection': collection,
'form': form})
开发者ID:ausbin,项目名称:mediagoblin,代码行数:51,代码来源:views.py
示例9: edit_collection
def edit_collection(request, collection):
defaults = dict(
title=collection.title,
slug=collection.slug,
description=collection.description)
form = forms.EditCollectionForm(
request.form,
**defaults)
if request.method == 'POST' and form.validate():
# Make sure there isn't already a Collection with such a slug
# and userid.
slug_used = check_collection_slug_used(collection.creator,
form.slug.data, collection.id)
# Make sure there isn't already a Collection with this title
existing_collection = request.db.Collection.query.filter_by(
creator=request.user.id,
title=form.title.data).first()
if existing_collection and existing_collection.id != collection.id:
messages.add_message(
request, messages.ERROR,
_('You already have a collection called "%s"!') % \
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(form.title.data)
collection.description = unicode(form.description.data)
collection.slug = unicode(form.slug.data)
collection.save()
return redirect_obj(request, collection)
if request.user.has_privilege(u'admin') \
and collection.creator != request.user.id \
and request.method != 'POST':
messages.add_message(
request, messages.WARNING,
_("You are editing another user's collection. Proceed with caution."))
return render_to_response(
request,
'mediagoblin/edit/edit_collection.html',
{'collection': collection,
'form': form})
开发者ID:incorpusyehtee,项目名称:mediagoblin,代码行数:50,代码来源:views.py
示例10: edit_media
def edit_media(request, media):
if not may_edit_media(request, media):
raise Forbidden("User may not edit this media")
defaults = dict(
title=media.title,
slug=media.slug,
description=media.description,
tags=media_tags_as_string(media.tags),
license=media.license)
form = forms.EditForm(
request.form,
**defaults)
if request.method == 'POST' and form.validate():
# Make sure there isn't already a MediaEntry with such a slug
# and userid.
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 = form.title.data
media.description = form.description.data
media.tags = convert_to_tag_list_of_dicts(
form.tags.data)
media.license = unicode(form.license.data) or None
media.slug = slug
media.save()
return redirect_obj(request, media)
if request.user.has_privilege(u'admin') \
and media.uploader != request.user.id \
and request.method != 'POST':
messages.add_message(
request, messages.WARNING,
_("You are editing another user's media. Proceed with caution."))
return render_to_response(
request,
'mediagoblin/edit/edit.html',
{'media': media,
'form': form})
开发者ID:incorpusyehtee,项目名称:mediagoblin,代码行数:48,代码来源:views.py
示例11: collection_confirm_delete
def collection_confirm_delete(request, collection):
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == 'POST' and form.validate():
username = collection.get_creator.username
if form.confirm.data is True:
collection_title = collection.title
# Delete all the associated collection items
for item in collection.get_collection_items():
entry = item.get_media_entry
entry.collected = entry.collected - 1
entry.save()
item.delete()
collection.delete()
messages.add_message(request, messages.SUCCESS,
_('You deleted the collection "%s"') % collection_title)
return redirect(request, "mediagoblin.user_pages.user_home",
user=username)
else:
messages.add_message(
request, messages.ERROR,
_("The collection was not deleted because you didn't check that you were sure."))
return redirect_obj(request, collection)
if ((request.user.is_admin and
request.user.id != collection.creator)):
messages.add_message(
request, messages.WARNING,
_("You are about to delete another user's collection. "
"Proceed with caution."))
return render_to_response(
request,
'mediagoblin/user_pages/collection_confirm_delete.html',
{'collection': collection,
'form': form})
开发者ID:spaetz,项目名称:mediagoblin_blog,代码行数:43,代码来源:views.py
示例12: edit_metadata
def edit_metadata(request, media):
form = forms.EditMetaDataForm(request.form)
if request.method == "POST" and form.validate():
metadata_dict = dict([(row['identifier'],row['value'])
for row in form.media_metadata.data])
json_ld_metadata = None
json_ld_metadata = compact_and_validate(metadata_dict)
media.media_metadata = json_ld_metadata
media.save()
return redirect_obj(request, media)
if len(form.media_metadata) == 0:
for identifier, value in media.media_metadata.iteritems():
if identifier == "@context": continue
form.media_metadata.append_entry({
'identifier':identifier,
'value':value})
return render_to_response(
request,
'mediagoblin/edit/metadata.html',
{'form':form,
'media':media})
开发者ID:incorpusyehtee,项目名称:mediagoblin,代码行数:23,代码来源:views.py
示例13: collection_item_confirm_remove
def collection_item_confirm_remove(request, collection_item):
form = user_forms.ConfirmCollectionItemRemoveForm(request.form)
if request.method == "POST" and form.validate():
username = collection_item.in_collection.get_creator.username
collection = collection_item.in_collection
if form.confirm.data is True:
entry = collection_item.get_media_entry
entry.collected = entry.collected - 1
entry.save()
collection_item.delete()
collection.items = collection.items - 1
collection.save()
messages.add_message(request, messages.SUCCESS, _("You deleted the item from the collection."))
else:
messages.add_message(
request, messages.ERROR, _("The item was not removed because you didn't check that you were sure.")
)
return redirect_obj(request, collection)
if request.user.is_admin and request.user.id != collection_item.in_collection.creator:
messages.add_message(
request,
messages.WARNING,
_("You are about to delete an item from another user's collection. " "Proceed with caution."),
)
return render_to_response(
request,
"mediagoblin/user_pages/collection_item_confirm_remove.html",
{"collection_item": collection_item, "form": form},
)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:37,代码来源:views.py
示例14: collection_confirm_delete
def collection_confirm_delete(request, collection):
form = user_forms.ConfirmDeleteForm(request.form)
if request.method == "POST" and form.validate():
username = collection.get_creator.username
if form.confirm.data is True:
collection_title = collection.title
# Delete all the associated collection items
for item in collection.get_collection_items():
remove_collection_item(item)
collection.delete()
messages.add_message(request, messages.SUCCESS, _('You deleted the collection "%s"') % collection_title)
return redirect(request, "mediagoblin.user_pages.user_home", user=username)
else:
messages.add_message(
request,
messages.ERROR,
_("The collection was not deleted because you didn't check that you were sure."),
)
return redirect_obj(request, collection)
if request.user.has_privilege(u"admin") and request.user.id != collection.creator:
messages.add_message(
request, messages.WARNING, _("You are about to delete another user's collection. " "Proceed with caution.")
)
return render_to_response(
request, "mediagoblin/user_pages/collection_confirm_delete.html", {"collection": collection, "form": form}
)
开发者ID:vasilenkomike,项目名称:mediagoblin,代码行数:36,代码来源:views.py
示例15: edit_collection
def edit_collection(request, collection):
defaults = dict(title=collection.title, slug=collection.slug, description=collection.description)
form = forms.EditCollectionForm(request.form, **defaults)
if request.method == "POST" and form.validate():
# Make sure there isn't already a Collection with such a slug
# and userid.
slug_used = check_collection_slug_used(collection.creator, 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": 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"!') % 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(form.title.data)
collection.description = unicode(form.description.data)
collection.slug = unicode(form.slug.data)
collection.save()
return redirect_obj(request, collection)
if request.user.is_admin and collection.creator != request.user.id and request.method != "POST":
messages.add_message(
request, messages.WARNING, _("You are editing another user's collection. Proceed with caution.")
)
return render_to_response(
request, "mediagoblin/edit/edit_collection.html", {"collection": collection, "form": form}
)
开发者ID:praveen97uma,项目名称:goblin,代码行数:36,代码来源:views.py
示例16: media_collect
def media_collect(request, media):
"""Add media to collection submission"""
form = user_forms.MediaCollectForm(request.form)
# A user's own collections:
form.collection.query = Collection.query.filter_by(
actor=request.user.id,
type=Collection.USER_DEFINED_TYPE
).order_by(Collection.title)
if request.method != 'POST' or not form.validate():
# No POST submission, or invalid form
if not form.validate():
messages.add_message(request, messages.ERROR,
_('Please check your entries and try again.'))
return render_to_response(
request,
'mediagoblin/user_pages/media_collect.html',
{'media': media,
'form': form})
# If we are here, method=POST and the form is valid, submit things.
# If the user is adding a new collection, use that:
if form.collection_title.data:
# Make sure this user isn't duplicating an existing collection
existing_collection = Collection.query.filter_by(
actor=request.user.id,
title=form.collection_title.data,
type=Collection.USER_DEFINED_TYPE
).first()
if existing_collection:
messages.add_message(request, messages.ERROR,
_('You already have a collection called "%s"!')
% existing_collection.title)
return redirect(request, "mediagoblin.user_pages.media_home",
user=media.get_actor.username,
media=media.slug_or_id)
collection = Collection()
collection.title = form.collection_title.data
collection.description = form.collection_description.data
collection.actor = request.user.id
collection.type = Collection.USER_DEFINED_TYPE
collection.generate_slug()
collection.get_public_id(request.urlgen)
create_activity("create", collection, collection.actor)
collection.save()
# Otherwise, use the collection selected from the drop-down
else:
collection = form.collection.data
if collection and collection.actor != request.user.id:
collection = None
# Make sure the user actually selected a collection
item = CollectionItem.query.filter_by(collection=collection.id)
item = item.join(CollectionItem.object_helper).filter_by(
model_type=media.__tablename__,
obj_pk=media.id
).first()
if not collection:
messages.add_message(
request, messages.ERROR,
_('You have to select or add a collection'))
return redirect(request, "mediagoblin.user_pages.media_collect",
user=media.get_actor.username,
media_id=media.id)
# Check whether media already exists in collection
elif item is not None:
messages.add_message(request, messages.ERROR,
_('"%s" already in collection "%s"')
% (media.title, collection.title))
else: # Add item to collection
add_media_to_collection(collection, media, form.note.data)
create_activity("add", media, request.user, target=collection)
messages.add_message(request, messages.SUCCESS,
_('"%s" added to collection "%s"')
% (media.title, collection.title))
return redirect_obj(request, media)
开发者ID:tofay,项目名称:mediagoblin,代码行数:83,代码来源:views.py
示例17: media_collect
def media_collect(request, media):
"""Add media to collection submission"""
form = user_forms.MediaCollectForm(request.form)
# A user's own collections:
form.collection.query = Collection.query.filter_by(creator=request.user.id).order_by(Collection.title)
if request.method != "POST" or not form.validate():
# No POST submission, or invalid form
if not form.validate():
messages.add_message(request, messages.ERROR, _("Please check your entries and try again."))
return render_to_response(request, "mediagoblin/user_pages/media_collect.html", {"media": media, "form": form})
# If we are here, method=POST and the form is valid, submit things.
# If the user is adding a new collection, use that:
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, title=form.collection_title.data
).first()
if existing_collection:
messages.add_message(
request, messages.ERROR, _('You already have a collection called "%s"!') % existing_collection.title
)
return redirect(
request, "mediagoblin.user_pages.media_home", user=media.get_uploader.username, media=media.slug_or_id
)
collection = Collection()
collection.title = form.collection_title.data
collection.description = form.collection_description.data
collection.creator = request.user.id
collection.generate_slug()
collection.save()
# Otherwise, use the collection selected from the drop-down
else:
collection = form.collection.data
if collection and collection.creator != request.user.id:
collection = None
# Make sure the user actually selected a collection
if not collection:
messages.add_message(request, messages.ERROR, _("You have to select or add a collection"))
return redirect(
request, "mediagoblin.user_pages.media_collect", user=media.get_uploader.username, media_id=media.id
)
# Check whether media already exists in collection
elif CollectionItem.query.filter_by(media_entry=media.id, collection=collection.id).first():
messages.add_message(
request, messages.ERROR, _('"%s" already in collection "%s"') % (media.title, collection.title)
)
else: # Add item to collection
add_media_to_collection(collection, media, form.note.data)
messages.add_message(
request, messages.SUCCESS, _('"%s" added to collection "%s"') % (media.title, collection.title)
)
return redirect_obj(request, media)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:62,代码来源:views.py
注:本文中的mediagoblin.tools.response.redirect_obj函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论