def new_user(): username = request.json.get('username') password = request.json.get('password') if username is None or password is None: abort(400) # missing arguments if User.query.filter_by(username=username).first() is not None: abort(400) # existing user user = User(username=username) user.hash_password(password) #db.session.add(user) #db.session.commit() s.add(user) s.commit() return (jsonify({'username': user.username}), 201, {'Location': url_for('get_user', id=user.id, _external=True)})
def get_resource(): # Get the parsed contents of the form data # submitted via Ajax request json = request.json # define dictionary item for entire object site = json['site'] # define address dictionary object address = json['site']['address'] # define geolocation dictionary object geolocation = json['site']['geolocation'] # define person dictionary object person = json['site']['person'] evaluation = json['site']['evaluation'] # insert into tables a = Address(address = address["address"], city = address["address"], state = address["state"], zip = address["zip"], neighborhood = address["neighborhood"], county = address["county"]) g = Geoposition(latitude = geolocation["latitude"], longitude = geolocation["longitude"], accuracy = geolocation["accuracy"]) p = Person(first_name = person["first_name"], type = person["type"]) e = Evaluation(comments = evaluation["comments"], exists = evaluation["exists"], evaluator = p) s = Site(site_name=site["site_name"], address = a, geoposition = g, evaluations = [e]) if mode == 'test': # print entire object print 'site:' print json['site'] print 'site name:' print site["site_name"] print 'address:' print site['address'] print address["address"] print 'geolocation:' print geolocation["accuracy"] print 'person:' print person["first_name"] print 'comments:' print evaluation["comments"] ''' db.session.add(a) db.session.add(g) db.session.add(p) db.session.add(e) db.session.add(s) db.session.commit() ''' s.add(a) s.add(g) s.add(p) s.add(e) s.add(s) s.commit() #if mode == 'test': #print s.address.count(address) # 1 #print s.address[0] # <Address object at 0x10c098ed0> #print s.address.filter_by(address = address["address"]).count(address) # 1 # Render template return jsonify(json)