Package madrona :: Package features :: Module forms
[hide private]

Source Code for Module madrona.features.forms

 1  # Need a UserForm base class here 
 2  # from django.db import models 
 3  from django import forms 
 4  from django.forms import ModelForm 
 5  from django.contrib.auth.models import User 
 6  from django.utils.safestring import mark_safe 
 7  from django.contrib.gis.geos import fromstr 
 8  from django.conf import settings  
 9  from madrona.manipulators.manipulators import display_kml 
10   
11 -class ShapeInput(forms.HiddenInput):
12 - def render(self, name, value, attrs=None):
13 from madrona.features.models import PolygonFeature, PointFeature, LineFeature 14 model = self.form_instance.Meta.model 15 if issubclass(model, PolygonFeature): 16 type = 'polygon' 17 elif issubclass(model, LineFeature): 18 type = 'linestring' 19 else: 20 type = 'point' 21 kml = '' 22 if name == 'geometry_final': 23 output = super(ShapeInput, self).render(name, '', attrs) 24 else: 25 output = super(ShapeInput, self).render(name, value, attrs) 26 if value: 27 geo = fromstr(value) 28 geo.srid = settings.GEOMETRY_DB_SRID 29 kml = display_kml(geo) 30 return mark_safe(""" 31 <script class="%s" id="%s_kml" type="application/vnd.google-earth.kml+xml"> 32 %s 33 </script> 34 %s 35 """ % (type, name, kml, output))
36
37 -class FeatureForm(ModelForm):
38 user = forms.ModelChoiceField(User.objects.all(),widget=forms.HiddenInput()) 39
40 - class Meta:
41 exclude = ('sharing_groups','content_type','object_id',)
42
43 -class SpatialFeatureForm(FeatureForm):
44 geometry_orig = forms.CharField(widget=ShapeInput()) 45 geometry_final = forms.CharField(widget=ShapeInput(), required=False) 46 manipulators = forms.CharField(widget=forms.HiddenInput(), required=False) 47
48 - class Meta:
49 exclude = ('sharing_groups','content_type','object_id',)
50
51 - def __init__(self, *args, **kwargs):
52 super(SpatialFeatureForm, self).__init__(*args, **kwargs) 53 self.fields['geometry_final'].widget.form_instance = self 54 self.fields['geometry_orig'].widget.form_instance = self
55