• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python response.render_404函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mediagoblin.tools.response.render_404函数的典型用法代码示例。如果您正苦于以下问题:Python render_404函数的具体用法?Python render_404怎么用?Python render_404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了render_404函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: user_home

def user_home(request, page):
    """'Homepage' of a User()"""
    user = User.query.filter_by(username=request.matchdict['user']).first()
    if not user:
        return render_404(request)
    elif not user.has_privilege(u'active'):
        return render_to_response(
            request,
            'mediagoblin/user_pages/user_nonactive.html',
            {'user': user})

    cursor = MediaEntry.query.\
        filter_by(uploader = user.id,
                  state = u'processed').order_by(MediaEntry.created.desc())

    pagination = Pagination(page, cursor)
    media_entries = pagination()

    #if no data is available, return NotFound
    if media_entries == None:
        return render_404(request)

    user_gallery_url = request.urlgen(
        'mediagoblin.user_pages.user_gallery',
        user=user.username)

    return render_to_response(
        request,
        'mediagoblin/user_pages/user.html',
        {'user': user,
         'user_gallery_url': user_gallery_url,
         'media_entries': media_entries,
         'pagination': pagination})
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:33,代码来源:views.py


示例2: user_collection

def user_collection(request, page, url_user=None):
    """A User-defined Collection"""
    collection = Collection.query.filter_by(
        get_creator=url_user,
        slug=request.matchdict['collection']).first()

    if not collection:
        return render_404(request)

    cursor = collection.get_collection_items()

    pagination = Pagination(page, cursor)
    collection_items = pagination()

    # if no data is available, return NotFound
    # TODO: Should an empty collection really also return 404?
    if collection_items == None:
        return render_404(request)

    return render_to_response(
        request,
        'mediagoblin/user_pages/collection.html',
        {'user': url_user,
         'collection': collection,
         'collection_items': collection_items,
         'pagination': pagination})
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:26,代码来源:views.py


示例3: wrapper

    def wrapper(request, *args, **kwargs):
        user = request.db.User.find_one(
            {'username': request.matchdict['user']})

        if not user:
            return render_404(request)
        media = request.db.MediaEntry.find_one(
            {'slug': request.matchdict['media'],
             'state': u'processed',
             'uploader': user._id})

        # no media via slug?  Grab it via ObjectId
        if not media:
            try:
                media = request.db.MediaEntry.find_one(
                    {'_id': ObjectId(request.matchdict['media']),
                     'state': u'processed',
                     'uploader': user._id})
            except InvalidId:
                return render_404(request)

            # Still no media?  Okay, 404.
            if not media:
                return render_404(request)

        return controller(request, media=media, *args, **kwargs)
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:26,代码来源:decorators.py


示例4: activity_view

def activity_view(request):
    """ /<username>/activity/<id> - Display activity

    This should display a HTML presentation of the activity
    this is NOT an API endpoint.
    """
    # Get the user object.
    username = request.matchdict["username"]
    user = LocalUser.query.filter_by(username=username).first()

    activity_id = request.matchdict["id"]

    if request.user is None:
        return render_404(request)

    activity = Activity.query.filter_by(
        id=activity_id,
        author=user.id
    ).first()

    # There isn't many places to check that the public_id is filled so this
    # will do, it really should be, lets try and fix that if it isn't.
    activity.get_public_id(request.urlgen)

    if activity is None:
        return render_404(request)

    return render_to_response(
        request,
        "mediagoblin/api/activity.html",
        {"activity": activity}
    )
开发者ID:tofay,项目名称:mediagoblin,代码行数:32,代码来源:views.py


示例5: user_collection

def user_collection(request, page):
    """A User-defined Collection"""
    user = request.db.User.find_one({
            'username': request.matchdict['user'],
            'status': u'active'})
    if not user:
        return render_404(request)

    collection = request.db.Collection.find_one(
        {'slug': request.matchdict['collection']})

    cursor = request.db.CollectionItem.find(
        {'collection': collection.id})

    pagination = Pagination(page, cursor)
    collection_items = pagination()

    #if no data is available, return NotFound
    if collection_items == None:
        return render_404(request)

    return render_to_response(
        request,
        'mediagoblin/user_pages/collection.html',
        {'user': user,
         'collection': collection,
         'collection_items': collection_items,
         'pagination': pagination})
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:28,代码来源:views.py


示例6: activity_view

