def delete_symbol(rule, library_rule, gs):
    try:
        style = Style.objects.get(id=rule.style.id)

        if gs.deleteStyle(style.name):
            style.delete()
        symbolizers = Symbolizer.objects.filter(rule_id=rule.id)
        for symbolizer in symbolizers:
            if get_ftype(symbolizer) == 'ExternalGraphic':
                file_name = rule.name + '.png'
                utils.delete_external_graphic_img(library_rule.library,
                                                  file_name)
            symbolizer.delete()
        library_rule.delete()
        rule.delete()

    except Exception as e:
        raise e
示例#2
0
def update_symbol(request, json_rule, rule, library_rule):
    try:
        gs = geographic_servers.get_instance().get_default_server()

        name = json_rule.get('name')
        title = json_rule.get('title')

        #if _valid_title_regex.search(title) == None:
        #    raise InvalidValue(-1, _("Invalid title: '{value}'. Title should not contain any special characters").format(value=title))

        rule.title = title
        rule.save()
        symbol_type = None
        eg_file = None

        if 'eg-file' in request.FILES:
            file_name = json_rule.get('file_name').split('/')[-1]
            eg_file = request.FILES['eg-file']

        for s in Symbolizer.objects.filter(rule=rule):
            if get_ftype(s) == 'ExternalGraphicSymbolizer':
                symbol_type = get_ftype(s)
                if eg_file is not None:
                    utils.delete_external_graphic_img(library_rule.library,
                                                      file_name)
            s.delete()

        for sym in json_rule.get('symbolizers'):

            json_sym = json.loads(sym.get('json'))
            if json_sym.get('type') == 'ExternalGraphicSymbolizer':
                library_path = utils.check_library_path(library_rule.library)
                file_name = name + '.png'
                if eg_file is not None:
                    if utils.save_external_graphic(library_path, eg_file,
                                                   file_name):
                        online_resource = utils.get_online_resource(
                            library_rule.library, file_name)
                        json_sym['online_resource'] = json_sym[
                            'online_resource'].replace(
                                "online_resource_replace", online_resource)

                symbolizer = ExternalGraphicSymbolizer(
                    rule=rule,
                    order=json_rule.get('order'),
                    opacity=json_sym.get('opacity'),
                    size=json_sym.get('size'),
                    rotation=json_sym.get('rotation'),
                    online_resource=json_sym.get('online_resource'),
                    format=json_sym.get('format'))
                symbolizer.save()

            if json_sym.get('type') == 'PolygonSymbolizer':
                symbolizer = PolygonSymbolizer(
                    rule=rule,
                    order=json_sym.get('order'),
                    fill=json_sym.get('fill'),
                    fill_opacity=json_sym.get('fill_opacity'),
                    stroke=json_sym.get('stroke'),
                    stroke_width=json_sym.get('stroke_width'),
                    stroke_opacity=json_sym.get('stroke_opacity'),
                    stroke_dash_array=json_sym.get('stroke_dash_array'))
                symbolizer.save()

            elif json_sym.get('type') == 'LineSymbolizer':
                symbolizer = LineSymbolizer(
                    rule=rule,
                    order=json_sym.get('order'),
                    stroke=json_sym.get('stroke'),
                    stroke_width=json_sym.get('stroke_width'),
                    stroke_opacity=json_sym.get('stroke_opacity'),
                    stroke_dash_array=json_sym.get('stroke_dash_array'))
                symbolizer.save()

            elif json_sym.get('type') == 'MarkSymbolizer':
                symbolizer = MarkSymbolizer(
                    rule=rule,
                    order=json_sym.get('order'),
                    opacity=json_sym.get('opacity'),
                    size=json_sym.get('size'),
                    rotation=json_sym.get('rotation'),
                    well_known_name=json_sym.get('well_known_name'),
                    fill=json_sym.get('fill'),
                    fill_opacity=json_sym.get('fill_opacity'),
                    stroke=json_sym.get('stroke'),
                    stroke_width=json_sym.get('stroke_width'),
                    stroke_opacity=json_sym.get('stroke_opacity'),
                    stroke_dash_array=json_sym.get('stroke_dash_array'))
                symbolizer.save()

        style = Style.objects.get(id=rule.style.id)

        if gs.deleteStyle(style.name):
            sld_body = sld_builder.build_library_symbol(rule)
            if not gs.createStyle(style.name, sld_body):
                return False

        return True

    except Exception as e:
        raise e