def createpoi(request): if request.method == 'POST': form = CreatePoiForm(request.POST) if form.is_valid(): place = PointOfInterest() place.userid = request.user place.title = form.cleaned_data['title'] place.description = form.cleaned_data['description'] place.latitude = form.cleaned_data['latitude'] place.longitude = form.cleaned_data['longitude'] place.category = form.cleaned_data['category'] place.dateCreated = datetime.now() place.dateModified = None place.save() return HttpResponseRedirect('/POI/place/'+str(place.id)+'/') else: form = CreatePoiForm(request.POST) template = loader.get_template('PointsOfInterest/createpoi.html') context = RequestContext(request, { 'form' : form, }) return HttpResponse(template.render(context)) else: form = CreatePoiForm() template = loader.get_template('PointsOfInterest/createpoi.html') context = RequestContext(request, { 'form': form, }) return HttpResponse(template.render(context)) """now = datetime.datetime.now()
def poiedit(request, placeid): place = PointOfInterest.objects.get(id = placeid) if User.objects.get(id = request.user.id) == place.userid: if request.method == 'POST': form = CreatePoiForm(request.POST) if form.is_valid(): place.userid = request.user place.title = form.cleaned_data['title'] place.description = form.cleaned_data['description'] place.latitude = form.cleaned_data['latitude'] place.longitude = form.cleaned_data['longitude'] place.category = form.cleaned_data['category'] place.dateModified = datetime.now() place.save() return HttpResponseRedirect('/POI/place/'+str(place.id)+'/') return HttpResponse(template.render(context)) else: form = CreatePoiForm(request.POST) template = loader.get_template('PointsOfInterest/poiedit.html') context = RequestContext(request, { 'form' : form, 'place' : place, }) return HttpResponse(template.render(context)) else: form = CreatePoiForm(initial={'title': place.title, 'description': place.description, 'latitude': place.latitude, 'longitude': place.longitude, 'category' : place.category}) template = loader.get_template('PointsOfInterest/poiedit.html') context = RequestContext(request, { 'form' : form, 'place' : place, }) return HttpResponse(template.render(context)) else: template = loader.get_template('PointsOfInterest/error.html') context = RequestContext(request, { 'err': 1, }) return HttpResponse(template.render(context))