Example #1
0
class AlienActivityForm(forms.Form):
    """ Example of olwidget in a custom form. """
    incident_name = forms.CharField()
    # Old style single field invocation
    landings = MapField([EditableLayerField({
            'geometry': 'point',
            'is_collection': True,
            'overlay_style': {
                'external_graphic': settings.MEDIA_URL+"alien.png",
                'graphic_width': 21,
                'graphic_height': 25,
            },
            'name': 'Landings',
        })])
    # Define a map to edit two geometry fields
    other_stuff = MapField([
            EditableLayerField({'geometry': ['point', 'linestring', 'polygon'],
                'is_collection': True, 'name': "Strange lights",
                'overlay_style': {
                    'fill_color': '#FFFF00',
                    'stroke_color': '#FFFF00',
                    'stroke_width': 6,
                }
            }),
            EditableLayerField({'geometry': 'linestring',
                'is_collection': True, 'name': "Chemtrails",
                'overlay_style': {
                    'fill_color': '#ffffff',
                    'stroke_color': '#ffffff',
                    'stroke_width': 6,
                },
            }),
        ])
Example #2
0
class RequirednessForm(forms.Form):
    optional = MapField(
            fields=[EditableLayerField(required=False, options={
                'geometry': 'point',
                'name': 'optional',
            })],
            options={
                'overlay_style': {'fill_color': '#00ff00'},
            })
    required = MapField(
            fields=[EditableLayerField(required=True, options={
                'geometry': 'point',
                'name': 'required',
            })],
            options={
                'overlay_style': {'fill_color': '#00ff00'},
            })
    unspecified = MapField(
            fields=[EditableLayerField({
                'geometry': 'point',
                'name': 'unspecified',
            })],
            options={
                'overlay_style': {'fill_color': '#00ff00'},
            })
Example #3
0
 class MyInfoModelForm(MapModelForm):
     start = MapField([
         EditableLayerField({'name': 'start'}),
         InfoLayerField([[Point(0, 0, srid=4326), "Of interest"]]),
     ])
     class Meta:
         model = MyModel
Example #4
0
class TestAdminForm(forms.ModelForm):
    boundary = MapField([
        EditableLayerField({'geometry': 'polygon', 'name': 'boundary', 'is_collection': True}),
        InfoLayerField([["SRID=4326;POINT (0 0)", "Of Interest"]], {"name": "Test"}),
    ], { 'overlay_style': { 'fill_color': '#00ff00' }}, 
    template="olwidget/admin_olwidget.html")

    def clean(self):
        self.cleaned_data['boundary'] = self.cleaned_data['boundary'][0]
        return self.cleaned_data

    class Meta:
        model = Country
Example #5
0
class MixedForm(forms.Form):
    capitals = MapField([
        InfoLayerField([[c.boundary, c.about] for c in Country.objects.all()],
            {
                'overlay_style': {
                    'fill_opacity': 0,
                    'stroke_color': "white",
                    'stroke_width': 6,
                }, 
                'name': "Country boundaries",
            }),
        EditableLayerField({
            'geometry': 'point',
            'name': "Country capitals",
            'is_collection': True,
        }),
        ], {'layers': ['google.satellite']})
Example #6
0
class PolySearchForm(forms.Form):
    poly = MapField(
        fields=[
            EditableLayerField({
                'geometry': 'polygon',
                'name': _('polygon')
            }),
        ],
        options={
            "default_lat": 41.6,
            "default_lon": 22,
            "default_zoom": 8,
            "map_div_style": {
                "width": "600px",
                "height": "300px",
            }
        },
        label="",
        required=False,
    )
Example #7
0
 class MyMultiForm(forms.Form):
     mymap = MapField((
         EditableLayerField({'name': 'Fun'}),
         InfoLayerField([[Point(0, 0, srid=4326), "that"]]),
         EditableLayerField(),
     ))
Example #8
0
 class MixedForm(forms.Form):
     stuff = MapField([
         InfoLayerField([["SRID=4326;POINT(0 0)", "Origin"]]),
         EditableLayerField({'geometry': 'point'}),
     ])
Example #9
0
def apply_maps_to_modelform_fields(fields,
                                   maps,
                                   default_options=None,
                                   default_template=None):
    """
    Rearranges fields to match those defined in ``maps``.  ``maps`` is a list
    of [field_list, options_dict] pairs.  For each pair, a new map field is
    created that contans all the fields in ``field_list``.
    """
    map_field_names = (name for name, field in fields.iteritems()
                       if isinstance(field, (MapField, GeometryField)))
    if not maps:
        maps = [((name, ), ) for name in map_field_names]
    elif isinstance(maps, dict):
        maps = [[tuple(map_field_names), maps]]

    default_options = utils.get_options(default_options)
    initial_data_keymap = {}

    for map_definition in maps:
        field_list = map_definition[0]
        if len(map_definition) > 1:
            options = map_definition[1]
        else:
            options = {}
        if len(map_definition) > 2:
            template = map_definition[2]
        else:
            template = default_template

        map_name = "_".join(field_list)
        layer_fields = []
        names = []
        min_pos = 65535  # arbitrarily high number for field ordering
        initial = []
        for field_name in field_list:
            min_pos = min(min_pos, fields.keyOrder.index(field_name))
            field = fields.pop(field_name)
            initial.append(field_name)
            if not isinstance(field.widget, (Map, BaseVectorLayer)):
                field.widget = EditableLayer(
                    options=utils.options_for_field(field))
            layer_fields.append(field)
            names.append(field_name)

        if isinstance(field, MapField):
            map_field = field
        else:
            map_opts = {}
            map_opts.update(default_options)
            map_opts.update(options or {})
            map_field = MapField(layer_fields,
                                 map_opts,
                                 layer_names=names,
                                 label=", ".join(
                                     forms.forms.pretty_name(f)
                                     for f in field_list),
                                 template=template)
        fields.insert(min_pos, map_name, map_field)
        initial_data_keymap[map_name] = initial
    return initial_data_keymap