Example #1
0
    def not_found(self, req):

        """
        Use this when you KNOW you should reply with a 404.

        Otherwise, just return None out of the route method and let the
        NotFound handler catch the request.

        """

        #Determine what we return based on request type
        if req.is_AJAX:
            resp = Response.plain("404 NOT FOUND")

        if req.is_JSON:
            resp = Response.json(dict(
                reply_timestamp=datetime.datetime.now(),
                message="404 NOT FOUND '{0}'".format(req.line_one),
                success=False))

        else:
            resp = Response.tmpl(self.four_zero_four_template)

        resp.status = '404 NOT FOUND'

        return resp
Example #2
0
    def prompt_for_login(self, req):

        # if ajax request, relative redirect won't work well
        # throw 401 error for now until we can figure out
        # better way to do it.

        # 401 error will be caught by jquery ajax error handler
        if req.is_AJAX:
            resp = Response.plain("You have to log in first!")

            resp.status = '401 UNAUTHORIZED'

        if req.is_JSON:
            resp = Response.json(dict(
                reply_timestamp=datetime.datetime.now(),
                message="You have to log in first!",
                success=False))

            resp.status = '401 UNAUTHORIZED'


        else:
            resp = Response.relative_redirect('/login',
                'You have to log in first!')

            # Redirect back to the page the person is hitting right now.
            resp.set_redirect_cookie(req.address_bar)

        return resp
Example #3
0
    def not_found(self, req):

        """
        Use this when you KNOW you should reply with a 404.

        Otherwise, just return None out of the route method and let the
        NotFound handler catch the request.

        """

        #Determine what we return based on request type
        if req.is_AJAX:
            resp = Response.plain("404 NOT FOUND")

        else:
            resp = Response.tmpl(self.four_zero_four_template)

        resp.status = '404 NOT FOUND'

        return resp