views:

39

answers:

1

İ ned to write a code sniplet that enables to disable connection to some parts of a site. Admin and the mainpage will be displayable, but user section (which uses ajax) will be displayed, but can not be used (vith a transparent div set over the page). Also there is a few pages which will be disabled.

my logic is that, i write a middleware,

def process_request(self, request):
    if ayar.tonline_kapali:
        url_parcalari = request.path.split('/')
        if url_parcalari[0] not in settings.BAGIMSIZ_URLLER:
            if not request.is_ajax():
                return render_to_response('bakim_modu.html')
    else:
        return None

that code let me to display a "site closed" message for the urls not in BAGIMSIZ_URLLER (which contains urls that will be accessible)

But i do not figure out how can i solve the problem about ajax pages... i need to set a header or something to the response and need to check it in the template.

+1  A: 

Hi, here documentation for process_view Usage is simple. process_view is called just before Django calls the view, and get few arguments: request - Request object view_func - View function view_args - Arguments view_kwargs - Keyword arguments

Which example do you need?

Saff
I need to pass some arguments in a dictionaty like format, like {'system_status': 'off'} or like. and check the value in the template (if possible) or in the view and place a div over the page , so user can not do anything but see the message. Page uses ajax as i said, and refreshes every few seconds, so as long as 'system_status' is off, page winn not be functionable, but visible.
FallenAngel
So, you can modify any arguments of view.You have:view_args - Argumentsview_kwargs - Keyword argumentsyou can edit them and send to you view, and check some parameters in you view...or for example create templatetag for your views which will be check parameters sended by you middleware.
Saff