def activity_view(request):
    """ /<username>/activity/<id> - Display activity

    This should display a HTML presentation of the activity
    this is NOT an API endpoint.
    """
    # Get the user object.
    username = request.matchdict["username"]
    user = User.query.filter_by(username=username).first()

    activity_id = request.matchdict["id"]

    if request.user is None:
        return render_404(request)

    activity = Activity.query.filter_by(
        id=activity_id,
        author=user.id
    ).first()

    if activity is None:
        return render_404(request)

    return render_to_response(
        request,
        "mediagoblin/api/activity.html",
        {"activity": activity}
    )
开发者ID:piratas,项目名称:biblioteca,代码行数:28,代码来源:views.py


示例7: user_gallery

def user_gallery(request, page):
    """'Gallery' of a User()"""
    user = request.db.User.find_one({
            'username': request.matchdict['user'],
            'status': u'active'})
    if not user:
        return render_404(request)

    cursor = request.db.MediaEntry.find(
        {'uploader': user._id,
         'state': u'processed'}).sort('created', DESCENDING)

    pagination = Pagination(page, cursor)
    media_entries = pagination()

    #if no data is available, return NotFound
    if media_entries == None:
        return render_404(request)

    return render_to_response(
        request,
        'mediagoblin/user_pages/gallery.html',
        {'user': user,
         'media_entries': media_entries,
         'pagination': pagination})
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:25,代码来源:views.py


示例8: user_home

def user_home(request, page):
    """'Homepage' of a User()"""
    # TODO: decide if we only want homepages for active users, we can
    # then use the @get_active_user decorator and also simplify the
    # template html.
    user = User.query.filter_by(username=request.matchdict["user"]).first()
    if not user:
        return render_404(request)
    elif user.status != u"active":
        return render_to_response(request, "mediagoblin/user_pages/user.html", {"user": user})

    cursor = MediaEntry.query.filter_by(uploader=user.id, state=u"processed").order_by(MediaEntry.created.desc())

    pagination = Pagination(page, cursor)
    media_entries = pagination()

    # if no data is available, return NotFound
    if media_entries == None:
        return render_404(request)

    user_gallery_url = request.urlgen("mediagoblin.user_pages.user_gallery", user=user.username)

    return render_to_response(
        request,
        "mediagoblin/user_pages/user.html",
        {"user": user, "user_gallery_url": user_gallery_url, "media_entries": media_entries, "pagination": pagination},
    )
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:27,代码来源:views.py


示例9: wrapper

    def wrapper(request, *args, **kwargs):
        try:
            page = int(request.GET.get('page', 1))
            if page < 0:
                return render_404(request)
        except ValueError:
            return render_404(request)

        return controller(request, page=page, *args, **kwargs)
开发者ID:phaer,项目名称:mediagoblin,代码行数:9,代码来源:decorators.py


示例10: 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


示例11: wrapper

    def wrapper(request, *args, **kwargs):
        media = MediaEntry.query.filter_by(id=request.matchdict["media_id"], state=u"processed").first()
        # Still no media?  Okay, 404.
        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)

        return controller(request, media=media, *args, **kwargs)
开发者ID:praveen97uma,项目名称:goblin,代码行数:11,代码来源:decorators.py


示例12: verify_forgot_password

def verify_forgot_password(request):
    """
    Check the forgot-password verification and possibly let the user
    change their password because of it.
    """
    # get form data variables, and specifically check for presence of token
    formdata = _process_for_token(request)
    if not formdata['has_userid_and_token']:
        return render_404(request)

    formdata_token = formdata['vars']['token']
    formdata_userid = formdata['vars']['userid']
    formdata_vars = formdata['vars']

    # check if it's a valid Id
    try:
        user = request.db.User.find_one(
            {'_id': ObjectId(unicode(formdata_userid))})
    except InvalidId:
        return render_404(request)

    # check if we have a real user and correct token
    if ((user and user.fp_verification_key and
         user.fp_verification_key == unicode(formdata_token) and
         datetime.datetime.now() < user.fp_token_expire
         and user.email_verified and user.status == 'active')):

        cp_form = auth_forms.ChangePassForm(formdata_vars)

        if request.method == 'POST' and cp_form.validate():
            user.pw_hash = auth_lib.bcrypt_gen_password_hash(
                request.form['password'])
            user.fp_verification_key = None
            user.fp_token_expire = None
            user.save()

            messages.add_message(
                request,
                messages.INFO,
                _("You can now log in using your new password."))
            return redirect(request, 'mediagoblin.auth.login')
        else:
            return render_to_response(
                request,
                'mediagoblin/auth/change_fp.html',
                {'cp_form': cp_form})

    # in case there is a valid id but no user whit that id in the db
    # or the token expired
    else:
        return render_404(request)
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:51,代码来源:views.py


