def new(request): """ Funkcja zwraca stronę z formularzem do dodania nowej mapy lub zapisuje mapę w zależności od typus żądania: GET (utwórz formularz) lub POST (zapisz formularz). """ formpoint = NewPointForm() if request.method == 'POST': form = NewMapForm(request.POST) if form.is_valid(): map = Map() southwest = LatLng() northeast = LatLng() map.name = form.cleaned_data['name'] map.tags = form.cleaned_data['tags'] map.latlngs = form.cleaned_data['latlngs'] map.city = form.cleaned_data['city'] map.distance = form.cleaned_data['distance'] southwest.latit = form.cleaned_data['swlat'] southwest.longi = form.cleaned_data['swlng'] northeast.latit = form.cleaned_data['nelat'] northeast.longi = form.cleaned_data['nelng'] southwest.save() northeast.save() map.southwest = southwest map.northeast = northeast map.save() messages.success(request, ADDED) return redirect('map', slug=map.slug, map_id=map.id) elif request.method == 'GET': form = NewMapForm() return direct_to_template(request, 'maps/new.html', { 'form': form, 'formp': formpoint })
def test_delete_map(self): ''' Usuwa mapę po utworzeniu. ''' form = NewMapForm({ 'name': 'Test', 'tags': 'test1, test2', 'city': 'Warszawa', 'latlngs': '0.1,0.2;0.3,0.4;', 'distance': '120.5', 'swlat': '0.1', 'swlng': '0.2', 'nelat': '0.3', 'nelng': '0.4', }) self.assertTrue(form.is_valid(), 'Formularz jest niepoprawny') map = Map() southwest = LatLng() northeast = LatLng() map.name = form.cleaned_data['name'] map.tags = form.cleaned_data['tags'] map.latlngs = form.cleaned_data['latlngs'] map.city = form.cleaned_data['city'] map.distance = form.cleaned_data['distance'] southwest.latit = form.cleaned_data['swlat'] southwest.longi = form.cleaned_data['swlng'] northeast.latit = form.cleaned_data['nelat'] northeast.longi = form.cleaned_data['nelng'] southwest.save() northeast.save() map.southwest = southwest map.northeast = northeast map.save() map.delete() self.assertTrue(map.pk is None, 'Nieprawidłowo usunięta mapa')