diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py index e9e5a7e8..33ac4c60 100644 --- a/www/maposmatic/views.py +++ b/www/maposmatic/views.py @@ -1,6 +1,7 @@ # Create your views here. -from django.forms import ModelForm +from django.forms.util import ErrorList +from django.forms import ChoiceField, RadioSelect, ModelForm, ValidationError from django.shortcuts import get_object_or_404, render_to_response from django.http import HttpResponseRedirect from www.maposmatic.models import MapRenderingJob @@ -12,6 +13,31 @@ class MapRenderingJobForm(ModelForm): fields = ('maptitle', 'administrative_city', 'lat_upper_left', 'lon_upper_left', 'lat_bottom_right', 'lon_bottom_right') + modes = (('admin', 'Administrative boundary'), + ('bbox', 'Bounding box')) + mode = ChoiceField(choices=modes, initial='admin', widget=RadioSelect) + + def clean(self): + cleaned_data = self.cleaned_data + + mode = cleaned_data.get("mode") + city = cleaned_data.get("administrative_city") + + if mode == 'admin' and city == "": + msg = u"Administrative city required" + self._errors["administrative_city"] = ErrorList([msg]) + del cleaned_data["administrative_city"] + + if mode == 'bbox': + for f in [ "lat_upper_left", "lon_upper_left", + "lat_bottom_right", "lon_bottom_right" ]: + val = cleaned_data.get(f) + msg = u"Required" + self._errors[f] = ErrorList([msg]) + del cleaned_data[f] + + return cleaned_data + def index(request): if request.method == 'POST': form = MapRenderingJobForm(request.POST) diff --git a/www/templates/maposmatic/base.html b/www/templates/maposmatic/base.html index 69a96c75..81348a27 100644 --- a/www/templates/maposmatic/base.html +++ b/www/templates/maposmatic/base.html @@ -12,7 +12,7 @@ -
+