kopia lustrzana https://github.com/hholzgra/maposmatic/
Additionnal checks on submitted values
rodzic
e356483c7c
commit
506ea5625d
|
@ -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)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body {% block extrabody %}{% endblock %}>
|
||||
<div id="header">
|
||||
<h1>MapOSMatic</h1>
|
||||
<div id="menu">
|
||||
|
|
|
@ -14,12 +14,26 @@ function area_selection_mode_switch(mode)
|
|||
document.getElementById('bbox-mode').style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function pageinit()
|
||||
{
|
||||
document.getElementById('id_mode_0').setAttribute('onclick', "area_selection_mode_switch('admin-mode')");
|
||||
document.getElementById('id_mode_1').setAttribute('onclick', "area_selection_mode_switch('bbox-mode')");
|
||||
if (document.getElementById('id_mode_0').getAttribute('checked') == 'checked')
|
||||
area_selection_mode_switch('admin-mode');
|
||||
else if (document.getElementById('id_mode_1').getAttribute('checked') == 'checked')
|
||||
area_selection_mode_switch('bbox-mode');
|
||||
}
|
||||
{% endblock %}
|
||||
|
||||
{% block menu-home %}
|
||||
class="activelink"
|
||||
{% endblock %}
|
||||
|
||||
{% block extrabody %}
|
||||
onload='pageinit()'
|
||||
{% endblock %}
|
||||
|
||||
{% block page %}
|
||||
<h1>MapOSMatic</h1>
|
||||
|
||||
|
@ -29,12 +43,12 @@ class="activelink"
|
|||
<tr>
|
||||
<td>Title for the generated map</td>
|
||||
<td>{{ form.maptitle }}</td>
|
||||
<td>{{ form.maptitle.errors }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Area selection mode</td>
|
||||
<td>
|
||||
<input type="radio" name="area-selection-mode" value="admin" checked="checked" onclick="area_selection_mode_switch('admin-mode');"/>Based on administrative limit<br/>
|
||||
<input type="radio" name="area-selection-mode" value="bbox" onclick="area_selection_mode_switch('bbox-mode');"/>Based on a bounding box <i>bouding box</i>
|
||||
{{ form.mode }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr id="admin-mode">
|
||||
|
@ -45,16 +59,10 @@ class="activelink"
|
|||
<tr id="bbox-mode" style="display: none;">
|
||||
<td>Bounding box</td>
|
||||
<td style="text-align: center">
|
||||
<input type="text" name="lat_upper_left" style="width: 100px; margin-bottom: 5px;"/><br/>
|
||||
<input type="text" name="lon_upper_left" style="width: 100px; margin-bottom: 5px;"/>
|
||||
<input type="text" name="lon_bottom_right" style="width: 100px"/><br/>
|
||||
<input type="text" name="lat_bottom_right" style="width: 100px"/>
|
||||
</td>
|
||||
<td>
|
||||
{{ form.lat_upper_left.errors }}
|
||||
{{ form.lon_upper_left.errors }}
|
||||
{{ form.lat_bottom_right.errors }}
|
||||
{{ form.lon_bottom_right.errors }}
|
||||
<input type="text" name="lat_upper_left" style="width: 100px; margin-bottom: 5px;"/>{{ form.lat_upper_left.errors }}<br/>
|
||||
<input type="text" name="lon_upper_left" style="width: 100px; margin-bottom: 5px;"/>{{ form.lon_upper_left.errors }}
|
||||
<input type="text" name="lon_bottom_right" style="width: 100px"/>{{ form.lat_bottom_right.errors }}<br/>
|
||||
<input type="text" name="lat_bottom_right" style="width: 100px"/>{{ form.lon_bottom_right.errors }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
Ładowanie…
Reference in New Issue