Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        if 'action' in request.POST:
            action = 'action_%s' % request.POST['action'].strip()
            if self.ACTION_RE.match(action):
                action_callable = getattr(self, action, None)
                if action_callable and isinstance(
                        action_callable,
                        collections.Callable) and self.user_can_call(
                            request, action):
                    self.populate_context(request, *args, **kwargs)
                    if isinstance(self.view_ctx.response, HttpResponse):
                        return self.view_ctx.response
                    else:
                        response = action_callable(request, request.POST,
                                                   *args, **kwargs)
                        if isinstance(response, HttpResponse):
                            return response
                        else:
                            return render_template_response(
                                request,
                                self.view_ctx,
                                self.template_name,
                                no_cache=self.no_cache,
                                minify_html=self.minify_html,
                                extra_ctx=self.extra_ctx)

        raise Http404()
Ejemplo n.º 2
0
    def dispatch(self, request, *args, **kwargs):
        self.state = ResponseState(request, *args, **kwargs)
        self.template_name = self.get_template_name()
        self.state.page_title = self.page_title
        self.state.page_description = self.page_description
        self.state.response_type = 'html'

        try:
            for view_middleware in self.view_middlewares:
                view_middleware.process_pre_view(self)

            self.init_hook()

            # somewhat disingenuous - call super on dispatch. this is just to let it resolve method names the way it do
            #   we aren't actually looking for any kind of full response object yet, just to build self.state (different return type)
            super(StatesAndHooksView, self).dispatch(request)

            for view_middleware in self.view_middlewares:
                view_middleware.process_post_view(self)

            if self.state.response_type == 'html':
                # here we equate 'html' and 'template'
                self.state.template_ctx = {}
                for view_middleware in self.view_middlewares:
                    view_middleware.process_pre_template(self)
                self.template_hook()
                for view_middleware in self.view_middlewares:
                    view_middleware.process_post_template(self)
                response = render_template_response(
                    request,
                    self.state.template_ctx,
                    self.template_name,
                    no_cache=self.no_cache,
                    minify_html=self.minify_html)

                return response
            elif self.state.response_type == 'json':
                self.state.json_ctx = {}
                self.json_hook()
                return HttpResponse(json.dumps(self.state.json_ctx),
                                    content_type='application/json')
            elif self.state.response_type == 'redirect':
                return HttpResponseRedirect(self.state.redirect_url)
            else:
                raise Exception('Unrecognized response_type %s',
                                self.state.response_type)

        except EarlyReturn, er:
            return er.response
Ejemplo n.º 3
0
Archivo: views.py Proyecto: 0xMF/alpha
    def post(self, request, *args, **kwargs):
        if 'action' in request.POST:
            action = 'action_%s' % request.POST['action'].strip()
            if self.ACTION_RE.match(action):
                action_callable = getattr(self, action, None)
                if action_callable and isinstance(action_callable, collections.Callable) and self.user_can_call(request, action):
                    self.populate_context(request, *args, **kwargs)
                    if isinstance(self.view_ctx.response, HttpResponse):
                        return self.view_ctx.response
                    else:
                        response = action_callable(request, request.POST, *args, **kwargs)
                        if isinstance(response, HttpResponse):
                            return response
                        else:
                            return render_template_response(request, self.view_ctx, self.template_name, no_cache=self.no_cache,
                                                            minify_html=self.minify_html, extra_ctx=self.extra_ctx)

        raise Http404()
Ejemplo n.º 4
0
Archivo: views.py Proyecto: 0xMF/alpha
    def get(self, request, *args, **kwargs):
        # right now, I'm still feeling out how these pieces will be put together but the current simple migration path
        # is that populate_context is essentially the same interface as the views we currently have. As I figure out more
        # refactoring, this will change
        # right now, i'm calling update_ctx just so i can still return dicts from populate_context i used to
        self.populate_context(request, *args, **kwargs)

        if self.set_csrf_token:
            # Ensure a CSRF Cookie
            get_token(request)

        # If this has been set, we want to take this path even if it's [] so a pure falsey check won't work
        if self.view_ctx.response is not None:
            return self.view_ctx.response
        else:
            return render_template_response(request, self.view_ctx, self.template_name, no_cache=self.no_cache,
                                            minify_html=self.minify_html, extra_ctx=self.extra_ctx,
                                            status_code=self.view_ctx.status_code)
Ejemplo n.º 5
0
Archivo: views.py Proyecto: 0xMF/alpha
    def dispatch(self, request, *args, **kwargs):
        self.state = ResponseState(request, *args, **kwargs)
        self.template_name = self.get_template_name()
        self.state.page_title = self.page_title
        self.state.page_description = self.page_description
        self.state.response_type = 'html'

        try:
            for view_middleware in self.view_middlewares:
                view_middleware.process_pre_view(self)

            self.init_hook()

            # somewhat disingenuous - call super on dispatch. this is just to let it resolve method names the way it do
            #   we aren't actually looking for any kind of full response object yet, just to build self.state (different return type)
            super(StatesAndHooksView, self).dispatch(request)

            for view_middleware in self.view_middlewares:
                view_middleware.process_post_view(self)

            if self.state.response_type == 'html':
                # here we equate 'html' and 'template'
                self.state.template_ctx = {}
                for view_middleware in self.view_middlewares:
                    view_middleware.process_pre_template(self)
                self.template_hook()
                for view_middleware in self.view_middlewares:
                    view_middleware.process_post_template(self)
                response = render_template_response(request, self.state.template_ctx, self.template_name, no_cache=self.no_cache,
                                                    minify_html=self.minify_html)

                return response
            elif self.state.response_type == 'json':
                self.state.json_ctx = {}
                self.json_hook()
                return HttpResponse(json.dumps(self.state.json_ctx), content_type='application/json')
            elif self.state.response_type == 'redirect':
                return HttpResponseRedirect(self.state.redirect_url)
            else:
                raise Exception('Unrecognized response_type %s', self.state.response_type)

        except EarlyReturn, er:
            return er.response
Ejemplo n.º 6
0
    def get(self, request, *args, **kwargs):
        # right now, I'm still feeling out how these pieces will be put together but the current simple migration path
        # is that populate_context is essentially the same interface as the views we currently have. As I figure out more
        # refactoring, this will change
        # right now, i'm calling update_ctx just so i can still return dicts from populate_context i used to
        self.populate_context(request, *args, **kwargs)

        if self.set_csrf_token:
            # Ensure a CSRF Cookie
            get_token(request)

        # If this has been set, we want to take this path even if it's [] so a pure falsey check won't work
        if self.view_ctx.response is not None:
            return self.view_ctx.response
        else:
            return render_template_response(
                request,
                self.view_ctx,
                self.template_name,
                no_cache=self.no_cache,
                minify_html=self.minify_html,
                extra_ctx=self.extra_ctx,
                status_code=self.view_ctx.status_code)
Ejemplo n.º 7
0
def rate_limit_handler(request, *args, **kwargs):
    response = render_template_response(request, {}, 'pau/429.html')
    response.status_code = 429
    return response
Ejemplo n.º 8
0
def rate_limit_handler(request, *args, **kwargs):
    response = render_template_response(request, {}, '429.html')
    response.status_code = 429
    return response