当前位置: 首页>>代码示例>>Python>>正文


Python response.render_404函数代码示例

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


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


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