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()))
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())
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())
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)
def post(self, request, *args, **kwargs): return Response("(POST) It works on FlaskCBV!")
def get(self, request, *args, **kwargs): return Response("(GET) It works on FlaskCBV!")
def get(self, request, *args, **kwargs): data = self.render_template(*args, **kwargs) return Response(data)
def dispatch(self, *args, **kwargs): Sessions().delete(self.request.user.id) return Response(redirect(url_for('admin:login')))
def helper_response(self): return Response(self.helper())
def form_invalid(self, form, *args, **kwargs): kwargs['form'] = form data = self.render_template(*args, **kwargs) return Response(data)
def page_not_found(e): return Response( """{"errno":-1,"error":"notfound","details":"undefined handler url"}""" ).render(), 404
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)
def dispatch(self, request, *args, **kwargs): answ = self.get_as_json( details="you should see 'testvar' variable in this answer") return Response(answ)
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())