本文整理汇总了Python中models.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach_pictures
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def attach_pictures(request):
menu_query = DBSession.query(Menu).filter(Menu.id==request.matchdict['menu_id'])
images_id = menu_query.one().images_id
images_id = images_id.split(' ') if images_id else []
if images_id:
images = DBSession.query(Image).filter(Image.id.in_(images_id)).all()
added_thumbs = []
if "data" in request.params:
data = json.loads(request.params["data"])
for image_info in data:
image, thumb = image_info
if not image or not thumb:
continue
ext = os.path.splitext(image)[-1].lower()
if ext in (".jpg", ".jpeg", ".png"):
new_image = Image(image_url=image, thumb_url=thumb)
added_thumbs.append(thumb)
DBSession.add(new_image)
DBSession.flush()
DBSession.refresh(new_image)
images_id.append(new_image.id)
menu_query.update({
"images_id": ' '.join([str(i) for i in images_id]),
})
return json.dumps(added_thumbs)
示例2: postAdd
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def postAdd(request):
currentUser = int(authenticated_userid(request))
rankWeight = None #TODO
pasteTitle = request.POST['paste_title']
topic_id = request.POST['topic']
newPost = Post(currentUser,rankWeight,topic_id,pasteTitle)
DBSession.add(newPost)
DBSession.flush()
contentTitles = []
contentURLs = []
for key, value in request.POST.iteritems():
if key == "title" and value != "":
contentTitles.append(value)
elif key == "URL" and value != "":
contentURLs.append(value)
contents = []
for title,URL in zip(contentTitles,contentURLs):
contentType = "LINK" # TODO
newContent = Content(title,URL,contentType,newPost.id)
DBSession.add(newContent)
DBSession.flush()
contents.append(row2dict(newContent))
post = {}
post['post'] = row2dict(newPost)
post['contents'] = contents
return {'post' : post}
示例3: upload
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def upload(request):
if request.content_length/1000000 > 20:
return error_response(400, 'Sorry, but the file must be under 20MB.')
# Create photo object in database
photo = Photo(datetime.today(), request.POST['file'].filename, request.client_addr, request.content_type, request.content_length)
DBSession.add(photo)
DBSession.flush()
# Save uploaded file
input_file = request.POST['file'].file
input_file.seek(0)
if not os.path.exists('data'):
os.makedirs('data')
if not os.path.exists('data/uploads'):
os.makedirs('data/uploads')
upload_path = os.path.join('data', 'uploads', str(photo.id))
with open(upload_path, 'w') as f:
shutil.copyfileobj(input_file, f)
# Check the content type and rename as appropriate
mime = magic.from_file(upload_path, mime=True)
if mime not in ['image/jpeg', 'image/pjpeg', 'image/gif', 'image/png', 'image/tiff', 'image/x-tiff']:
resp = Response('Sorry, but we can only accept jpg, gif, or png files.')
resp.status_code = 400
resp.status_string = '400 Bad Request'
return resp
extension = {'image/jpeg': '.jpg', 'image/pjpeg': '.jpg',
'image/gif': '.gif', 'image/png': '.png',
'image/tiff': '.tiff', 'image/x-tiff': '.tiff'}[mime]
os.rename(upload_path, upload_path + extension)
photo.content_type = mime
return Response('OK')
示例4: post_entry
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def post_entry(request):
entry = m.Entry()
entry.start_datetime = datetime.datetime.now()
entry.updated_datetime = datetime.datetime.now()
DBSession.add(entry)
DBSession.flush()
return entry.entry_id
示例5: eventAdd
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def eventAdd(request):
eventName = request.POST['name']
eventType = request.POST['type']
eventDescription = request.POST['description']
image = request.POST.getall('file')
for i in image:
imageId = uuid.uuid1()
imageUrl = str(imageId)
open('/home/mohit/intern/hallwala/HallWala/hallwala/images/%d.jpg' % (imageId), 'wb').write(i.file.read())
for infile in glob.glob("/home/mohit/intern/hallwala/HallWala/hallwala/images/*.jpg"):
im = Image.open(infile)
# don't save if thumbnail already exists
if infile[0:2] != "T_":
# convert to thumbnail image
im.thumbnail((128, 128), Image.ANTIALIAS)
# prefix thumbnail file with T_
im.save("T_" + infile, "JPEG")
newEvent = Event(eventName,eventType,eventDescription)
DBSession.add(newEvent)
DBSession.flush()
event = newEvent.getJSON()
return {'event' : event}
示例6: create_translation
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def create_translation(client_id, contents=list(), gist_type='Service'):
gist = TranslationGist(client_id=client_id, type=gist_type)
DBSession.add(gist)
DBSession.flush()
for content in contents:
atom = TranslationAtom(client_id=client_id, content=content[0], locale_id=content[1], parent=gist)
DBSession.add(atom)
DBSession.flush()
return gist
示例7: make_session
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def make_session(user, sessionid=None, expires_in=3600):
if not sessionid:
sessionid = str(uuid.uuid4())
DBSession.query(Session).filter(Session.sessionid == sessionid).delete()
logging.debug("making session for %s with sessionid %s" % (user.username, sessionid))
s = Session(user_id=user.id, sessionid=sessionid, expires=datetime.datetime.now() + datetime.timedelta(0, expires_in))
DBSession.add(s)
DBSession.flush()
DBSession.expunge(s)
return s
示例8: add_money
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def add_money(player_in, amount):
in_player = Player.query.filter(Player.id == int(player_in)).first()
movement_in = Movement(player=in_player, amount=amount, move_type=Movement.TYPES['IN'])
DBSession.add(movement_in)
in_player.update_balance(operation_type=Movement.TYPES['IN'], amount=amount)
DBSession.flush()
DBSession.commit()
示例9: create_user
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def create_user(username, password):
logging.debug("creating user %s" % (username))
if find_user(username):
raise RuntimeError("User %s already exists" % (username))
hashed_password = hash_password(password)
u = User(username=username, password=hashed_password)
DBSession.add(u)
DBSession.flush()
DBSession.expunge(u)
return u
示例10: subtract_money
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def subtract_money(player_out, amount):
out_player = Player.query.filter(Player.id == int(player_out)).first()
movement_out = Movement(player=out_player, amount=amount, move_type=Movement.TYPES['OUT'])
DBSession.add(movement_out)
out_player.update_balance(operation_type=Movement.TYPES['OUT'], amount=amount)
DBSession.flush()
DBSession.commit()
示例11: add_players_command
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def add_players_command(num_of_players):
'''num_of_players: Numero de jogadores'''
for p in range(int(num_of_players)):
player_name = 'Jogador {}'.format(p + 1)
player = Player(player_name=player_name)
DBSession.add(player)
player = Player(player_name='Banqueiro', balance=float(1000000.00))
DBSession.add(player)
DBSession.flush()
DBSession.commit()
示例12: post_spending_item
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def post_spending_item(request):
spending = m.Spending()
print(request.body)
spending.amount = request.get_json('amount')
spending.category_id = request.get_json('categoryId')
spending.incurred_begin_date = request.get_json('incurredBeginDate')
spending.incurred_end_date = request.get_json('incurredEndDate')
spending.note = request.get_json('note')
spending.paid_date = request.get_json('paidDate')
spending.recipient = request.get_json('recipient')
DBSession.add(spending)
DBSession.flush()
return spending.spending_id
示例13: add_servers
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def add_servers(self):
data = self.request.json
with transaction.manager:
server = Server(**data)
DBSession.add(server)
DBSession.flush()
qs = DBSession.query(Server)
qs.session.refresh(server)
return {
'uid': server.uid,
'address': server.address,
'port': server.port,
'useSSL': server.useSSL
}
示例14: userSignup
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def userSignup(request):
name = request.POST['name']
email = request.POST['email']
password = hashlib.sha256(request.POST['password']).hexdigest()
dbFoundUser = DBSession.query(User.id).filter(User.email == email).first()
if dbFoundUser:
return dict(status = 0)
userToSave = User(name,email,password)
DBSession.add(userToSave)
DBSession.flush()
headers = remember(request,userToSave.id)
return HTTPFound(location = request.route_url('home'), headers = headers)
示例15: postLike
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import flush [as 别名]
def postLike(request):
currentUser = int(authenticated_userid(request))
postId = int(request.matchdict['post_id'])
liked = DBSession.query(PostLike).\
filter(and_(PostLike.post_id == postId,PostLike.user_id == currentUser)).\
first()
if liked != None:
return {'status' : 'Already UpVoted'}
newPostLike = PostLike(postId,currentUser)
DBSession.add(newPostLike)
DBSession.flush()
return {'status' : 'UpVoted'}