def test_location_creation_form(self): form_data = { 'name' : 'NewLoc', 'description': 'A New location' } form = LocationForm(data=form_data) self.assertTrue(form.is_valid())
def add_location_page(request): lat, lng = 15.87003, 100.99254 # Thailand if request.method == 'POST': form = LocationForm(request.POST) if form.is_valid(): location = form.save(commit=False) location.user = request.user; if request.user.profile.editor: location.send_media = True location.save() request.flash['message'] = ('alert-success', _('New place added successfully')) return HttpResponseRedirect('/places') else: try: lat = float(form.data.get('latitude')) lng = float(form.data.get('longitude')) except ValueError,e: pass
def edit_location_page(request, pk): location = Location.objects.get(pk=int(pk)) if location.user.id != request.user.id and not request.user.is_superuser: return HttpResponseRedirect('/places') lat, lng = location.latitude, location.longitude if request.method == 'POST': form = LocationForm(request.POST, instance=location) if form.is_valid(): location = form.save() if location.user == None: location.user = request.user; location.save() update_location_task.apply_async((location,), countdown=0) request.flash['message'] = ('alert-success', _('Place updated successfully')) return HttpResponseRedirect('/places') else: try: lat = float(form.data.get('latitude')) lng = float(form.data.get('longitude')) except ValueError,e: pass