Ejemplo n.º 1
0
    def setter(self, srlzr, value):
        try:
            layer = etree.fromstring(value)
            relaxng = schema(Map)
            relaxng.assertValid(layer)

        except etree.XMLSyntaxError as e:
            raise ValidationError(_("XML syntax error: %s") % str(e))

        except etree.DocumentInvalid as e:
            raise ValidationError(_("XML schema error: %s") % str(e))

        for cls in registry:
            if hasattr(cls, 'assert_valid'):
                tag = cls.name.lower()
                for el in layer.xpath('//%s' % tag):
                    try:
                        cls.assert_valid(el)
                    except Exception as e:
                        raise ValidationError("{0} within <{1}> tag".format(
                            str(e), tag))

        SP.setter(self, srlzr, value)

        on_style_change.fire(srlzr.obj)
Ejemplo n.º 2
0
    def setter(self, srlzr, value):
        srcfile, _ = env.file_upload.get_filename(value['id'])
        fileobj = env.file_storage.fileobj(component='nextgisweb_mapnik')
        srlzr.obj.xml_fileobj = fileobj
        dstfile = env.file_storage.filename(fileobj, makedirs=True)

        with open(srcfile, 'r') as fs, open(dstfile, 'w') as fd:
            copyfileobj(fs, fd)
        on_style_change.fire(srlzr.obj)
Ejemplo n.º 3
0
    def setter(self, srlzr, value):
        srcfile, srcmeta = env.file_upload.get_filename(value['id'])
        fileobj = env.file_storage.fileobj(component='sprite')
        srlzr.obj.sprite_fileobj = fileobj
        dstfile = env.file_storage.filename(fileobj, makedirs=True)

        with open(srcfile, 'r+b') as fs, open(dstfile, 'w+b') as fd:
            copyfileobj(fs, fd)

        sprite_dir = get_mapbox_helper().sprite_dir

        if not zipfile.is_zipfile(dstfile):
            raise ValidationError(_("Sprite must be a *.zip archive"))

        with tempfile.TemporaryDirectory():
            with zipfile.ZipFile(dstfile) as zip_sprite:
                for sprite_name in zip_sprite.namelist():
                    if os.path.exists(os.path.join(sprite_dir, sprite_name)):
                        raise ValidationError(
                            _("Sprite with name `%s` already exists" %
                              sprite_name))
                zip_sprite.extractall(path=sprite_dir)
        on_style_change.fire(srlzr.obj)
Ejemplo n.º 4
0
    def setter(self, srlzr, value):
        style_dir = get_mapbox_helper().style_dir
        if srlzr.obj.id is not None:
            old_style = loads(srlzr.obj.style)
            old_style_name = old_style.setdefault('name',
                                                  srlzr.obj.display_name)
            if os.path.exists(os.path.join(style_dir,
                                           old_style_name + '.json')):
                os.unlink(os.path.join(style_dir, old_style_name + '.json'))

        mb_style = loads(value)
        style_name = mb_style.setdefault('name', srlzr.obj.display_name)
        mb_style['name'] = style_name

        if os.path.exists(os.path.join(style_dir, style_name + '.json')):
            raise ValidationError(
                _("Mapbox Style with name '%s' exists") % style_name)
        with open(os.path.join(style_dir, style_name + '.json'),
                  mode='w',
                  encoding='utf-8') as fs:
            fs.write(dumps(mb_style, ensure_ascii=True, indent=4))
        super(StyleAttr, self).setter(srlzr, dumps(mb_style,
                                                   ensure_ascii=True))
        on_style_change.fire(srlzr.obj)