示例13: verify_email

def verify_email(request):
    """
    Email verification view

    validates GET parameters against database and unlocks the user account, if
    you are lucky :)
    """
    # If we don't have userid and token parameters, we can't do anything; 404
    if not 'userid' in request.GET or not 'token' in request.GET:
        return render_404(request)

    user = request.db.User.find_one(
        {'_id': ObjectId(unicode(request.GET['userid']))})

    if user and user.verification_key == unicode(request.GET['token']):
        user.status = u'active'
        user.email_verified = True
        user.verification_key = None

        user.save()

        messages.add_message(
            request,
            messages.SUCCESS,
            _("Your email address has been verified. "
              "You may now login, edit your profile, and submit images!"))
    else:
        messages.add_message(
            request,
            messages.ERROR,
            _('The verification key or user id is incorrect'))

    return redirect(
        request, 'mediagoblin.user_pages.user_home',
        user=user.username)
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:35,代码来源:views.py


示例14: verify_email

def verify_email(request):
    """
    Email verification view for changing email address
    """
    # If no token, we can't do anything
    if not "token" in request.GET:
        return render_404(request)

    # Catch error if token is faked or expired
    token = None
    try:
        token = get_timed_signer_url("mail_verification_token").loads(request.GET["token"], max_age=10 * 24 * 3600)
    except BadSignature:
        messages.add_message(request, messages.ERROR, _("The verification key or user id is incorrect."))

        return redirect(request, "index")

    user = User.query.filter_by(id=int(token["user"])).first()

    if user:
        user.email = token["email"]
        user.save()

        messages.add_message(request, messages.SUCCESS, _("Your email address has been verified."))

    else:
        messages.add_message(request, messages.ERROR, _("The verification key or user id is incorrect."))

    return redirect(request, "mediagoblin.user_pages.user_home", user=user.username)
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:29,代码来源:views.py


示例15: atom_feed

def atom_feed(request):
    """
    generates the atom feed with the newest images
    """
    user = User.query.filter_by(
        username = request.matchdict['user']).first()
    if not user or not user.has_privilege(u'active'):
        return render_404(request)

    cursor = MediaEntry.query.filter_by(
        uploader = user.id,
        state = u'processed').\
        order_by(MediaEntry.created.desc()).\
        limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)

    """
    ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI)
    """
    atomlinks = [{
           'href': request.urlgen(
               'mediagoblin.user_pages.user_home',
               qualified=True, user=request.matchdict['user']),
           'rel': 'alternate',
           'type': 'text/html'
           }]

    if mg_globals.app_config["push_urls"]:
        for push_url in mg_globals.app_config["push_urls"]:
            atomlinks.append({
                'rel': 'hub',
                'href': push_url})

    feed = AtomFeed(
               "MediaGoblin: Feed for user '%s'" % request.matchdict['user'],
               feed_url=request.url,
               id='tag:{host},{year}:gallery.user-{user}'.format(
                   host=request.host,
                   year=datetime.datetime.today().strftime('%Y'),
                   user=request.matchdict['user']),
               links=atomlinks)

    for entry in cursor:
        feed.add(entry.get('title'),
            entry.description_html,
            id=entry.url_for_self(request.urlgen, qualified=True),
            content_type='html',
            author={
                'name': entry.get_uploader.username,
                'uri': request.urlgen(
                    'mediagoblin.user_pages.user_home',
                    qualified=True, user=entry.get_uploader.username)},
            updated=entry.get('created'),
            links=[{
                'href': entry.url_for_self(
                    request.urlgen,
                    qualified=True),
                'rel': 'alternate',
                'type': 'text/html'}])

    return feed.get_response()
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:60,代码来源:views.py


示例16: user_gallery

def user_gallery(request, page, url_user=None):
    """'Gallery' of a User()"""
    tag = request.matchdict.get('tag', None)
    cursor = MediaEntry.query.filter_by(
        uploader=url_user.id,
        state=u'processed').order_by(MediaEntry.created.desc())

    # Filter potentially by tag too:
    if tag:
        cursor = cursor.filter(
            MediaEntry.tags_helper.any(
                MediaTag.slug == request.matchdict['tag']))

    # Paginate gallery
    pagination = Pagination(page, cursor)
    media_entries = pagination()

    #if no data is available, return NotFound
    # TODO: Should we really also return 404 for empty galleries?
    if media_entries == None:
        return render_404(request)

    return render_to_response(
        request,
        'mediagoblin/user_pages/gallery.html',
        {'user': url_user, 'tag': tag,
         'media_entries': media_entries,
         'pagination': pagination})
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:28,代码来源:views.py


