def post(self): newproperty = Property() newproperty.title = self.request.get("title").strip() newproperty.description = self.request.get("description").strip() newproperty.location = self.request.get("location").strip() newproperty.sqft = self.request.get("size").strip() newproperty.price = self.request.get("price").strip() newproperty.kind = self.request.get("type").strip() developer_key = ndb.Key("Developer", normalize_id(self.request.get("developer").strip())) newproperty.developer = developer_key amenities = PROPERTY_AMENITIES.copy() new_amenities = PROPERTY_AMENITIES.copy() for key, value in amenities.items(): if self.request.get("amenities_"+key).strip(): new_val = self.request.get("amenities_"+key).strip() else: new_val = 0 new_amenities[key] = new_val newproperty.amenities = new_amenities newproperty.put() self.redirect("/upload/"+ str(newproperty.key.id()))
def updateProperty(request): form = PropertyForm() try: if 'owner' not in request.POST: crrProp = Property() else: pid = request.POST.get('owner', '') crrProp = Property.objects.get(pk=pid) except Property.DoesNotExist: return HttpResponse("no prtoperty with this id") crrProp.ptype = request.POST['ptype'] crrProp.location = request.POST['location'] crrProp.price = request.POST['price'] crrProp.area = request.POST['area'] crrProp.nrooms = request.POST['nrooms'] crrProp.ntoilets = request.POST['ntoilets'] crrProp.lang = request.POST['long'] crrProp.latt = request.POST['lat'] # crrProp.lang = 70 # crrProp.latt = 40 SITE_ROOT = path.dirname(path.dirname(path.realpath(__file__))) user = Client.objects.get(pk=1) crrProp.owner = user crrProp.save() fname = request.FILES['fileToUpload'].name extension = fname.split(".")[-1] imgName = str(crrProp.id) + "." + extension imgPath = SITE_ROOT + "/aqarmap/static/img/" + imgName handle_uploaded_file(request.FILES['fileToUpload'], imgPath) # form = ModelFormWithFileField(request.POST, request.FILES) # if form.is_valid(): # form.save() crrProp.img = imgName crrProp.save() return render(request, 'add-property.html', {'form': form.as_p()})
#print '---------' if tryfloat(row[cnames.index("VE_MONTO")]) != 0.0: #print 'soy venta!' prop.prop_operation_id |= 1 prop.price_sell = float(tryfloat( row[cnames.index("VE_MONTO")])) #access op_monto prop.price_sell_currency = currencies[row[cnames.index( "VE_MONEDA")]] #op moneda id if tryfloat(row[cnames.index("AL_MONTO")]) != 0.0: #print 'soy alquiler!' prop.prop_operation_id |= 2 prop.price_rent = float(tryfloat(row[cnames.index("AL_MONTO")])) prop.price_rent_currency = currencies[row[cnames.index("AL_MONEDA")]] prop.location = "0,0" prop.calculate_inner_values() #pkey = db.Key.from_path(Property, str(int(tryint(row[cnames.index("PROP_Id")])))) arr = [] #KEY arr.append(unicode(int(tryint(row[cnames.index("PROP_Id")])))) for att in Property.public_attributes(): val = getattr(prop, att) #if att == 'price_rent_computed' or att == 'price_sell_computed': # print u'voy a meter %s = ' + unicode(val) arr.append(unicode(val))