def with_ajax_check(request, *args, **kwargs): if not can_access_editor(request): raise PermissionDenied request.changeset = ChangeSet.get_for_request(request, select_related) ajax = request.is_ajax() or 'ajax' in request.GET if not ajax: request.META.pop('HTTP_IF_NONE_MATCH', None) response = func(request, *args, **kwargs) if ajax: if isinstance(response, HttpResponseRedirect): return render(request, 'editor/redirect.html', {'target': response['location']}) if not isinstance(response, HttpResponseNotModified): response.write( render(request, 'editor/fragment_nav.html', {}).content) response['Cache-Control'] = 'no-cache' patch_vary_headers(response, ('X-Requested-With', )) return response if isinstance(response, HttpResponseRedirect): return response response = render(request, 'editor/map.html', {'content': response.content.decode()}) response['Cache-Control'] = 'no-cache' patch_vary_headers(response, ('X-Requested-With', )) return response
def current(self, request, *args, **kwargs): changeset = ChangeSet.get_for_request(request) return Response({ 'direct_editing': changeset.direct_editing, 'changeset': changeset.serialize() if changeset.pk else None, })
def set_changeset_author_on_login(sender, user, request, **kwargs): try: changeset = request.changeset except AttributeError: changeset = ChangeSet.get_for_request(request, as_logged_out=True) if changeset.pk is not None: changeset.author = user changeset.save()
def etag_func(request, *args, **kwargs): try: changeset = request.changeset except AttributeError: changeset = ChangeSet.get_for_request(request) request.changeset = changeset return ( get_language() + ':' + changeset.raw_cache_key_by_changes + ':' + AccessPermission.cache_key_for_request(request, with_update=False) + ':' + str(request.user.pk or 0))
def etag_func(request, *args, **kwargs): try: changeset = request.changeset except AttributeError: changeset = ChangeSet.get_for_request(request) request.changeset = changeset return (get_language() + ':' + changeset.raw_cache_key_by_changes + ':' + AccessPermission.cache_key_for_request(request, with_update=False) + ':' + str(request.user.pk or 0) + ':' + str(int(request.user_permissions.can_access_base_mapdata)) + ':' + ','.join(str(i) for i in request.user_space_accesses) + ':' + str(int(request.user.is_superuser)))
def wrapped_func(self, request, *args, **kwargs): try: changeset = request.changeset except AttributeError: changeset = ChangeSet.get_for_request(request) request.changeset = changeset update_cache_key = request.changeset.raw_cache_key_without_changes update_cache_key_match = request.GET.get('update_cache_key') == update_cache_key return func(self, request, *args, update_cache_key=update_cache_key, update_cache_key_match=update_cache_key_match, **kwargs)
def etag_func(request, *args, **kwargs): try: changeset = request.changeset except AttributeError: changeset = ChangeSet.get_for_request(request) request.changeset = changeset return (get_language() + ':' + changeset.raw_cache_key_by_changes + ':' + AccessPermission.cache_key_for_request( request, with_update=False) + ':' + str(request.user.pk or 0) + ':' + str(int(request.user_permissions.can_access_base_mapdata)) + ':' + ','.join(str(i) for i in request.user_space_accesses) + ':' + str(int(request.user.is_superuser)))
def direct_editing(self, request, *args, **kwargs): # django-rest-framework doesn't automatically do this for logged out requests SessionAuthentication().enforce_csrf(request) if not ChangeSet.can_direct_edit(request): raise PermissionDenied(_('You don\'t have the permission to activate direct editing.')) changeset = ChangeSet.get_for_request(request) if changeset.pk is not None: raise PermissionDenied(_('You cannot activate direct editing if you have an active changeset.')) request.session['direct_editing'] = True return Response({ 'success': True, })
def wrapped(request, *args, api=False, **kwargs): if api and not api_hybrid: raise Exception('API call on a view without api_hybrid!') if not can_access_editor(request): raise PermissionDenied request.changeset = ChangeSet.get_for_request(request, select_related) if api: request.is_delete = request.method == 'DELETE' return call_api_hybrid_view_for_api(func, request, *args, **kwargs) ajax = request.is_ajax() or 'ajax' in request.GET if not ajax: request.META.pop('HTTP_IF_NONE_MATCH', None) if api_hybrid: response = call_api_hybrid_view_for_html(func, request, *args, **kwargs) else: response = func(request, *args, **kwargs) if ajax: if isinstance(response, HttpResponseRedirect): return render(request, 'editor/redirect.html', {'target': response['location']}) if not isinstance(response, HttpResponseNotModified): response.write( render(request, 'editor/fragment_nav.html', {}).content) if request.mobileclient: response.write( render(request, 'editor/fragment_mobileclientdata.html', {}).content) response['Cache-Control'] = 'no-cache' patch_vary_headers(response, ('X-Requested-With', )) return response if isinstance(response, HttpResponseRedirect): return response response = render(request, 'editor/map.html', {'content': response.content.decode()}) response['Cache-Control'] = 'no-cache' patch_vary_headers(response, ('X-Requested-With', )) return response
def wrapped(request, *args, api=False, **kwargs): if api and not api_hybrid: raise Exception('API call on a view without api_hybrid!') if not can_access_editor(request): raise PermissionDenied request.changeset = ChangeSet.get_for_request(request, select_related) if api: request.is_delete = request.method == 'DELETE' return call_api_hybrid_view_for_api(func, request, *args, **kwargs) ajax = request.is_ajax() or 'ajax' in request.GET if not ajax: request.META.pop('HTTP_IF_NONE_MATCH', None) if api_hybrid: response = call_api_hybrid_view_for_html(func, request, *args, **kwargs) else: response = func(request, *args, **kwargs) if ajax: if isinstance(response, HttpResponseRedirect): return render(request, 'editor/redirect.html', {'target': response['location']}) if not isinstance(response, HttpResponseNotModified): response.write(render(request, 'editor/fragment_nav.html', {}).content) if request.mobileclient: response.write(render(request, 'editor/fragment_mobileclientdata.html', {}).content) response['Cache-Control'] = 'no-cache' patch_vary_headers(response, ('X-Requested-With', )) return response if isinstance(response, HttpResponseRedirect): return response response = render(request, 'editor/map.html', {'content': response.content.decode()}) response['Cache-Control'] = 'no-cache' patch_vary_headers(response, ('X-Requested-With', )) return response
def current(self, request, *args, **kwargs): if not can_access_editor(request): return PermissionDenied changeset = ChangeSet.get_for_request(request) return Response(changeset.serialize())
def current(self, request, *args, **kwargs): changeset = ChangeSet.get_for_request(request) return Response(changeset.serialize())