本文整理汇总了Python中mediacore.lib.helpers.redirect函数的典型用法代码示例。如果您正苦于以下问题:Python redirect函数的具体用法?Python redirect怎么用?Python redirect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _save
def _save(self, form, redirect_action=None, values=None):
"""Save the values from the passed in form instance."""
values = self._flatten_settings_from_form(tmpl_context.settings,
form, values)
self._update_settings(values)
if redirect_action:
helpers.redirect(action=redirect_action)
开发者ID:Jpoudrier,项目名称:mediacore-community,代码行数:7,代码来源:base.py
示例2: save
def save(self, id, email_address, display_name, login_details,
delete=None, **kwargs):
"""Save changes or create a new :class:`~mediacore.model.auth.User` instance.
:param id: User ID. If ``"new"`` a new user is created.
:type id: ``int`` or ``"new"``
:returns: Redirect back to :meth:`index` after successful save.
"""
user = fetch_row(User, id)
if delete:
DBSession.delete(user)
redirect(action='index', id=None)
user.display_name = display_name
user.email_address = email_address
user.user_name = login_details['user_name']
password = login_details['password']
if password is not None and password != '':
user.password = password
if login_details['group']:
group = fetch_row(Group, login_details['group'])
user.groups = [group]
else:
user.groups = []
DBSession.add(user)
DBSession.flush()
redirect(action='index', id=None)
开发者ID:86me,项目名称:mediacore,代码行数:32,代码来源:users.py
示例3: edit
def edit(self, id, engine_type=None, **kwargs):
"""Display the :class:`~mediacore.lib.storage.StorageEngine` for editing or adding.
:param id: Storage ID
:type id: ``int`` or ``"new"``
:rtype: dict
:returns:
"""
if id != "new":
engine = fetch_row(StorageEngine, id)
else:
types = dict((cls.engine_type, cls) for cls in StorageEngine)
engine_cls = types.get(engine_type, None)
if not engine_cls:
redirect(controller="/admin/storage", action="index")
engine = engine_cls()
if not engine.settings_form:
# XXX: If this newly created storage engine has no settings,
# just save it. This isn't RESTful (as edit is a GET
# action), but it simplifies the creation process.
DBSession.add(engine)
redirect(controller="/admin/storage", action="index")
return {
"engine": engine,
"form": engine.settings_form,
"form_action": url_for(action="save", engine_type=engine_type),
"form_values": kwargs,
}
开发者ID:greentv,项目名称:mediacore,代码行数:31,代码来源:storage.py
示例4: rate
def rate(self, slug, up=None, down=None, **kwargs):
"""Say 'I like this' for the given media.
:param slug: The media :attr:`~mediacore.model.media.Media.slug`
:rtype: unicode
:returns:
The new number of likes
"""
media = fetch_row(Media, slug=slug)
request.perm.assert_permission(u'view', media.resource)
if up:
if not request.settings['appearance_show_like']:
abort(status_code=403)
media.increment_likes()
elif down:
if not request.settings['appearance_show_dislike']:
abort(status_code=403)
media.increment_dislikes()
if request.is_xhr:
return u''
else:
redirect(action='view')
开发者ID:wafe,项目名称:mediadrop,代码行数:25,代码来源:media.py
示例5: serve
def serve(self, id, slug, container, **kwargs):
"""Serve a :class:`~mediacore.model.media.MediaFile` binary.
:param id: File ID
:type id: ``int``
:param slug: The media :attr:`~mediacore.model.media.Media.slug`
:type slug: The file :attr:`~mediacore.model.media.MediaFile.container`
:raises webob.exc.HTTPNotFound: If no file exists for the given params.
:raises webob.exc.HTTPNotAcceptable: If an Accept header field
is present, and if the mimetype of the requested file doesn't
match, then a 406 (not acceptable) response is returned.
"""
media = fetch_row(Media, slug=slug)
for file in media.files:
if file.id == id and file.container == container:
# Catch external redirects in case they aren't linked to directly
if file.url:
redirect(file.url.encode('utf-8'))
# Ensure that the clients request allows for files of this container
mimetype = mimeparse.best_match([file.mimetype],
request.environ.get('HTTP_ACCEPT', '*/*'))
if mimetype == '':
raise webob.exc.HTTPNotAcceptable() # 406
response.headers['Content-Type'] = mimetype
response.headers['Content-Disposition'] = \
'attachment;filename="%s"' % file.display_name.encode('utf-8')
return open(file.file_path, 'rb').read()
else:
raise webob.exc.HTTPNotFound()
开发者ID:86me,项目名称:mediacore,代码行数:33,代码来源:media.py
示例6: index
def index(self, **kwargs):
"""List podcasts and podcast media.
:rtype: dict
:returns:
podcasts
The :class:`~mediacore.model.podcasts.Podcast` instance
"""
podcasts = Podcast.query\
.options(orm.undefer('media_count_published'))\
.all()
if len(podcasts) == 1:
redirect(action='view', slug=podcasts[0].slug)
podcast_episodes = {}
for podcast in podcasts:
episode_query = podcast.media.published().order_by(Media.publish_on.desc())
podcast_episodes[podcast] = viewable_media(episode_query)[:4]
return dict(
podcasts = podcasts,
podcast_episodes = podcast_episodes,
)
开发者ID:ajoythomas,项目名称:mediacore-community,代码行数:25,代码来源:podcasts.py
示例7: index
def index(self, page=1, **kwargs):
"""List podcasts and podcast media.
Our custom paginate decorator allows us to have fewer podcast episodes
display on the first page than on the rest with the ``items_first_page``
param. See :class:`mediacore.lib.custompaginate.CustomPage`.
:param page: Page number, defaults to 1.
:type page: int
:rtype: dict
:returns:
podcasts
The :class:`~mediacore.model.podcasts.Podcast` instance
"""
podcasts = Podcast.query\
.options(orm.undefer('media_count_published'))\
.all()
if len(podcasts) == 1:
redirect(action='view', slug=podcasts[0].slug)
podcast_episodes = {}
for podcast in podcasts:
podcast_episodes[podcast] = podcast.media.published()\
.order_by(Media.publish_on.desc())[:4]
return dict(
podcasts = podcasts,
podcast_episodes = podcast_episodes,
)
开发者ID:MechanisM,项目名称:mediacore,代码行数:31,代码来源:podcasts.py
示例8: feed
def feed(self, slug, **kwargs):
"""Serve the feed as RSS 2.0.
If :attr:`~mediacore.model.podcasts.Podcast.feedburner_url` is
specified for this podcast, we redirect there if the useragent
does not contain 'feedburner', as described here:
http://www.google.com/support/feedburner/bin/answer.py?hl=en&answer=78464
:param feedburner_bypass: If true, the redirect to feedburner is disabled.
:rtype: Dict
:returns:
podcast
A :class:`~mediacore.model.podcasts.Podcast` instance.
episodes
A list of :class:`~mediacore.model.media.Media` instances
that belong to the ``podcast``.
Renders: :data:`podcasts/feed.xml` XML
"""
podcast = fetch_row(Podcast, slug=slug)
if (
podcast.feedburner_url
and not "feedburner" in request.environ.get("HTTP_USER_AGENT", "").lower()
and not kwargs.get("feedburner_bypass", False)
):
redirect(podcast.feedburner_url.encode("utf-8"))
response.content_type = content_type_for_response(["application/rss+xml", "application/xml", "text/xml"])
episodes = podcast.media.published().order_by(Media.publish_on.desc())[:25]
return dict(podcast=podcast, episodes=episodes)
开发者ID:smalltide,项目名称:mediacore-community,代码行数:34,代码来源:podcasts.py
示例9: save
def save(self, id, delete=None, **kwargs):
"""Save changes or create a category.
See :class:`~mediacore.forms.admin.settings.categories.CategoryForm` for POST vars.
:param id: Category ID
:param delete: If true the category is to be deleted rather than saved.
:type delete: bool
:rtype: JSON dict
:returns:
success
bool
"""
if tmpl_context.form_errors:
if request.is_xhr:
return dict(success=False, errors=tmpl_context.form_errors)
else:
# TODO: Add error reporting for users with JS disabled?
return redirect(action="edit")
cat = fetch_row(Category, id)
if delete:
DBSession.delete(cat)
data = dict(success=True, id=cat.id, parent_options=unicode(category_form.c["parent_id"].display()))
else:
cat.name = kwargs["name"]
cat.slug = get_available_slug(Category, kwargs["slug"], cat)
if kwargs["parent_id"]:
parent = fetch_row(Category, kwargs["parent_id"])
if parent is not cat and cat not in parent.ancestors():
cat.parent = parent
else:
cat.parent = None
DBSession.add(cat)
DBSession.flush()
data = dict(
success=True,
id=cat.id,
name=cat.name,
slug=cat.slug,
parent_id=cat.parent_id,
parent_options=unicode(category_form.c["parent_id"].display()),
depth=cat.depth(),
row=unicode(
category_row_form.display(
action=url_for(id=cat.id), category=cat, depth=cat.depth(), first_child=True
)
),
)
if request.is_xhr:
return data
else:
redirect(action="index", id=None)
开发者ID:kiberpipa,项目名称:mediacore,代码行数:59,代码来源:categories.py
示例10: view
def view(self, slug, podcast_slug=None, **kwargs):
"""Display the media player, info and comments.
:param slug: The :attr:`~mediacore.models.media.Media.slug` to lookup
:param podcast_slug: The :attr:`~mediacore.models.podcasts.Podcast.slug`
for podcast this media belongs to. Although not necessary for
looking up the media, it tells us that the podcast slug was
specified in the URL and therefore we reached this action by the
preferred route.
:rtype dict:
:returns:
media
The :class:`~mediacore.model.media.Media` instance for display.
comment_form
The :class:`~mediacore.forms.comments.PostCommentForm` instance.
comment_form_action
``str`` comment form action
comment_form_values
``dict`` form values
next_episode
The next episode in the podcast series, if this media belongs to
a podcast, another :class:`~mediacore.model.media.Media`
instance.
"""
media = fetch_row(Media, slug=slug)
if media.podcast_id is not None:
# Always view podcast media from a URL that shows the context of the podcast
if url_for() != url_for(podcast_slug=media.podcast.slug):
redirect(podcast_slug=media.podcast.slug)
if media.fulltext:
search_terms = '%s %s' % (media.title, media.fulltext.tags)
related = Media.query.published()\
.options(orm.undefer('comment_count_published'))\
.filter(Media.id != media.id)\
.search(search_terms, bool=False)
else:
related = []
media.increment_views()
# Which style of 'likes' links has the admin selected?
# TODO: Add settings to control these options.
mediacore_likes = True
facebook_likes = False
return dict(
media = media,
related_media = related[:6],
comments = media.comments.published().all(),
comment_form = post_comment_form,
comment_form_action = url_for(action='comment', anchor=post_comment_form.id),
comment_form_values = kwargs,
mediacore_likes = mediacore_likes,
facebook_likes = facebook_likes,
)
开发者ID:kiberpipa,项目名称:mediacore,代码行数:58,代码来源:media.py
示例11: view
def view(self, slug, podcast_slug=None, **kwargs):
"""Display the media player, info and comments.
:param slug: The :attr:`~mediacore.models.media.Media.slug` to lookup
:param podcast_slug: The :attr:`~mediacore.models.podcasts.Podcast.slug`
for podcast this media belongs to. Although not necessary for
looking up the media, it tells us that the podcast slug was
specified in the URL and therefore we reached this action by the
preferred route.
:rtype dict:
:returns:
media
The :class:`~mediacore.model.media.Media` instance for display.
related_media
A list of :class:`~mediacore.model.media.Media` instances that
rank as topically related to the given media item.
comments
A list of :class:`~mediacore.model.comments.Comment` instances
associated with the selected media item.
comment_form_action
``str`` comment form action
comment_form_values
``dict`` form values
next_episode
The next episode in the podcast series, if this media belongs to
a podcast, another :class:`~mediacore.model.media.Media`
instance.
"""
media = fetch_row(Media, slug=slug)
request.perm.assert_permission(u'view', media.resource)
if media.podcast_id is not None:
# Always view podcast media from a URL that shows the context of the podcast
if url_for() != url_for(podcast_slug=media.podcast.slug):
redirect(podcast_slug=media.podcast.slug)
try:
media.increment_views()
DBSession.commit()
except OperationalError:
DBSession.rollback()
if request.settings['comments_engine'] == 'facebook':
response.facebook = Facebook(request.settings['facebook_appid'])
related_media = viewable_media(Media.query.related(media))[:6]
# TODO: finish implementation of different 'likes' buttons
# e.g. the default one, plus a setting to use facebook.
return dict(
media = media,
related_media = related_media,
comments = media.comments.published().all(),
comment_form_action = url_for(action='comment'),
comment_form_values = kwargs,
)
开发者ID:wafe,项目名称:mediadrop,代码行数:56,代码来源:media.py
示例12: fetch_engine
def fetch_engine(self, id, engine_type=None):
if id != 'new':
engine = fetch_row(StorageEngine, id)
else:
types = dict((cls.engine_type, cls) for cls in StorageEngine)
engine_cls = types.get(engine_type, None)
if not engine_cls:
redirect(controller='/admin/storage', action='index')
engine = engine_cls()
return engine
开发者ID:AshKash,项目名称:mediacore-community,代码行数:10,代码来源:storage.py
示例13: disable
def disable(self, id, **kwargs):
"""Disable a StorageEngine.
:param id: engine ID.
:type id: ``int``
:returns: Redirect back to :meth:`index` after success.
"""
engine = fetch_row(StorageEngine, id)
engine.enabled = False
redirect(action='index', id=None)
开发者ID:AshKash,项目名称:mediacore-community,代码行数:10,代码来源:storage.py
示例14: enable
def enable(self, id, **kwargs):
"""Enable a StorageEngine.
:param id: Storage ID.
:type id: ``int``
:returns: Redirect back to :meth:`index` after success.
"""
engine = fetch_row(StorageEngine, id)
engine.enabled = True
redirect(action="index", id=None)
开发者ID:greentv,项目名称:mediacore,代码行数:10,代码来源:storage.py
示例15: update_status
def update_status(self, id, update_button=None, publish_on=None, **values):
"""Update the publish status for the given media.
:param id: Media ID
:type id: ``int``
:param update_status: The text of the submit button which indicates
that the :attr:`~mediacore.model.media.Media.status` should change.
:type update_status: ``unicode`` or ``None``
:param publish_on: A date to set to
:attr:`~mediacore.model.media.Media.publish_on`
:type publish_on: :class:`datetime.datetime` or ``None``
:rtype: JSON dict
:returns:
success
bool
message
Error message, if unsuccessful
status_form
Rendered XHTML for the status form, updated to reflect the
changes made.
"""
media = fetch_row(Media, id)
new_slug = None
# Make the requested change assuming it will be allowed
if update_button == _('Review Complete'):
media.reviewed = True
elif update_button == _('Publish Now'):
media.publishable = True
media.publish_on = publish_on or datetime.now()
media.update_popularity()
# Remove the stub prefix if the user wants the default media title
if media.slug.startswith('_stub_'):
new_slug = get_available_slug(Media, media.slug[len('_stub_'):])
media.slug = new_slug
elif publish_on:
media.publish_on = publish_on
media.update_popularity()
# Verify the change is valid by re-determining the status
media.update_status()
DBSession.flush()
if request.is_xhr:
# Return the rendered widget for injection
status_form_xhtml = unicode(update_status_form.display(
action=url_for(action='update_status'), media=media))
return dict(
success = True,
status_form = status_form_xhtml,
slug = new_slug,
)
else:
redirect(action='edit')
开发者ID:RadioErewan,项目名称:mediacore,代码行数:55,代码来源:media.py
示例16: update_status
def update_status(self, id, status=None, publish_on=None, publish_until=None, **values):
"""Update the publish status for the given media.
:param id: Media ID
:type id: ``int``
:param update_status: The text of the submit button which indicates
that the :attr:`~mediacore.model.media.Media.status` should change.
:type update_status: ``unicode`` or ``None``
:param publish_on: A date to set to
:attr:`~mediacore.model.media.Media.publish_on`
:type publish_on: :class:`datetime.datetime` or ``None``
:param publish_until: A date to set to
:attr:`~mediacore.model.media.Media.publish_until`
:type publish_until: :class:`datetime.datetime` or ``None``
:rtype: JSON dict
:returns:
success
bool
message
Error message, if unsuccessful
status_form
Rendered XHTML for the status form, updated to reflect the
changes made.
"""
media = fetch_row(Media, id)
new_slug = None
# Make the requested change assuming it will be allowed
if status == 'unreviewed':
media.reviewed = True
elif status == 'draft':
self._publish_media(media, publish_on)
elif publish_on:
media.publish_on = publish_on
media.update_popularity()
elif publish_until:
media.publish_until = publish_until
# Verify the change is valid by re-determining the status
media.update_status()
DBSession.flush()
if request.is_xhr:
# Return the rendered widget for injection
status_form_xhtml = unicode(update_status_form.display(
action=url_for(action='update_status'), media=media))
return dict(
success = True,
status_form = status_form_xhtml,
slug = new_slug,
)
else:
redirect(action='edit')
开发者ID:kidrane,项目名称:mediacore-community,代码行数:54,代码来源:media.py
示例17: popularity_save
def popularity_save(self, **kwargs):
"""Save :class:`~mediacore.forms.admin.settings.PopularityForm`.
Updates the popularity for every media item based on the submitted
values.
"""
self._save(popularity_form, values=kwargs)
for m in Media.query:
m.update_popularity()
DBSession.add(m)
redirect(action='popularity')
开发者ID:AshKash,项目名称:mediacore-community,代码行数:11,代码来源:settings.py
示例18: disable
def disable(self, id, **kwargs):
"""Disable a PlayerPref.
:param id: Player ID.
:type id: ``int``
:returns: Redirect back to :meth:`index` after success.
"""
player = fetch_row(PlayerPrefs, id)
player.enabled = False
update_enabled_players()
redirect(action='index', id=None)
开发者ID:BlendedLearningCollaborative,项目名称:mediacore-community,代码行数:11,代码来源:players.py
示例19: comments_save
def comments_save(self, **kwargs):
"""Save :class:`~mediacore.forms.admin.settings.CommentsForm`."""
old_vulgarity_filter = c.settings['vulgarity_filtered_words'].value
self._save(comments_form, values=kwargs)
# Run the filter now if it has changed
if old_vulgarity_filter != c.settings['vulgarity_filtered_words'].value:
for comment in DBSession.query(Comment):
comment.body = filter_vulgarity(comment.body)
redirect(action='comments')
开发者ID:AshKash,项目名称:mediacore-community,代码行数:12,代码来源:settings.py
示例20: post_login
def post_login(self, came_from=None, **kwargs):
if not request.identity:
# The FriendlyForm plugin will always issue a redirect to
# /login/continue (post login url) even for failed logins.
# If 'came_from' is a protected page (i.e. /admin) we could just
# redirect there and the login form will be displayed again with
# our login error message.
# However if the user tried to login from the front page, this
# mechanism doesn't work so go to the login method directly here.
self._increase_number_of_failed_logins()
return self.login(came_from=came_from)
redirect(came_from or url_for('/admin'))
开发者ID:ajoythomas,项目名称:mediacore-community,代码行数:12,代码来源:login.py
注:本文中的mediacore.lib.helpers.redirect函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论