本文整理汇总了Python中models.db.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:hugarsthealth,项目名称:tapin-portal,代码行数:7,代码来源:test.py
示例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")
开发者ID:cruor99,项目名称:sadpandareader,代码行数:7,代码来源:gallerypreviewscreen.py
示例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
开发者ID:kejukeji,项目名称:pub_py,代码行数:33,代码来源:user_function.py
示例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)
开发者ID:ungarst,项目名称:p4p_svr,代码行数:35,代码来源:receipt_routes.py
示例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")
开发者ID:cruor99,项目名称:sadpandareader,代码行数:25,代码来源:frontscreen.py
示例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
开发者ID:pesome,项目名称:pub_py,代码行数:26,代码来源:user_function.py
示例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())
开发者ID:hugarsthealth,项目名称:tapin-portal,代码行数:34,代码来源:tapin.py
示例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()
开发者ID:jcgharvey,项目名称:vsm-svr,代码行数:7,代码来源:test.py
示例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()
开发者ID:ungarst,项目名称:p4p_svr,代码行数:31,代码来源:standard_sample_data.py
示例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")
开发者ID:cruor99,项目名称:sadpandareader,代码行数:31,代码来源:main.py
示例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()
开发者ID:kejukeji,项目名称:pub_py,代码行数:8,代码来源:user_function.py
示例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()
开发者ID:kejukeji,项目名称:pub_py,代码行数:8,代码来源:admin_pub.py
示例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()
开发者ID:kejukeji,项目名称:pub_py,代码行数:9,代码来源:user_function.py
示例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
开发者ID:bamboodigital,项目名称:flaskboat,代码行数:9,代码来源:pipelines.py
示例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())
开发者ID:ungarst,项目名称:p4p_svr,代码行数:9,代码来源:smartcard_routes.py
示例16: new_smartcard
def new_smartcard(user):
if validate_smartcard():
user.smartcard = Smartcard(request.json["smartcard_number"], request.json["enabled"])
db.add(user)
db.commit()
return json.dumps(user.smartcard.serialize())
else:
return make_response("Incorrect data in JSON", 400)
开发者ID:ungarst,项目名称:p4p_svr,代码行数:9,代码来源:smartcard_routes.py
示例17: populate_gallery
def populate_gallery(self):
# change placehold.it with
gallerypages = float(self.pagecount) / float(40)
pageregex = re.compile('http://' + App.get_running_app().root.baseurl +
'.org/s/\S{10}/\d{6}-\d+')
if gallerypages.is_integer():
pass
else:
gallerypages += 1
headers = {'User-agent': 'Mozilla/5.0'}
cookies = App.get_running_app().root.cookies
for i in range(int(gallerypages)):
galleryrequest = requests.get(
"http://" + App.get_running_app().root.baseurl +
".org/g/{}/{}/?p={}\
"
.format(self.gallery_id, self.gallery_token, i),
headers=headers,
cookies=cookies)
soup = BS(galleryrequest.text)
for a in soup.findAll(name="a", attrs={"href": pageregex}):
self.pagelinks.append(a["href"])
existpageurl = db.query(Pagelink).filter_by(
pagelink=a["href"]).first()
if existpageurl:
pass
else:
pageurl = Pagelink(galleryid=self.db_id,
pagelink=a["href"])
db.add(pageurl)
db.commit()
# pagetimer = 0
# for page in self.pagelinks:
# Clock.schedule_once(partial(self.grab_image, page), 2*pagetimer)
# pagetimer += 1
self.next_page = 1
currentexist = db.query(Pagelink).filter_by(galleryid=self.db_id,
current=1).first()
if currentexist:
first_screen = self.construct_image(currentexist.pagelink)
self.ids.gallery_manager.switch_to(first_screen)
else:
first_screen = self.construct_image(self.pagelinks[0])
self.ids.gallery_manager.switch_to(first_screen)
# consider adding this in its own thread
firstimage = db.query(Pagelink).filter_by(
pagelink=self.pagelinks[0]).first()
firstimage.current = 1
db.commit()
开发者ID:cruor99,项目名称:sadpandareader,代码行数:56,代码来源:galleryscreen.py
示例18: add_checkin
def add_checkin(nhi, data):
c = CheckIn(**data)
c.patient_nhi = nhi
db.add(c)
db.commit()
if c.patient.latest_checkin_time is None or c.checkin_time > c.patient.latest_checkin_time:
c.patient.latest_checkin_time = c.checkin_time
db.commit()
return c
开发者ID:hugarsthealth,项目名称:tapin-portal,代码行数:12,代码来源:tapin.py
示例19: save_activity_thumbnail
def save_activity_thumbnail(picture_id):
"""通过图片ID,查找图片,生产略缩图,存储本地,然后存储数据库"""
activity_picture = ActivityPicture.query.filter(ActivityPicture.id == picture_id).first()
save_path = activity_picture.base_path + activity_picture.rel_path + '/'
picture = save_path + activity_picture.pic_name
im = Image.open(picture)
im.thumbnail((256, 256))
thumbnail_name = time_file_name(activity_picture.upload_name, sign='nail') + '.jpeg'
im.save(save_path+thumbnail_name, 'jpeg')
activity_picture.thumbnail = thumbnail_name
db.commit()
开发者ID:kejukeji,项目名称:pub_py,代码行数:12,代码来源:admin_file.py
示例20: add_vital_info
def add_vital_info(nhi, data):
v = VitalInfo(**data)
v.patient_nhi = nhi
db.add(v)
db.commit()
if v.patient.latest_check_in is None or v.check_in_time > v.patient.latest_check_in:
v.patient.latest_check_in = v.check_in_time
db.commit()
return v
开发者ID:jcgharvey,项目名称:vsm-svr,代码行数:12,代码来源:vsm.py
注:本文中的models.db.commit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论