コード例 #1
0
ファイル: views.py プロジェクト: iobis/geonode
def invalidate_tileddataset_cache(request):
    from geonode.geoserver.security import set_geowebcache_invalidate_cache
    uuid = request.POST['uuid']
    resource = get_object_or_404(ResourceBase, uuid=uuid)
    can_change_data = request.user.has_perm('change_resourcebase', resource)
    layer = Dataset.objects.get(id=resource.id)
    if layer and can_change_data:
        try:
            set_geowebcache_invalidate_cache(layer.alternate or layer.typename)
        except Exception:
            tb = traceback.format_exc()
            logger.debug(tb)
        return HttpResponse(json.dumps({
            'success':
            'ok',
            'message':
            _('GeoWebCache Tiled Layer Emptied!')
        }),
                            status=200,
                            content_type='text/plain')
    else:
        return HttpResponse(json.dumps({
            'success':
            'false',
            'message':
            _('You cannot modify this resource!')
        }),
                            status=200,
                            content_type='text/plain')
コード例 #2
0
def dataset_append_replace_view(request, layername, template, action_type):
    try:
        layer = _resolve_dataset(request, layername,
                                 'base.change_resourcebase',
                                 _PERMISSION_MSG_MODIFY)
    except PermissionDenied:
        return HttpResponse("Not allowed", status=403)
    except Exception:
        raise Http404("Not found")
    if not layer:
        raise Http404("Not found")

    if request.method == 'GET':
        ctx = {
            'charsets': CHARSETS,
            'resource': layer,
            'is_featuretype': layer.is_vector(),
            'is_dataset': True,
        }
        return render(request, template, context=ctx)
    elif request.method == 'POST':
        form = LayerUploadForm(request.POST, request.FILES)
        out = {}
        if form.is_valid():
            try:
                tempdir, base_file = form.write_files()
                files, _tmpdir = get_files(base_file)
                #  validate input source
                resource_is_valid = validate_input_source(
                    layer=layer,
                    filename=base_file,
                    files=files,
                    action_type=action_type)
                out = {}
                if resource_is_valid:
                    getattr(resource_manager,
                            action_type)(layer,
                                         vals={
                                             'files': list(files.values()),
                                             'user': request.user
                                         })
                    out['success'] = True
                    out['url'] = layer.get_absolute_url()
                    #  invalidating resource chache
                    set_geowebcache_invalidate_cache(layer.typename)
            except Exception as e:
                logger.exception(e)
                out['success'] = False
                out['errors'] = str(e)
            finally:
                if tempdir is not None:
                    shutil.rmtree(tempdir, ignore_errors=True)
                if _tmpdir is not None:
                    shutil.rmtree(_tmpdir, ignore_errors=True)
        else:
            errormsgs = []
            for e in form.errors.values():
                errormsgs.append([escape(v) for v in e])
            out['errors'] = form.errors
            out['errormsgs'] = errormsgs

        if out['success']:
            status_code = 200
            register_event(request, 'change', layer)
        else:
            status_code = 400

        return HttpResponse(json.dumps(out),
                            content_type='application/json',
                            status=status_code)