2017-06-20 14:02:30 +02:00
|
|
|
from functools import wraps
|
|
|
|
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.shortcuts import render
|
|
|
|
from django.views.decorators.cache import never_cache
|
|
|
|
|
|
|
|
from c3nav.editor.models import ChangeSet
|
|
|
|
|
|
|
|
|
2017-07-05 16:17:19 +02:00
|
|
|
def sidebar_view(func=None, select_related=None):
|
|
|
|
if func is None:
|
|
|
|
def wrapped(inner_func):
|
|
|
|
return sidebar_view(inner_func, select_related)
|
|
|
|
return wrapped
|
|
|
|
|
2017-06-20 14:02:30 +02:00
|
|
|
@wraps(func)
|
|
|
|
def with_ajax_check(request, *args, **kwargs):
|
2017-07-05 16:17:19 +02:00
|
|
|
request.changeset = ChangeSet.get_for_request(request, select_related)
|
2017-06-20 14:02:30 +02:00
|
|
|
|
|
|
|
response = func(request, *args, **kwargs)
|
|
|
|
if request.is_ajax() or 'ajax' in request.GET:
|
|
|
|
if isinstance(response, HttpResponseRedirect):
|
|
|
|
return render(request, 'editor/redirect.html', {'target': response['location']})
|
|
|
|
response.write(render(request, 'editor/fragment_nav.html', {}).content)
|
|
|
|
return response
|
|
|
|
if isinstance(response, HttpResponseRedirect):
|
|
|
|
return response
|
|
|
|
return render(request, 'editor/map.html', {'content': response.content})
|
|
|
|
return never_cache(with_ajax_check)
|