def createPerson(aVorname, aNachname): DBSession = sessionmaker(bind=engine) session = DBSession() person = Person(vorname=aVorname, name=aNachname) session.add(person) session.commit() print(person.id)
def createPerson(login_session): newPerson = Person(email=login_session['email']) session.add(newPerson) session.commit() person = session.query(Person).filter_by( email=login_session['email']).one() return person.id
def createPerson(login_session): newUser = Person(fname=login_session[ 'fname'], lname=login_session['lname'], email=login_session['email'], status='Player') session.add(newUser) session.commit() user = session.query(Person).filter_by(email=login_session['email']).one() return user.id
def createUser(login_session): newUser = Person(name=login_session[ 'username'], email=login_session['email']) session.add(newUser) session.commit() user = session.query(Person).filter_by(email=login_session['email']).one() return user.id
def person(): # create new person or get list of all people if request.method == 'POST': new_person = Person(name=request.json['name'], age=request.json['age']) session.add(new_person) session.commit() return f'person {new_person.name} created!', 201 else: people = session.query(Person).all() return jsonify(people=[person.serialize for person in people]), 200
def addPerson(): #TO DO: restrict this route for anyone other than logged in users Staff or higher if request.method == 'POST': newPerson = Person(fname=request.form['fname'], lname=request.form['lname'], email=request.form['email'], status=request.form['status']) session.add(newPerson) session.commit() flash("New Person %s has been created!" % newPerson.fname) return redirect(url_for ('home')) else: return render_template('addperson.html')
def createUser(current_login_session): """ Create New User :param current_login_session: :return: new user's id """ new_user = Person(name=current_login_session['username'], email=current_login_session['email'], picture=current_login_session['picture']) session.add(new_user) session.commit() user = session.query(Person).filter_by( email=current_login_session['email']).one() return user.id
def addPerson(age, phone, name): session.begin(subtransactions=True) try: person = session.query(Person).filter_by(phone=phone).first() if person: return False newItem = Person(phone=phone, name=name, age=age) session.add(newItem) session.commit() return True except: session.rollback() # rolls back the transaction, in this case # the one that was initiated in method_a(). raise
def create_account(): if request.method == 'GET': return render_template('create_account.html') else: # ADD CREATING ACCOUNT AND ALL THAT GOOD STUFF HERE!!! user = Person(name=request.form['fullname'], username=request.form['username'], password=request.form['password'], gender=request.form['gender'], nationality=request.form['nationality'], bio=request.form['bio'], rating=5, pic="") dbsession.add(user) dbsession.commit() return redirect(url_for('login'))
def sign_up(): if request.method == 'GET': return render_template("sign_up.html") else: print(request.form) friend = Person(name=request.form['name'], sir_name=request.form['sir_name'], gender=request.form['gender'], birth_date=request.form['birth_date'], country=request.form['country'], city=request.form['city'], user_name=request.form['user_name'], password=request.form['password'], event_fav=request.form['event_fav']) print("DID I MADE A FRIEND?") session.add(friend) session.commit() print("I made it past the commit") return redirect(url_for('log_in'))
def addPerson(category_name): if 'user_id' not in login_session: return redirect(url_for('showLogin')) else: if request.method == 'POST': if request.form['person_name'] and request.form['mobile']: category_id = Session.query(Category).filter( Category.name == category_name).one().id newPerson = Person(name=request.form['person_name'], mobile=request.form['mobile'], address=request.form['address'], category_id=category_id, user_id=login_session['user_id']) Session.add(newPerson) Session.commit() Session.remove() flash("Successfully added a new entry") return redirect( url_for('showCategory', category_name=category_name)) else: return render_template('newPerson.html', category_name=category_name, user_id=login_session['user_id'])
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from database_setup import Address, Base, Person engine = create_engine('sqlite:///sqlalchemy_storage.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() new_person = Person(name='DEVODYUTI MUKHERJEE') session.add(new_person) session.commit() new_address = Address(street_name='1600', street_number='Amphitheatre+Parkway,+Mountain+View,+CA', Post_Code='', person=new_person) session.add(new_address) session.commit()
from sqlalchemy.orm import relationship, sessionmaker from sqlalchemy import create_engine from database_setup import Base, Person engine = create_engine('sqlite:///crudlab.db') Base.metadata.create_all(engine) Base.metadata.bind = engine jack=Person(name='jack', birthday='24/3/2000', gender='male', username='******', passwaord='jack33')s DBSession = sessionmaker(bind=engine) session = DBSession()
from database_setup import engine, Base, Category, Person, User DBSession = sessionmaker(bind=engine) session = DBSession() admin = User(email="*****@*****.**") mohit = User(email="*****@*****.**") plumber = Category(name="Plumber", user=admin) carpenter = Category(name="Carpenter", user=admin) electrician = Category(name="Electrician", user=admin) mechanic = Category(name="Mechanic", user=mohit) plumber1 = Person(name="Ajay Venkatesan", address="""Defence Colony, 100 Feet Road, Indiranagar""", mobile="99410369", category=plumber, user=admin) plumber2 = Person(name="Meghana Raju", address="""75 /, Girls School Road, Mavalli""", mobile="95120252", category=plumber, user=admin) plumber3 = Person(name="Abhimanyu Sem", address="""C/1, Jivanjyoti Bldg, 18/2, \ Cawasji Patel Street, Above Bank Of Rajasthan, Fort""", mobile="23623192", category=plumber, user=admin) plumber4 = Person(name="Rajesh Chauhan", address="""Shop No.10, 25/26, Manish Sunflower, 4 Bungalow, \
def gconnect(): # Check validate state token if request.args.get('state') != session['state']: response = make_response(json.dumps('Invalid state parameter.'), 401) response.headers['Content-Type'] = 'application/json' return response #Obtain authorization code code = request.data try: # Upgrade the authorization code into a credentials object oauth_flow = flow_from_clientsecrets(client_secret_file, scope='') oauth_flow.redirect_uri = 'postmessage' credentials = oauth_flow.step2_exchange(code) except FlowExchangeError: response = make_response(json.dumps('Failed to upgrade the authorization code.'), 401) response.headers['Content-Type'] = 'application/json' return response # Check that the access token is valid. access_token = credentials.access_token url = ('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=%s' % access_token) h = httplib2.Http() result = json.loads(h.request(url, 'GET')[1]) # If there was an error in the access token info, abort. if result.get('error') is not None: response = make_response(json.dumps(result.get('error')), 500) response.headers['Content-Type'] = 'application/json' # Verify that the access token is used for the intended user. gplus_id = credentials.id_token['sub'] if result['user_id'] != gplus_id: response = make_response( json.dumps("Token's user ID doesn't match given user ID."), 401) response.headers['Content-Type'] = 'application/json' return response # Verify that the access token is valid for this app. if result['issued_to'] != CLIENT_ID: response = make_response(json.dumps("Token's client ID does not match app's."), 401) print "Token's client ID does not match app's." response.headers['Content-Type'] = 'application/json' return response stored_credentials = session.get('credentials') stored_gplus_id = session.get('gplus_id') if stored_credentials is not None and gplus_id == stored_gplus_id: response = make_response(json.dumps('Current user is already connected.'), 200) response.headers['Content-Type'] = 'application/json' return response # Store the access token in the session for later use. session['credentials'] = credentials session['person_id'] = gplus_id #Get user info userinfo_url = "https://www.googleapis.com/oauth2/v1/userinfo" params = {'access_token': credentials.access_token, 'alt':'json'} answer = requests.get(userinfo_url, params=params) data = answer.json() # save data user in session session['person_name'] = data['name'] session['person_picture'] = data['picture'] session['person_email'] = data['email'] # cache user in person database for reference is_person_exists = db.query(Person).filter_by( email = session['person_email'] ) if not is_person_exists.count(): person = Person( name = session['person_name'], email = session['person_email'], google_id = session['person_id'] ) db.add(person) db.commit() session['person_id'] = person.id else: session['person_id'] = is_person_exists.one().id response = make_response(json.dumps('Welcome'), 200) response.headers['Content-Type'] = 'application/json' return response
from sqlalchemy.orm import relationship, sessionmaker from sqlalchemy import create_engine from database_setup import Base, Person, Posts engine = create_engine('sqlite:///project.db') Base.metadata.create_all(engine) Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # You can add some starter data for your database here. ron = Person(name='Ron', username = '******', password = 123456, gender = 'Male', hometown = 'jerusalem') post1 = Posts(text = 'jerusalem is great', country = 'israel', person = ron) post2 = Posts(text = 'jerusalem is great2', country = 'israel', person = ron) session.add(ron) session.add(post1) session.add(post2) session.commit() print(ron.posts[0].text) print(ron.posts[1].text)