本文整理汇总了Python中models.db.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(TestCheckIn, self).setUp()
db.add(Patient(nhi="123ABC"))
db.add(CheckIn(patient_nhi="123ABC", checkin_time=self.now))
db.commit()
示例2: search_tag
def search_tag(self, instance):
tag = instance.text
search = Search(searchterm=tag)
db.add(search)
db.commit()
App.get_running_app().root.next_screen("front_screen")
示例3: get
def get():
"""
参数:
user_id:用户登录id
"""
parser = reqparse.RequestParser()
parser.add_argument('user_id', type=str, required=True, help=u'user_id必须.')
args = parser.parse_args()
user_id = args['user_id']
resp_suc = success_dic().dic
resp_fail = fail_dic().dic
message_count = Message.query.filter(Message.receiver_id == user_id).count()
if message_count > 1:
messages = Message.query.filter(Message.receiver_id == user_id).all()
for message in messages:
db.delete(message)
try:
db.commit()
except:
return resp_fail
return resp_suc
else:
message = Message.query.filter(Message.receiver_id == user_id).first()
db.delete(message)
try:
db.commit()
except:
return resp_fail
return resp_suc
示例4: receipts
def receipts(user_id):
user = User.query.filter_by(id=user_id).first()
if not user:
return make_response("User " + str(user_id) + " doesn't exist", 404)
if request.method == "POST":
if validate_request_receipt():
receipt_date = date_string_to_datetime(request.json["date_time"])
receipt = Receipt(request.json["store_name"],
request.json["category"],
request.json["total_transaction"],
receipt_date)
user.receipts.append(receipt)
for item in request.json["items"]:
if validate_item(item):
item = PurchasedItem(item["name"],
request.json["category"],
item["price_per_item"],
item["quantity"])
receipt.purchased_items.append(item)
db.add(user)
db.commit()
return json.dumps({"receipt": receipt.serialize()})
else: #request is a get and return the receipts of the user
return get_user_receipts(user)
示例5: enter_gallery
def enter_gallery(self, instance):
galleryinfo = [instance.gallery_id, instance.gallery_token,
instance.pagecount, instance.gallery_name,
instance.gallery_tags, instance.gallery_thumb, instance.filesize]
existgallery = db.query(Gallery).filter_by(
gallery_id=instance.gallery_id).first()
if existgallery:
pass
else:
gallery = Gallery(gallery_id=instance.gallery_id,
gallery_token=instance.gallery_token,
pagecount=instance.pagecount,
gallery_name=instance.gallery_name,
gallery_thumb=instance.gallery_thumb,
filesize=instance.filesize)
db.add(gallery)
db.commit()
for tag in instance.gallery_tags:
gallerytag = GalleryTags(galleryid=gallery.id, tag=tag)
db.add(gallerytag)
db.commit()
preview_screen = App.get_running_app(
).root.ids.sadpanda_screen_manager.get_screen("gallery_preview_screen")
preview_screen.gallery_id = instance.gallery_id
App.get_running_app().root.next_screen("gallery_preview_screen")
示例6: get
def get():
"""
所需参数
user_id: 必传,登录用户的id
pub_id: 必传,用户点击收藏的当前酒吧的id
"""
parser = reqparse.RequestParser()
parser.add_argument('user_id', type=str, required=True, help=u'用户登录user_id必须。')
parser.add_argument('pub_id', type=str, required=True, help=u'当前酒吧pub_id必须。')
args = parser.parse_args()
user_id = int(args['user_id'])
pub_id = int(args['pub_id'])
resp_suc = {}
# 先判断用户是否已经收藏此酒吧
check_collect = Collect.query.filter(Collect.user_id == user_id, Collect.pub_id == pub_id).count()
if check_collect >= 1:
resp_suc['message'] = 'again'
resp_suc['status'] = 2
else:
collect = Collect(user_id, pub_id)
db.add(collect)
db.commit()
resp_suc['message'] = 'success'
resp_suc['status'] = 0
return resp_suc
示例7: patients
def patients():
query = Patient.query.join(Department.patients).filter(
Department.department_name == request.cookies.get('department', 'default'))
if request.method == "GET":
offset = int(request.args.get('offset', 0))
limit = int(request.args.get('limit', 100))
return make_response((json.dumps([
p.serialize() for p in query
.order_by(desc(Patient.latest_checkin_time))
.offset(offset)
.limit(limit)
.all()
]), 200, {"Content-Type": "application/json"}))
elif request.method == "POST":
patient_data = json.loads(request.data)
patient = Patient(**patient_data)
patient = db.merge(patient)
db.commit()
department = Department.query.filter_by(
department_name=request.cookies.get('department', 'default')).first()
if department:
patient.departments.append(department)
db.commit()
if 'checkin' in patient_data:
add_checkin(patient.nhi, patient_data['checkin'])
return jsonify(patient.serialize())
示例8: setUp
def setUp(self):
super(TestVitalInfo, self).setUp()
db.add(Patient(nhi="123ABC"))
db.add(VitalInfo(patient_nhi="123ABC", check_in_time=self.now))
db.commit()
示例9: add_receipt
def add_receipt(num_receipts=1):
user = User.query.first()
days_ago_to_start = num_receipts/2
date = datetime.now() - timedelta(days=days_ago_to_start)
even_receipt = True
for x in range(num_receipts):
SHOP_NAME = "Countdown Birkenhead"
SHOP_CATEGORY = "Groceries"
TOTAL = 123.81
r = Receipt(SHOP_NAME, SHOP_CATEGORY, TOTAL, date)
r.purchased_items = [
PurchasedItem("Chocolate Milk", SHOP_CATEGORY, 3.99, 2),
PurchasedItem("Garlic Pita Breads", SHOP_CATEGORY, 4.50, 1),
PurchasedItem("Old Spice Deoderant", SHOP_CATEGORY, 6.21, 4),
PurchasedItem("Eye Fillet Steak", SHOP_CATEGORY, 21.4, 1),
PurchasedItem("Obikwa Wine 750mL", SHOP_CATEGORY, 6.99, 4),
PurchasedItem("North Shore Rubbish Sack", SHOP_CATEGORY, 4.99, 5),
PurchasedItem("Nutri-Grain 700g", SHOP_CATEGORY, 6.23, 1),
PurchasedItem("Olivio Butter", SHOP_CATEGORY, 5.95, 1)
]
user.receipts.append(r)
even_receipt = not even_receipt
if even_receipt:
date = date + timedelta(days=1)
print len(user.receipts)
db.add(user)
db.commit()
示例10: login_exhentai
def login_exhentai(self, username, password):
self.username = username.text
self.password = password.text
payload = {
"UserName": username.text,
"PassWord": password.text,
"returntype": "8",
"CookieDate": "1",
"b": "d",
"bt": "pone"
}
headers = {'User-Agent': 'Mozilla/5.0'}
r = requests.post(
"https://forums.e-hentai.org/index.php?act=Login&CODE=01",
data=payload,
headers=headers)
if len(r.cookies) <= 1:
captchapopup = CaptchaPopup()
captchapopup.bind(on_dismiss=self.login_captcha)
captchapopup.open()
else:
self.cookies = r.cookies
cookies = User(cookies=str(self.cookies))
db.add(cookies)
db.commit()
self.baseurl = "exhentai"
self.next_screen("front_screen")
示例11: direct_message_count
def direct_message_count(direct_message):
if type(direct_message) is list:
for message in direct_message:
message.view = 1
db.commit()
else:
direct_message.view = 1
db.commit()
示例12: save_pub_type
def save_pub_type(pub_id, types):
"""保存酒吧类型"""
type_list = [int(i) for i in types.split(",")]
for pub_type in type_list:
db.add(PubTypeMid(pub_id, pub_type))
db.commit()
示例13: message_type
def message_type(user_id, system_message):
user = User.query.filter(User.id == user_id).first()
if type(system_message) is list:
user.system_message_time = todayfstr()
db.commit()
else:
if system_message:
user.system_message_time = todayfstr()
db.commit()
示例14: process_item
def process_item(self, item, spider):
# create a new SQL Alchemy object and add to the db session
record = AllData(title=item['title'][0].decode('unicode_escape'),
url=item['url'][0],
desc=item['desc'])
db.add(record)
db.commit()
return item
示例15: update_smartcard_status
def update_smartcard_status(smartcard):
if not "enabled" in request.json:
return make_response("Incorrect data in json", 400)
smartcard.enabled = request.json["enabled"]
db.add(smartcard)
db.commit()
return json.dumps(smartcard.serialize())