def checkUser(username, password): user = dbsession.query(User).filter_by(name=username).first() if user: password_db = user.password password_encrypt = encrypt(username + password) if password_encrypt == password_db: return True return False
def checkUser(username, password): user = dbsession.query( User ).filter_by( name = username ).first() if user: password_db = user.password password_encrypt = encrypt( username + password ) if password_encrypt == password_db: return True return False
def populate_db(): users = dbsession.query(User).all() if not users: jimmy = User(name='jimmy', password='******') jimmy.itemlist.append( Item(title='iphone1', price='1000', desc='sixty percent new', location='POINT(%s %s)' % ('31.199', '121.587'))) jimmy.itemlist.append( Item(title='iphone2', price='1500', desc='sixty-five percent new', location='POINT(%s %s)' % ('31.299', '121.587'))) jimmy.itemlist.append( Item(title='iphone3', price='2000', desc='seventy percent new', location='POINT(%s %s)' % ('31.099', '121.587'))) jimmy.itemlist.append( Item(title='iphone4', price='3000', desc='eighty percent new', location='POINT(%s %s)' % ('31.199', '121.487'))) jimmy.itemlist.append( Item(title='iphone4s', price='4000', desc='ninty percent new', location='POINT(%s %s)' % ('31.099', '121.787'))) jimmy.itemlist.append( Item(title='iphone5', price='9999', desc='comming soon...', location='POINT(%s %s)' % ('31.199', '121.587'))) dbsession.add(jimmy) lisa = User(name='lisa', password='******') lisa.itemlist.append( Item(title='iphone6', price='99999', desc='future...', location='POINT(%s %s)' % ('31.299', '121.387'))) lisa.itemlist.append( Item(title='iphone7', price='999999', desc='future...', location='POINT(%s %s)' % ('31.199', '121.387'))) dbsession.add(lisa) dbsession.add(User(name='bob', password='******')) dbsession.add(User(name='john', password='******')) dbsession.commit()
def add_item(): title = request.GET.get('title') price = request.GET.get('price') desc = request.GET.get('description') latlng = request.GET.get('latlng') [lat, lng] = latlng.split(',') username = request.GET.get('username') user = dbsession.query(User).filter_by(name=username).first() if not user: #return HTTPError(404, 'User not found.') return {'status' : 'error'} item = Item(title=title, price=price, desc=desc, location='POINT(%s %s)' %(lat, lng)) user.itemlist.append(item) dbsession.commit() #return "item %s added!" % title return {'status' : 'ok'}
def populate_db(): users = dbsession.query(User).all() if not users: jimmy = User(name='jimmy', password='******') jimmy.itemlist.append(Item(title='iphone1', price='1000', desc='sixty percent new', location='POINT(%s %s)' %('31.199', '121.587'))) jimmy.itemlist.append(Item(title='iphone2', price='1500', desc='sixty-five percent new', location='POINT(%s %s)' %('31.299', '121.587'))) jimmy.itemlist.append(Item(title='iphone3', price='2000', desc='seventy percent new', location='POINT(%s %s)' %('31.099', '121.587'))) jimmy.itemlist.append(Item(title='iphone4', price='3000', desc='eighty percent new', location='POINT(%s %s)' %('31.199', '121.487'))) jimmy.itemlist.append(Item(title='iphone4s', price='4000', desc='ninty percent new', location='POINT(%s %s)' %('31.099', '121.787'))) jimmy.itemlist.append(Item(title='iphone5', price='9999', desc='comming soon...', location='POINT(%s %s)' %('31.199', '121.587'))) dbsession.add(jimmy) lisa = User(name='lisa', password='******') lisa.itemlist.append(Item(title='iphone6', price='99999', desc='future...', location='POINT(%s %s)' %('31.299', '121.387'))) lisa.itemlist.append(Item(title='iphone7', price='999999', desc='future...', location='POINT(%s %s)' %('31.199', '121.387'))) dbsession.add(lisa) dbsession.add(User(name='bob', password='******')) dbsession.add(User(name='john', password='******')) dbsession.commit()
def add_item(): title = request.GET.get('title') price = request.GET.get('price') desc = request.GET.get('description') latlng = request.GET.get('latlng') [lat, lng] = latlng.split(',') username = request.GET.get('username') user = dbsession.query(User).filter_by(name=username).first() if not user: #return HTTPError(404, 'User not found.') return {'status': 'error'} item = Item(title=title, price=price, desc=desc, location='POINT(%s %s)' % (lat, lng)) user.itemlist.append(item) dbsession.commit() #return "item %s added!" % title return {'status': 'ok'}
def search_nearby_box(north, east, south, west, max_results=10): items = dbsession.query(Item).limit(max_results).all() return items
from db import engine, Login_info, dbsession, session query_uname = dbsession.query( Login_info.uname).filter(Login_info.uname == 'asd').one() print(query_uname) str1 = query_uname[0] print(str1) print(query_uname[(0)])
def isUserExsit(username): user = dbsession.query( User ).filter_by( name = username ).first() if user: return True return False
def isUserExsit(username): user = dbsession.query(User).filter_by(name=username).first() if user: return True return False
def latest_items(): response.content_type = 'application/json' items = dbsession.query(Item).limit(10).all() return item_dump(items)
def search_nearby_box(north, east, south, west, max_results=10): box = "POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))" % ( north, east, south, east, south, west, north, west, north, east) items = dbsession.query(Item).filter( Item.location.within(box)).limit(max_results).all() return items
def user_name(name): user = dbsession.query(User).filter_by(name=name).first() if user: return "<li>%s found, items count %d</li>" % (user.name, len(user.itemlist)) return HTTPError(404, 'User not found.')
def users(): users = dbsession.query(User) if users: result = "".join(["<li>%s</li>" % user.name for user in users]) return "<ul>%s</ul>" % result return HTTPError(404, 'User not found.')
def search_nearby_box(north, east, south, west, max_results=10): box = "POLYGON((%s %s, %s %s, %s %s, %s %s, %s %s))" % (north, east, south, east, south, west, north, west, north, east) items = dbsession.query(Item).filter(Item.location.within(box)).limit(max_results).all() return items
def get_item(title): item = dbsession.query(Item).filter_by(title=title).first() if item: return "<li>%s by %s</li>" % (item.title, item.user.name) return HTTPError(404, 'Item not found.')