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


Python HTTPFound.encode_content方法代码示例

本文整理汇总了Python中pyramid.httpexceptions.HTTPFound.encode_content方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPFound.encode_content方法的具体用法?Python HTTPFound.encode_content怎么用?Python HTTPFound.encode_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.httpexceptions.HTTPFound的用法示例。


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

示例1: ClientView

# 需要导入模块: from pyramid.httpexceptions import HTTPFound [as 别名]
# 或者: from pyramid.httpexceptions.HTTPFound import encode_content [as 别名]
class ClientView(BaseUserViewCallable):
    def __init__(self, request):
        self.usermodel = request.usermodel
        super(ClientView, self).__init__(request)
        if request.method == 'POST':
            self.handle_post()
        else:
            self.handle_get()

    def handle_get(self):
        request = self.request
        view = request.view_name
        subpath = request.subpath
        settings = self.get_app_settings()
        if not view:
            route = request.matched_route.name
            if route == 'home':
                self.get_main()
                return
            elif route == 'apps':
                self.get_main(appname=request.matchdict['appname'])
                return
            else:
                raise HTTPNotFound, "no such animal"
        elif view in ['login', 'logout']:
            if view == 'logout':
                return self.handle_logout()
            elif view == 'login':
                appname = settings.get('default.js.login_app', 'login')
                self.get_main(appname=appname, view=view)
                return
        elif view == 'admin':
            appname = settings.get('default.js.admin_app', 'admin')
            basecolor = settings.get('default.admin.basecolor', 'DarkSeaGreen')
            self.get_main(appname=appname, basecolor=basecolor, view=view)
        else:
            raise HTTPNotFound, 'no way'
        
    def get_main(self, appname=None, basecolor=None, view=None):
        settings = self.get_app_settings()
        if appname is None:
            appname = settings.get('default.js.mainapp', 'frontdoor')
        content = make_page(appname, settings, basecolor=basecolor, view=view)
        self.response = Response(body=content)
        self.response.encode_content()
        
    def handle_login(self, post):
        if check_login_form(self.request):
            username = post['username']
            headers = remember(self.request, username)
        home = self.request.route_url('home')
        self.response = HTTPFound(home)


    def handle_logout(self):
        headers = forget(self.request)
        if 'user' in self.request.session:
            del self.request.session['user']
        while self.request.session.keys():
            key = self.request.session.keys()[0]
            del  self.request.session[key]
        location = self.request.route_url('home')
        self.response = HTTPFound(location=location, headers=headers)

    def handle_post(self):
        request = self.request
        view = request.view_name
        post = request.POST
        if view == 'login':
            return self.handle_login(post)
        elif view == 'logout':
            return self.handle_logout()
        else:
            raise HTTPNotFound, 'nope'
开发者ID:joelsefus,项目名称:paella,代码行数:76,代码来源:client.py

示例2: FrontDoorView

# 需要导入模块: from pyramid.httpexceptions import HTTPFound [as 别名]
# 或者: from pyramid.httpexceptions.HTTPFound import encode_content [as 别名]
class FrontDoorView(BasicView):
    def __init__(self, request):
        super(FrontDoorView, self).__init__(request)
        if request.method == 'POST':
            self.handle_post()
        else:
            self.handle_get()
            
    def handle_get(self):
        request = self.request
        view = request.view_name
        subpath = request.subpath
        if not view:
            route = self.request.matched_route.name
            if route == 'home':
                self.response = HTTPFound('/frontdoor')
                return
            raise HTTPNotFound()
        elif view in ['login', 'logout']:
            # This breaks GET has no side effects
            if view == 'logout':
                return self.handle_logout({})
            self.response = HTTPFound('/frontdoor')
            return
        elif view == 'frontdoor':
            if not len(subpath):
                template = 'trumpet:templates/webview-app.mako'
                settings = self.get_app_settings()
                basecolor = settings['default.css.basecolor']
                env = dict(appname='frontdoor', basecolor=basecolor)
                content = render(template, env)
                self.response = Response(body=content)
                self.response.encode_content()
            else:
                assetpath = 'trumpet:static/apps/frontdoor'
                asset = os.path.join(assetpath, *subpath)
                self.response = static_asset_response(request, asset)
        else:
            self.response = HTTPNotFound()

    def handle_login(self, post):
        if check_login_form(self.request):
            username = post['username']
            headers = remember(self.request, username)
        self.response = HTTPFound('/frontdoor')


    def handle_logout(self, post):
        headers = forget(self.request)
        if 'user' in self.request.session:
            del self.request.session['user']
        while self.request.session.keys():
            key = self.request.session.keys()[0]
            del  self.request.session[key]
        location = self.request.route_url('home')
        self.response = HTTPFound(location=location, headers=headers)
        
    

    def handle_post(self):
        request = self.request
        view = request.view_name
        subpath = request.subpath
        post = request.POST
        if view == 'login':
            return self.handle_login(post)
        elif view == 'login':
            return self.handle_logout(post)
        else:
            return self.handle_login(post)
开发者ID:nkabir,项目名称:trumpet,代码行数:72,代码来源:frontdoor.py


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