本文整理汇总了Python中archeologicaladdressbook.model.Session.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Session.commit方法的具体用法?Python Session.commit怎么用?Python Session.commit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类archeologicaladdressbook.model.Session
的用法示例。
在下文中一共展示了Session.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_04_cascade_delete
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_04_cascade_delete(self):
""" Test for cascade delete on the `Address` model."""
person = Session.query(model.Person).filter_by().first()
Session.delete(person)
Session.commit()
addresses = Session.query(model.Address).filter_by(person_id=person.person_id).count()
assert addresses == 0
示例2: test_04_cascade_delete
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_04_cascade_delete(self):
""" Test for cascade delete on the `Photo` model."""
person = Session.query(model.Person).filter_by().first()
Session.delete(person)
Session.commit()
photos = Session.query(model.Photo).filter_by(person_id=person.person_id).count()
assert photos == 0
示例3: test_04_cascade_delete
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_04_cascade_delete(self):
""" Test for cascade delete between `VoluntaryMember` and `Person` models."""
v_member = Session.query(model.VoluntaryMember).filter_by().first()
Session.delete(v_member)
Session.commit()
person = Session.query(model.Person).filter_by(person_id=v_member.person_id).count()
assert person == 0
示例4: test_03_cascade_delete
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_03_cascade_delete(self):
""" Test for cascade delete on the `Excavation` model."""
person = Session.query(model.Person).filter_by().first()
Session.delete(person)
Session.commit()
excavations = Session.query(model.Excavation). \
filter_by(person_id=person.person_id).count()
assert excavations == 0
示例5: create
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def create(self):
""" Add a new excavation record for a person in the database."""
person_id = self.form_result['person_id']
person = Session.query(Person).get(person_id)
excavation = Excavation(**self.form_result)
person.excavations.append(excavation)
Session.commit()
flash_message(_("New excavation record added"), 'success')
return redirect(url.current(action='show', id=excavation.excavation_id))
示例6: create
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def create(self):
""" Add a new address record for a person in the database."""
person_id = self.form_result['person_id']
person = Session.query(Person).get(person_id)
address = Address(**self.form_result)
person.addresses.append(address)
Session.commit()
flash_message(_("New address record added"), 'success')
return redirect(url.current(action='show', id=address.address_id))
示例7: test_05_orphans
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_05_orphans(self):
""" Test that orphans are forbidden for the `Photo` model."""
test_photo = OrphanPhotoData.JohnSmithPhoto()
photo = model.Photo(path=test_photo.path)
Session.add(photo)
try:
Session.commit()
raise AssertionError('`Photo` delete-orphans constraint is missing.')
except sa.exc.FlushError:
Session.rollback()
示例8: create
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def create(self):
""" Add a new person record in the database."""
# check first for a duplicate entry
self._check_duplicate(self.form_result)
# create the record
person = Person(**self.form_result)
Session.add(person)
Session.commit()
flash_message(_("New person record added"), 'success')
return redirect(url.current(action='show', id=person.person_id))
示例9: delete
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def delete(self, id=None):
""" Delete an existing excavation record."""
excavation = Session.query(Excavation).get(id)
if excavation:
Session.delete(excavation)
Session.commit()
flash_message(_("Excavation record deleted"), 'success')
return redirect(url.current(action='index'))
else:
flash_message(_("This record did not exist"), 'warning')
return redirect(url.current(action='index', id=None))
示例10: delete
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def delete(self, id=None):
""" Delete an existing address record."""
address = Session.query(Address).get(id)
if address:
Session.delete(address)
Session.commit()
flash_message(_("Address record deleted"), 'success')
return redirect(url.current(action='index'))
else:
flash_message(_("This record did not exist"), 'warning')
return redirect(url.current(action='index', id=None))
示例11: update
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def update(self, id=None):
""" Update an existing address record."""
address = Session.query(Address).get(id)
if address:
# update record attributes
for key, value in self.form_result.items():
setattr(address, key, value)
Session.commit()
flash_message(_("Address record updated"), 'success')
return redirect(url.current(action='show', id=address.address_id))
else:
flash_message(_("This record did not exist"), 'warning')
return redirect(url.current(action='index', id=None))
示例12: test_02_unique_constraint
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_02_unique_constraint(self):
""" Test for unique constraint for the `Photo` model.
Test the unique constraint on `path`.
"""
test_photo = DuplicatePhotoData.JohnDoePhoto()
person = Session.query(model.Person).filter_by().first()
person.photo = model.Photo(path=test_photo.path)
try:
Session.commit()
raise AssertionError('`Photo` unique constraint on `path` is missing.')
except sa.exc.IntegrityError:
Session.rollback()
示例13: update
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def update(self, id=None):
""" Update an existing person record."""
person = Session.query(Person).get(id)
if person:
# check first for a duplicate entry
self._check_duplicate(self.form_result, person.person_id)
# update record attributes
for key, value in self.form_result.items():
setattr(person, key, value)
Session.commit()
flash_message(_("Person record updated"), 'success')
return redirect(url.current(action='show', id=person.person_id))
else:
flash_message(_("This record did not exist"), 'warning')
return redirect(url.current(action='index', id=None))
示例14: test_02_unique_constraint
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_02_unique_constraint(self):
""" Test for unique constraint for the `Permission` model.
Test the unique constraint on `group_name`.
"""
test_permission = DuplicatePermissionData.View()
permission = model.Permission(
permission_name=test_permission.permission_name,
description=test_permission.description
)
Session.add(permission)
try:
Session.commit()
raise AssertionError('`Permission` unique constraint on `group_name`, is missing.')
except sa.exc.IntegrityError:
Session.rollback()
示例15: test_04_orphans
# 需要导入模块: from archeologicaladdressbook.model import Session [as 别名]
# 或者: from archeologicaladdressbook.model.Session import commit [as 别名]
def test_04_orphans(self):
""" Test that orphans are forbidden for the `Excavation` model."""
test_excavation = OrphanExcavationData.ExcavationSite2()
excavation = model.Excavation(
site_name=test_excavation.site_name,
start_date=test_excavation.start_date,
end_date=test_excavation.end_date,
appreciation=test_excavation.appreciation
)
Session.add(excavation)
try:
Session.commit()
raise AssertionError("`Excavation` delete-orphans constraint \
is missing.")
except sa.exc.FlushError:
Session.rollback()