def photographer_upload(): # if request method is post if request.method == 'POST': form = PhotoUploadForm(name=request.form.get("name"), file=request.files.get("file")) if form.validate(): # get the photographer id from the user # save the image and link to photographer image_file = form.file.data photo = Photo(name=form.name.data, photographer_id=current_user.photographer.id, file=image_file.read()) image = Image.open(image_file) file_type = image_file.headers.get("Content-Type") photo.add_image_data(*image.size, file_type) # save photo to db session_object = db_session() session_object.add(photo) session_object.commit() # success message flash("Image Uploaded Successfully", "success") return redirect(url_for('dashboard')) else: return render_template('photographer_uploads.html', form=form) # if the request is any other than get return render_template('photographer_uploads.html', form=PhotoUploadForm())
def results(): if (current_user.is_anonymous): return redirect(url_for('login')) form = PhotoUploadForm() # photo upload works, but doesn't save the file yet, this is being worked on if (request.method == 'POST'): photo = request.files['photo'] mlsnums = closestMatches(photo) properties = {} top = {} count = 0 for mlsnum in mlsnums: prop = Properties.query.filter_by(mlsnum=mlsnum).first() price = str(prop.listprice) p = str(prop.beds) + " beds | " + str( prop.baths) + " baths | " + str(int(prop.sqft)) + " sqft" # reformat the price string so it removes decimals and adds the price sign if (price is not None): sub = str(price).split(".")[0] price = "${:,}".format(int(sub)) if count == 0: # separate out the 'top' hit to be displayed separately top[prop.mlsnum] = { "string": p, "photo": prop.photourl, "mlsnum": mlsnum } if (price is not None): top[prop.mlsnum].update({"price": price}) else: properties[prop.mlsnum] = { "string": p, "photo": prop.photourl, "mlsnum": mlsnum } if (price is not None): properties[prop.mlsnum].update({"price": price}) count = count + 1 print(str(top)) return render_template('results.html', properties=properties, top=top) else: return render_template('search.html', form=form)
def add_picture(request): if request.method == 'GET': return render(request, 'PicShare/uploadform.html', { 'form': PhotoUploadForm, 'user': request.user }) if request.method == 'POST': form = PhotoUploadForm(request.POST, request.FILES) if form.is_valid(): owner = request.user pic = Picture(owner=owner, caption=form.data['caption'], description=form.data['description'], image=request.FILES['image']) pic.save() return HttpResponseRedirect(reverse('profile')) else: return render(request, 'PicShare/uploadform.html', { 'form': form, 'user': request.user })