本文整理汇总了Python中mediagoblin.tools.response.redirect_obj函数的典型用法代码示例。如果您正苦于以下问题:Python redirect_obj函数的具体用法?Python redirect_obj怎么用?Python redirect_obj使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect_obj函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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}
)
示例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})
示例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)
示例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})
示例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})
示例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})
示例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})
示例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})
示例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})
示例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})
示例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},
)
示例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}
)
示例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}
)