def init_db_command(): """Clear the existing data and create new tables.""" from flaskr.__init__ import create_app from flaskr.schema import Users from flaskr.schema import Text # pass the create_app result so Flask-SQLAlchemy gets the configuration. for the db object, not the app object db.create_all(app=create_app()) click.echo('Initialized the database.')
def index(): if request.method == 'POST': email = request.form['email'] firstName = request.form['firstName'] lastName = request.form['lastName'] description = request.form['description'] photoUploaded = False try: file = request.files['photo'] extension = os.path.splitext(file.filename)[1] ALLOWED_EXTENSIONS = set([ '.jpe', '.pdf', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.bmp' ]) if extension not in ALLOWED_EXTENSIONS: flash('Please Enter A Valid Photo Type') else: f_name = str(uuid.uuid4()) + extension app = create_app(None) file.save( os.path.join(app.config['UPLOADED_PHOTOS_DEST'], f_name)) location = "uploads/" + f_name photoUploaded = True except: photoUploaded = False error = None db = get_db() if re.search(".+@.+", email) is None: error = "Please Enter a Valid Email Address" elif re.search("[a-zA-Z ]+", firstName) is None: error = "Please Enter a Valid First Name" elif re.search("[a-zA-Z ]+", lastName) is None: error = "Please Enter a Valid Last Name" #SQL statements when Photo is uploaded if error is None and photoUploaded: destination = db.execute( 'SELECT profilePicture FROM user WHERE firstName = ? AND email = ? AND userId = ?', (firstName, email, session.get('user_id'))).fetchone() if str(destination[0]) != "uploads/stickfigure.png": print(str(destination[0])) os.remove('flaskr/static/' + str(destination[0])) db.execute( 'UPDATE user SET email = ?, firstName = ? , lastName = ?, description = ?, profilePicture = ? WHERE userId =? ', (email, firstName, lastName, description, location, session.get('user_id'))) db.commit() print("successfully updated user") #SQL statements when Photo is not uploaded elif error is None and not photoUploaded: db.execute( 'UPDATE user SET email = ?, firstName = ? , lastName = ?, description = ? WHERE userId =? ', (email, firstName, lastName, description, session.get('user_id'))) db.commit() print("successfully updated user") else: print(error) return redirect(url_for('dashboard.index')) return render_template('dashboard/index.html')
from flaskr.__init__ import create_app app = create_app() if __name__ == "__main__": print(app.secret_key) app.run()