def patch_detail(self, request, **kwargs): """Allow patch request to update default_style. Request body must match this: { 'default_style': <resource_uri_to_style> } """ reason = 'Can only patch "default_style" field.' try: body = json.loads(request.body) if 'default_style' not in body: return http.HttpBadRequest(reason=reason) match = resolve(body['default_style']) style_id = match.kwargs['id'] api_name = match.kwargs['api_name'] resource_name = match.kwargs['resource_name'] if not (resource_name == 'styles' and api_name == 'api'): raise Exception() from geonode.qgis_server.models import QGISServerStyle style = QGISServerStyle.objects.get(id=style_id) layer_id = kwargs['id'] layer = Layer.objects.get(id=layer_id) except Exception: return http.HttpBadRequest(reason=reason) from geonode.qgis_server.views import default_qml_style request.method = 'POST' response = default_qml_style( request, layername=layer.name, style_name=style.name) if isinstance(response, TemplateResponse): if response.status_code == 200: return HttpResponse(status=200) return self.error_response(request, response.content)
def patch_detail(self, request, **kwargs): """Allow patch request to update default_style. Request body must match this: { 'default_style': <resource_uri_to_style> } """ reason = 'Can only patch "default_style" field.' try: body = json.loads(request.body) if 'default_style' not in body: return http.HttpBadRequest(reason=reason) match = resolve(body['default_style']) style_id = match.kwargs['id'] api_name = match.kwargs['api_name'] resource_name = match.kwargs['resource_name'] if not (resource_name == 'styles' and api_name == 'api'): raise Exception() from geonode.qgis_server.models import QGISServerStyle style = QGISServerStyle.objects.get(id=style_id) layer_id = kwargs['id'] layer = Layer.objects.get(id=layer_id) except BaseException: return http.HttpBadRequest(reason=reason) from geonode.qgis_server.views import default_qml_style request.method = 'POST' response = default_qml_style( request, layername=layer.name, style_name=style.name) if isinstance(response, TemplateResponse): if response.status_code == 200: return HttpResponse(status=200) return self.error_response(request, response.content)