def register_user(): if request.method == 'POST': email = request.form['email'] password = request.form['password'] confirm_password = request.form['confirm_password'] age = request.form['age'] gender = request.form['gender'] job = request.form['job'] zipcode = request.form['zipcode'] if password != confirm_password: flash("Your passwords do not match. Please re-type all your information.") return redirect("/sign_up") existing = db_session.query(User).filter_by(email=email).first() if existing: flash("Email is already in use.", "error") return redirect(url_for("display_search")) #create a new user object user = User(email=email, password=password, age=age, gender=gender, job=job, zipcode=zipcode) db_session.add(user) db_session.commit() db_session.refresh(user) session['user_id'] = user.id # save a cookie to the browser return redirect(url_for("display_search")) return redirect(url_for("login"))
def uploadfile(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) photo_location = "uploads/" + filename photo_file_path = os.path.join(app.config['UPLOAD_PHOTO_FOLDER'], filename) file.save(photo_file_path) thumbnail_file_path = os.path.splitext( photo_file_path)[0] + ".thumbnail" create_thumbnail(filename, photo_file_path, thumbnail_file_path) thumbnail_location = "uploads/" + os.path.splitext( filename)[0] + ".thumbnail" image = Image.open(photo_file_path) exif_data = get_exif_data(image) latlon = get_lat_lon(exif_data) l = str(latlon) latitude = lat(l) longitude = lon(l) timestamp = get_time(exif_data) if timestamp != None: timestamp = datetime.strptime(str(timestamp), "%Y:%m:%d %H:%M:%S") caption = request.form['caption'] p = Photo(file_location=photo_location, caption=caption, latitude=latitude, longitude=longitude, timestamp=timestamp, user_id=g.user_id, thumbnail=thumbnail_location) db_session.add(p) db_session.commit() db_session.refresh(p) if latitude == None: # photo_id is a key and p.id is a value and session is a dict print "SESSION" session['photo_id'] = p.id return redirect(url_for('addlocation', photo_id=p.id)) user = db_session.query(User).filter_by(id=g.user_id).one() # create a template that shows the view of an uploaded photo and then the user's other photos return redirect(url_for('userpage')) return render_template("upload.html")
def signup(): email = request.form['email'] password = request.form['password'] existing = db_session.query(Users).filter_by(email=email).first() if existing: flash("Email already in use") return redirect(url_for("index")) u = Users(email=email, password=password) db_session.add(u) db_session.commit() db_session.refresh(u) session['user_id'] = u.id return redirect(url_for("selection"))
def register(): email = request.form['email'] password = request.form['password'] existing = db_session.query(User).filter_by(email=email).first() if existing: flash("Email already in use", "error") return redirect(url_for("index")) u = User(email=email, password=password) db_session.add(u) db_session.commit() db_session.refresh(u) session['user_id'] = u.id return redirect(url_for("display_search"))
def register(): email = request.form['email'] username = request.form['username'] password = request.form['password'] existing = db_session.query(User).filter_by(email=email).first() if existing: # FIX FLASH flash("Email already in use", "error") return redirect(url_for("index")) u = User(email=email, password=password, user_name=username) print u db_session.add(u) db_session.commit() db_session.refresh(u) session['user_id'] = u.id return render_template("index.html")
def uploadfile(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): filename = secure_filename(file.filename) photo_location = "uploads/"+filename photo_file_path = os.path.join(app.config['UPLOAD_PHOTO_FOLDER'], filename) file.save(photo_file_path) thumbnail_file_path = os.path.splitext(photo_file_path)[0] + ".thumbnail" create_thumbnail(filename, photo_file_path, thumbnail_file_path) thumbnail_location = "uploads/"+ os.path.splitext(filename)[0] + ".thumbnail" image = Image.open(photo_file_path) exif_data = get_exif_data(image) latlon = get_lat_lon(exif_data) l = str(latlon) latitude = lat(l) longitude = lon(l) timestamp = get_time(exif_data) if timestamp != None: timestamp = datetime.strptime(str(timestamp), "%Y:%m:%d %H:%M:%S") caption = request.form['caption'] p = Photo(file_location=photo_location, caption=caption, latitude=latitude, longitude=longitude, timestamp=timestamp, user_id=g.user_id, thumbnail=thumbnail_location) db_session.add(p) db_session.commit() db_session.refresh(p) if latitude == None: # photo_id is a key and p.id is a value and session is a dict print "SESSION" session['photo_id'] = p.id return redirect(url_for('addlocation', photo_id=p.id)) user = db_session.query(User).filter_by(id=g.user_id).one() # create a template that shows the view of an uploaded photo and then the user's other photos return redirect(url_for('userpage')) return render_template("upload.html")
def signup(): email = request.form['email'] password = request.form['password'] age = request.form['age'] gender = request.form['gender'] occupation = request.form['occupation'] zipcode = request.form["zipcode"] existing = db_session.query(User).filter_by(email=email).first() if existing: flash("Email already in use", "error") return redirect(url_for("index")) user = User(email=email, password=password, age=age, gender=gender, occupation=occupation, zipcode=zipcode) db_session.add(user) db_session.commit() db_session.refresh(user) session['user_id'] = user.id return redirect(url_for("display_search"))
def register(): email = request.form["email"] password = request.form["password"] age = request.form["age"] gender = request.form["gender"] zipcode = request.form["zipcode"] user_exists = db_session.query(User).filter_by(email=email).first() if user_exists: flash("Email already in use.", "error") return redirect(url_for("index")) user_object = User(age=age, gender=gender, zipcode=zipcode, email=email, password=password) db_session.add(user_object) db_session.commit() db_session.refresh(user_object) session["user_id"] = user_object.id return redirect(url_for("signed_in_landing"))
def register(): if request.method == 'GET': return render_template('register.html') else: username = request.form.get('username') user = model_session.query(model.User).filter_by(username=username).first() if user != None: flash('This username is already taken.') return redirect(url_for('register')) else: password = request.form.get('password') verify_password = request.form.get('verify_password') if verify_password == password: new_user = model.User(username=username) new_user.set_password(password) model_session.add(new_user) model_session.commit() model_session.refresh(new_user) return redirect(url_for('login')) else: flash('Passwords do not match!') return redirect(url_for('register'))
def unpack_zendesk_users_tickets(session, user_dict, org_dict): existing_users = User.list_user_ids() for user in user_dict["users"]: #check to see if ticket author is already in database zendesk_user_id = int(user["id"]) if zendesk_user_id not in existing_users: role = user["role"] name = user["name"] email = user["email"] organization_id = user["organization_id"] if organization_id: for organization in org_dict["organizations"]: if organization["id"] == organization_id: organization_name = organization["name"] else: organization_name = None user = model.User(zendesk_user_id = zendesk_user_id, role = role, name = name, email = email, organization_name = organization_name) session.add(user) session.commit() session.refresh(user) user_tickets = zendesk.user_tickets_requested(zendesk_user_id) #Find the last ticket id of messages already in DB in order to determine which messages to add (ticket ids increment by 1) added_tickets = [] for ticket in user_tickets["tickets"]: if ticket["status"] == "open" or ticket["status"] == "pending": ticket_id = int(ticket["id"]) db_tickets = set(Ticket.list_all_ticket_ids()) if ticket_id in db_tickets: continue if ticket_id in added_tickets: continue subject = ticket["subject"] content = ticket["description"] all_content = subject + " " + content user_id = int(ticket["requester_id"]) submitter_id = int(ticket["submitter_id"]) assignee_id = int(ticket["assignee_id"]) source = ticket["via"]["channel"] if source == "twitter": priority = 1 else: priority = 2 timestamp = datetime.strptime(ticket["created_at"], "%Y-%m-%dT%H:%M:%SZ") status = ticket["status"] label = predict_sentiment_label(all_content) ticket = model.Ticket(ticket_id = ticket_id, user_id = user_id, submitter_id = submitter_id, assignee_id = assignee_id, timestamp = timestamp, subject = subject, content = content, status = status, source = source, priority = priority, sentiment_label = label, update_date = timestamp) session.add(ticket) session.commit() session.refresh(ticket) added_tickets.append(ticket_id)
def upload(): username = session.get('username') if username: user_id = model_session.query(model.User).filter_by(username=username).first().id else: user_id = 0 f_keys = request.form.keys() pattern = re.compile(r'^data:image/(png|jpeg|jpg);base64,(.*)$') raw_data = [] for key in f_keys: if key != 'cloud_name' and key != 'choice': match = pattern.match(request.form[key]) if match is None: raise ValueError('Invalid image data.') content_type = 'image/{}'.format(match.group(1)) file_data = base64.b64decode(match.group(2)) raw_data.append(file_data) user_path = 'static/uploads/%d' % user_id if not os.path.exists(user_path): # user doesn't have his/her own directory yet, so create one os.mkdir(user_path) cloud_name = request.form['cloud_name'] algorithm = request.form['choice'] # save cloud to database new_cloud = model.Cloud(user_id=user_id, name=cloud_name) model_session.add(new_cloud) model_session.commit() model_session.refresh(new_cloud) cloud_id = model_session.query(model.Cloud.id).order_by(desc(model.Cloud.id)).first()[0] # create a new directory inside the user's directory for uploaded photos path = user_path + '/' + str(cloud_id) if not os.path.exists(path): os.mkdir(path) for idx, d in enumerate(raw_data): filename = '{}.{}'.format(len(raw_data)-idx, match.group(1)) with open(path + '/' + filename, 'w') as f: f.write(d) path = 'static/uploads/%d/%s' % (user_id, cloud_id) images = sorted(path + '/' + img for img in os.listdir(path) if img.rpartition('.')[2].lower() in ('jpg', 'jpeg', 'png')) points_path = os.path.abspath(os.path.join(path, "points")) reconstruct.start(algorithm, images, file_path=points_path) if algorithm == 'features': points = str(reconstruct.extract_points(points_path + "_inliers.txt")) elif algorithm == 'flow': points = str(reconstruct.extract_points(points_path + ".txt")) # set the path to the text file storing the 3D points of the cloud cloud = model_session.query(model.Cloud).filter_by(id=cloud_id).first() cloud.path = path model_session.commit() # save photos to database photos = [ img for img in os.listdir(path) if img.rpartition('.')[2].lower() in ('jpg', 'jpeg', 'png') ] for photo in photos: new_photo = model.Photo(filename=photo, path=path, cloud_id=cloud_id) model_session.add(new_photo) model_session.commit() model_session.refresh(new_photo) cloud_data = {'cloud_id': cloud_id, 'points': points} return jsonify(cloud_data)