示例17: atom_feed

def atom_feed(request):
    """
    generates the atom feed with the newest images
    """
    user = User.query.filter_by(username=request.matchdict["user"], status=u"active").first()
    if not user:
        return render_404(request)

    cursor = (
        MediaEntry.query.filter_by(uploader=user.id, state=u"processed")
        .order_by(MediaEntry.created.desc())
        .limit(ATOM_DEFAULT_NR_OF_UPDATED_ITEMS)
    )

    """
    ATOM feed id is a tag URI (see http://en.wikipedia.org/wiki/Tag_URI)
    """
    atomlinks = [
        {
            "href": request.urlgen("mediagoblin.user_pages.user_home", qualified=True, user=request.matchdict["user"]),
            "rel": "alternate",
            "type": "text/html",
        }
    ]

    if mg_globals.app_config["push_urls"]:
        for push_url in mg_globals.app_config["push_urls"]:
            atomlinks.append({"rel": "hub", "href": push_url})

    feed = AtomFeed(
        "MediaGoblin: Feed for user '%s'" % request.matchdict["user"],
        feed_url=request.url,
        id="tag:{host},{year}:gallery.user-{user}".format(
            host=request.host, year=datetime.datetime.today().strftime("%Y"), user=request.matchdict["user"]
        ),
        links=atomlinks,
    )

    for entry in cursor:
        feed.add(
            entry.get("title"),
            entry.description_html,
            id=entry.url_for_self(request.urlgen, qualified=True),
            content_type="html",
            author={
                "name": entry.get_uploader.username,
                "uri": request.urlgen(
                    "mediagoblin.user_pages.user_home", qualified=True, user=entry.get_uploader.username
                ),
            },
            updated=entry.get("created"),
            links=[
                {"href": entry.url_for_self(request.urlgen, qualified=True), "rel": "alternate", "type": "text/html"}
            ],
        )

    return feed.get_response()
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:57,代码来源:views.py


示例18: wrapper

    def wrapper(request, *args, **kwargs):
        media = MediaEntry.query.filter_by(
                id=request.matchdict['media'],
                state=u'processed').first()
        # Still no media?  Okay, 404.
        if not media:
            return render_404(request)

        return controller(request, media=media, *args, **kwargs)
开发者ID:imclab,项目名称:mediagoblin,代码行数:9,代码来源:decorators.py


示例19: media_preview_comment

def media_preview_comment(request):
    """Runs a comment through markdown so it can be previewed."""
    # If this isn't an ajax request, render_404
    if not request.is_xhr:
        return render_404(request)

    comment = unicode(request.form["comment_content"])
    cleancomment = {"content": cleaned_markdown_conversion(comment)}

    return Response(json.dumps(cleancomment))
开发者ID:aurelienmaury,项目名称:JoshuaGoblin,代码行数:10,代码来源:views.py


示例20: blog_delete

def blog_delete(request, **kwargs):
    """
    Deletes a blog and media entries, tags associated with it.
    """
    url_user = request.matchdict.get('user')
    owner_user = request.db.LocalUser.query.filter(
        LocalUser.username==url_user
    ).first()

    blog_slug = request.matchdict.get('blog_slug', None)
    blog = get_blog_by_slug(request, blog_slug, author=owner_user.id)
    if not blog:
        return render_404(request)

    form = blog_forms.ConfirmDeleteForm(request.form)
    if request.user.id == blog.author or request.user.has_privilege(u'admin'):
        if request.method == 'POST' and form.validate():
            if form.confirm.data is True:
                blog.delete()
                messages.add_message(
                    request,
                    messages.SUCCESS,
                    _('You deleted the Blog.'))
                return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
                        user=request.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(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
                        user=request.user.username)
        else:
            if request.user.has_privilege(u'admin'):
                messages.add_message(
                    request,
                    messages.WARNING,
                    _("You are about to delete another user's Blog. "
                      "Proceed with caution."))
            return render_to_response(
            request,
            'mediagoblin/blog/blog_confirm_delete.html',
            {'blog':blog,
            'form':form
            })
    else:
        messages.add_message(
            request,
            messages.ERROR,
            _("The blog was not deleted because you have no rights."))
        return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
        user=request.user.username)
开发者ID:ausbin,项目名称:mediagoblin,代码行数:53,代码来源:views.py



注:本文中的mediagoblin.tools.response.render_404函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python response.render_to_response函数代码示例发布时间:2022-05-27
下一篇:
Python response.redirect_obj函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap