Exemplo n.º 1
0
    def dispatch(self, request, *args, **kwargs):
        try:
            self.__json_indent = int(request.args['json_indent'])
        except:
            self.__json_indent = None

        try:
            r = super(JSONView, self).dispatch(request, *args, **kwargs)
            if self.is_helper:
                return r
            return Response(self.get_as_json())
        except AbortEx as err:
            return Response(
                json.dumps(err.errdata, indent=self.get_json_indent()))
Exemplo n.º 2
0
    def post(self, *args, **kwargs):
        try:
            login = self.get_argument_smart('username',
                                            as_get=False,
                                            as_post=True,
                                            as_session=False,
                                            as_cookie=False)
            passwd = self.get_argument_smart('passwd',
                                             as_get=False,
                                             as_post=True,
                                             as_session=False,
                                             as_cookie=False)
        except Exception as err:
            abort(403)

        try:
            passwd = sha.new(passwd).hexdigest()
        except:
            abort(403)
        user = session.query(Users).filter(Users.login == login).filter(
            Users.passwd == passwd).first()
        if user is None:
            abort(403)

        flask_session['session'] = Sessions().create(user.id)

        return Response(self.get_as_json())
Exemplo n.º 3
0
    def get(self, *args, **kwargs):
        try:
            self.__days = self.get_argument_smart('days')
        except:
            self.__days = None

        try:
            self.__json_indent = int(self.request.args['json_indent'])
        except:
            self.__json_indent = None

        super(calendDataView, self).get(*args, **kwargs)

        return Response(self.get_as_json())
Exemplo n.º 4
0
    def prepare(self, *args, **kwargs):
        if not self.check_session():
            response = ResponseRedirect(url_for('auth:login'))
            return response.render(headers=self.get_headers())

        ## Check for access to default group:
        access_group = self.get_access_group()
        if access_group is not None and not self.check_access(access_group):

            ## Render template:
            body = render_template('403.tpl')

            ## Make flaskCBV Response() object:
            response = Response(body)

            ## Make Flask response object with status_code == 403:
            r = response.render(headers=self.get_headers())
            r.status_code = 403
            return r

        return super(AccessMixin, self).prepare(*args, **kwargs)
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     return Response("(POST) It works on FlaskCBV!")
Exemplo n.º 6
0
 def get(self, request, *args, **kwargs):
     return Response("(GET) It works on FlaskCBV!")
Exemplo n.º 7
0
 def get(self, request, *args, **kwargs):
     data = self.render_template(*args, **kwargs)
     return Response(data)
Exemplo n.º 8
0
 def dispatch(self, *args, **kwargs):
     Sessions().delete(self.request.user.id)
     return Response(redirect(url_for('admin:login')))
Exemplo n.º 9
0
 def helper_response(self):
     return Response(self.helper())
Exemplo n.º 10
0
 def form_invalid(self, form, *args, **kwargs):
     kwargs['form'] = form
     data = self.render_template(*args, **kwargs)
     return Response(data)
Exemplo n.º 11
0
def page_not_found(e):
    return Response(
        """{"errno":-1,"error":"notfound","details":"undefined handler url"}"""
    ).render(), 404
Exemplo n.º 12
0
 def dispatch(self, request, *args, **kwargs):
     answ = self.json_error(
         error='test_error',
         details='If you see this error, then view is worked!:)')
     return Response(answ)
Exemplo n.º 13
0
    def dispatch(self, request, *args, **kwargs):
        answ = self.get_as_json(
            details="you should see 'testvar' variable in this answer")

        return Response(answ)
Exemplo n.º 14
0
 def dispatch(self, request, *args, **kwargs):
     try: self.__json_indent = int(request.args['json_indent'])
     except: self.__json_indent = None
     return Response(self.get_as_json())