本文整理汇总了Python中c3smembership.data.model.base.DBSession.delete方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.delete方法的具体用法?Python DBSession.delete怎么用?Python DBSession.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c3smembership.data.model.base.DBSession
的用法示例。
在下文中一共展示了DBSession.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_testing_db
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import delete [as 别名]
def init_testing_db():
"""
Initializes the memory database with test samples.
"""
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:', }
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
# There is a side effect of test_initialization.py after which there
# are still records in the database although it is setup from scratch.
# Therefore, remove all members to have an empty table.
# pylint: disable=no-member
members = C3sMember.get_all()
for member in members:
DBSession.delete(member)
DBSession.flush()
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2014,
u'1. ordentliche Generalversammlung',
date(2014, 8, 23)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2015,
u'2. ordentliche Generalversammlung',
date(2015, 6, 13)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2015_2,
u'Außerordentliche Generalversammlung',
date(2015, 7, 16)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2016,
u'3. ordentliche Generalversammlung',
date(2016, 4, 17)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2017,
u'4. ordentliche Generalversammlung',
date(2017, 4, 2)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2018,
u'5. ordentliche Generalversammlung',
date(2018, 6, 3)))
DBSession.add(GeneralAssembly(
GENERAL_ASSEMBLY_NUMBER_2018_2,
u'Außerordentliche Generalversammlung',
date(2018, 12, 1)))
# German person
member1 = C3sMember(
firstname=u'SomeFirstnäme',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFG1',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=False,
name_of_colsoc=u"",
num_shares=u'23',
)
# English person
member2 = C3sMember(
firstname=u'AAASomeFirstnäme',
lastname=u'XXXSomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
postcode=u"12345",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"en",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u'ABCDEFG2',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=False,
name_of_colsoc=u"",
num_shares=u'23',
)
# German legal entity
member3 = C3sMember(
firstname=u'Cooles PlattenLabel',
lastname=u'SomeLastnäme',
email=u'[email protected]',
address1=u"addr one",
address2=u"addr two",
#.........这里部分代码省略.........
示例2: merge_member_view
# 需要导入模块: from c3smembership.data.model.base import DBSession [as 别名]
# 或者: from c3smembership.data.model.base.DBSession import delete [as 别名]
def merge_member_view(request):
"""
Merges member duplicates into one member record.
Some people have more than one entry in our C3SMember table,
e.g. because they used the application form more than once
to acquire more shares.
They shall not, however, become members twice and get more than one
membership number. So we try and merge them:
If a person is already a member and acquires a second package of shares,
this package of shares is added to the former membership entry.
The second entry in the C3sMember table is given the 'is_duplicate' flag
and also the 'duplicate_of' is given the *id* of the original entry.
"""
afm_id = request.matchdict['afm_id']
member_id = request.matchdict['mid']
if DEBUG: # pragma: no cover
print "shall merge {} to {}".format(afm_id, member_id)
orig = C3sMember.get_by_id(member_id)
merg = C3sMember.get_by_id(afm_id)
if not orig.membership_accepted:
request.session.flash(
'you can only merge to accepted members!',
'danger')
HTTPFound(request.route_url('make_member', afm_id=afm_id))
exceeds_60 = int(orig.num_shares) + int(merg.num_shares) > 60
if exceeds_60:
request.session.flash(
'merger would exceed 60 shares!',
'danger')
return HTTPFound(request.route_url('make_member', afm_id=afm_id))
# TODO: this needs fixing!!!
# date must be set manually according to date of approval of the board
shares_date_of_acquisition = merg.signature_received_date if (
merg.signature_received_date > merg.payment_received_date
) else merg.payment_received_date
share_acquisition = request.registry.share_acquisition
share_id = share_acquisition.create(
orig.membership_number,
merg.num_shares,
shares_date_of_acquisition)
share_acquisition.set_signature_reception(
share_id,
date(
merg.signature_received_date.year,
merg.signature_received_date.month,
merg.signature_received_date.day))
share_acquisition.set_signature_confirmation(
share_id,
date(
merg.signature_confirmed_date.year,
merg.signature_confirmed_date.month,
merg.signature_confirmed_date.day))
share_acquisition.set_payment_reception(
share_id,
date(
merg.payment_received_date.year,
merg.payment_received_date.month,
merg.payment_received_date.day))
share_acquisition.set_payment_confirmation(
share_id,
date(
merg.payment_confirmed_date.year,
merg.payment_confirmed_date.month,
merg.payment_confirmed_date.day))
share_acquisition.set_reference_code(
share_id,
merg.email_confirm_code)
DBSession.delete(merg)
return HTTPFound(request.route_url('detail', member_id=member_id))