本文整理匯總了Python中c3smembership.models.DBSession.flush方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.flush方法的具體用法?Python DBSession.flush怎麽用?Python DBSession.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類c3smembership.models.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def setUp(self):
super(C3sMembershipModelTests, self).setUp()
with transaction.manager:
member1 = C3sMember( # german
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'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
DBSession.add(member1)
DBSession.flush()
示例2: verify_mailaddress_conf
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def verify_mailaddress_conf(request):
'''
let member confirm her email address by clicking a link
'''
user_email = request.matchdict['email']
refcode = request.matchdict['refcode']
token = request.matchdict['token']
# try to get entry from DB
afm = C3sMember.get_by_code(refcode)
if isinstance(afm, NoneType): # no entry?
#print "entry not found"
return {
'confirmed': False,
'firstname': 'foo',
'lastname': 'bar',
'result_msg': 'bad URL / bad codes. please contact [email protected]!',
}
# check token
if ('_used' in afm.email_confirm_token): # token was invalidated already
#print "the token is empty"
return {
'confirmed': False,
'firstname': afm.firstname,
'lastname': afm.lastname,
'result_msg': 'your token is invalid. please contact [email protected]!',
}
try:
assert(afm.email_confirm_token in token)
assert(token in afm.email_confirm_token)
assert(afm.email in user_email)
assert(user_email in afm.email)
except:
return {
'confirmed': False,
'firstname': 'foo',
'lastname': 'bar',
'result_msg': 'bad token/email. please contact [email protected]!',
}
afm.email_is_confirmed = True
afm.email_confirm_token += u'_used'
DBSession.flush()
# notify staff
message = Message(
subject='[C3S Yes!] afm email confirmed',
sender='[email protected]',
recipients=[request.registry.settings['c3smembership.mailaddr'], ],
body=u'see {}/detail/{}'.format(
request.registry.settings['c3smembership.url'],
afm.id)
)
mailer = get_mailer(request)
mailer.send(message)
return {
'confirmed': True,
'firstname': afm.firstname,
'lastname': afm.lastname,
'result_msg': u'',
}
示例3: setUp
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.close()
DBSession.remove()
#print("removed old DBSession ===================================")
except:
#print("no DBSession to remove ==================================")
pass
#try:
# os.remove('test_webtest_functional.db')
# #print "deleted old test database"
#except:
# pass
# #print "never mind"
my_settings = {
#'sqlalchemy.url': 'sqlite:///test_webtest_functional.db',
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.mailaddr': '[email protected]'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
self.session = DBSession # ()
Base.metadata.create_all(engine)
# dummy database entries for testing
with transaction.manager:
member1 = C3sMember( # german
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'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
DBSession.add(member1)
DBSession.flush()
from c3smembership import main
app = main({}, **my_settings)
from webtest import TestApp
self.testapp = TestApp(app)
示例4: setUp
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.remove()
except:
pass
#engine = create_engine('sqlite:///test_model_staff.db')
engine = create_engine('sqlite://')
self.session = DBSession
self.session.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
group1 = Group(name=u'staff')
group2 = Group(name=u'staff2')
DBSession.add(group1, group2)
DBSession.flush()
示例5: setUp
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def setUp(self):
"""
set up everything for a test case
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.close()
DBSession.remove()
#print("removing old DBSession ===================================")
except:
#print("no DBSession to remove ===================================")
pass
from sqlalchemy import create_engine
#engine = create_engine('sqlite:///test_utils.db')
engine = create_engine('sqlite:///:memory:')
DBSession.configure(bind=engine)
self.session = DBSession # ()
Base.metadata.create_all(engine)
with transaction.manager:
member1 = C3sMember( # german
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'ABCDEFGBAR',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
DBSession.add(member1)
DBSession.flush()
示例6: main
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def main(argv=sys.argv):
"""
initialize the database
"""
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
# add some content
with transaction.manager:
# a group for accountants/staff
accountants_group = Group(name=u"staff")
try:
DBSession.add(accountants_group)
DBSession.flush()
#print("adding group staff")
except:
print("could not add group staff.")
# pass
with transaction.manager:
# staff personnel
staffer1 = C3sStaff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
try:
DBSession.add(staffer1)
#print("adding staff rut")
DBSession.flush()
except:
print("it borked! (rut)")
# pass
# one more staffer
with transaction.manager:
staffer2 = C3sStaff(
login=u"reel",
password=u"boo",
email=u"[email protected]",
)
staffer2.groups = [accountants_group]
try:
DBSession.add(staffer2)
#print("adding staff reel")
DBSession.flush()
except:
print("it borked! (reel)")
# pass
# a member, actually a membership form submission
with transaction.manager:
member1 = C3sMember(
firstname=u"Firstnäme", # includes umlaut
lastname=u"Lastname",
email=u"[email protected]",
password=u"berries",
address1=u"address one",
address2=u"address two",
postcode=u"12345 foo",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"en",
date_of_birth=date.today(),
email_is_confirmed=False,
email_confirm_code=u"ABCDEFGHIJ",
num_shares=u'10',
date_of_submission=datetime.now(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
)
try:
DBSession.add(member1)
#print("adding Firstnäme")
except:
pass
# even more members
import random
import string
print("about to add %s members..." % how_many)
with transaction.manager:
for i in range(how_many): # create 50 members with semi-random dates
#print i
member = C3sMember(
firstname=u"Firstnäme%s" % i, # includes umlaut
lastname=u"Lastname",
email=u"[email protected]",
password=u"berries",
address1=u"address one",
address2=u"address two",
postcode=u"12345 foo",
city=u"Footown Mäh",
country=u"Foocountry",
locale=u"de",
date_of_birth=date.today(),
#.........這裏部分代碼省略.........
示例7: staff_view
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
#.........這裏部分代碼省略.........
if 'action' in request.POST:
#print(request.POST['id'])
try:
_staffer = C3sStaff.get_by_id(int(request.POST['id']))
except:
# print("exception!")
return HTTPFound(location=request.route_url('staff'))
#print(request.POST['action'])
if request.POST['action'] == u'delete':
#print("will delete staff id %s" % _staffer.id)
C3sStaff.delete_by_id(_staffer.id)
#print("deleted staff id %s" % _staffer.id)
# send mail
encrypted = encrypt_with_gnupg('''hi,
%s was deleted from the backend by %s.
best,
your membership tool''' % (_staffer.login,
request.authenticated_userid))
message = Message(
subject='[C3S Yes] staff was deleted.',
sender='[email protected]',
recipients=[
request.registry.settings['c3smembership.mailaddr']],
body=encrypted
)
mailer = get_mailer(request)
mailer.send(message)
return HTTPFound(location=request.route_url('staff'))
elif request.POST['action'] == 'edit':
appstruct = {
'login': _staffer.login,
'password': '_UNCHANGED_',
}
stafferform.set_appstruct(appstruct)
if 'new_staffer' in request.POST:
#print "new staffer!"
controls = request.POST.items()
try:
appstruct = stafferform.validate(controls)
#print('validated!')
except ValidationFailure, e:
return {
'stafferform': e.render()
}
# XXX login must be unique!
existing = C3sStaff.get_by_login(appstruct['login'])
if existing is not None:
#print "that staffer exists!"
if u'_UNCHANGED_' in appstruct['password']:
pass
else:
existing.password = appstruct['password']
existing.last_password_change = datetime.now()
encrypted = encrypt_with_gnupg('''hi,
the password of %s was changed by %s.
best,
your membership tool''' % (existing.login,
request.authenticated_userid))
message = Message(
subject='[C3S Yes] staff password changed.',
sender='[email protected]',
recipients=[
request.registry.settings['c3smembership.mailaddr']],
body=encrypted
)
else: # create new entry
staffer = C3sStaff(
login=appstruct['login'],
password=appstruct['password'],
email=u'',
)
staffer.groups = [Group.get_staffers_group()]
#print "about to add user"
DBSession.add(staffer)
DBSession.flush()
print "added staffer"
# send mail
encrypted = encrypt_with_gnupg('''hi,
%s was added to the backend by %s.
best,
your membership tool''' % (staffer.login,
request.authenticated_userid))
message = Message(
subject='[C3S Yes] staff was added.',
sender='[email protected]',
recipients=[
request.registry.settings['c3smembership.mailaddr']],
body=encrypted
)
mailer = get_mailer(request)
mailer.send(message)
return HTTPFound(
request.route_url('staff')
)
示例8: setUp
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.close()
DBSession.remove()
#print "closed and removed DBSession"
except:
pass
#print "no session to close"
#try:
# os.remove('test_import.db')
# #print "deleted old test database"
#except:
# pass
# #print "never mind"
# self.session = DBSession()
my_settings = {
#'sqlalchemy.url': 'sqlite:///test_import.db',
'sqlalchemy.url': 'sqlite:///:memory:',
'available_languages': 'da de en es fr',
'c3smembership.dashboard_number': '30'}
engine = engine_from_config(my_settings)
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
with transaction.manager:
member1 = C3sMember( # german
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'ABCDEFGFOO',
password=u'arandompassword',
date_of_submission=date.today(),
membership_type=u'normal',
member_of_colsoc=True,
name_of_colsoc=u"GEMA",
num_shares=u'23',
)
DBSession.add(member1)
DBSession.flush()
self.m1_last_pw_change = member1.last_password_change
with transaction.manager:
# a group for accountants/staff
accountants_group = Group(name=u"staff")
try:
DBSession.add(accountants_group)
DBSession.flush()
#print("adding group staff")
except:
#print("could not add group staff.")
pass
# staff personnel
staffer1 = C3sStaff(
login=u"rut",
password=u"berries",
email=u"[email protected]",
)
staffer1.groups = [accountants_group]
try:
DBSession.add(accountants_group)
DBSession.add(staffer1)
DBSession.flush()
except:
#print("it borked! (rut)")
pass
from c3smembership import main
app = main({}, **my_settings)
from webtest import TestApp
self.testapp = TestApp(app)
示例9: new_member
# 需要導入模塊: from c3smembership.models import DBSession [as 別名]
# 或者: from c3smembership.models.DBSession import flush [as 別名]
#.........這裏部分代碼省略.........
# data sanity: if not in collecting society, don't save
# collsoc name even if it was supplied through form
#if 'no' in appstruct['membership_info']['member_of_colsoc']:
# appstruct['membership_info']['name_of_colsoc'] = ''
# print appstruct['membership_info']['name_of_colsoc']
#print '-'*80
except ValidationFailure as e:
#print("Validation Failure!")
#print("the request.POST: %s \n" % request.POST)
#for thing in request.POST:
# print("the thing: %s") % thing
# print("type: %s") % type(thing)
#print(e.args)
#print(e.error)
#print(e.message)
request.session.flash(
_(u"Please note: There were errors, "
"please check the form below."),
'message_above_form',
allow_duplicate=False)
return{'form': e.render()}
def make_random_string():
"""
used as email confirmation code
"""
import random
import string
return u''.join(
random.choice(
string.ascii_uppercase + string.digits
) for x in range(10))
# make confirmation code and
randomstring = make_random_string()
# check if confirmation code is already used
while (C3sMember.check_for_existing_confirm_code(randomstring)):
# create a new one, if the new one already exists in the database
randomstring = make_random_string() # pragma: no cover
# to store the data in the DB, an objet is created
member = C3sMember(
firstname=appstruct['person']['firstname'],
lastname=appstruct['person']['lastname'],
email=appstruct['person']['email'],
password='UNSET',
address1=appstruct['person']['address1'],
address2=appstruct['person']['address2'],
postcode=appstruct['person']['postcode'],
city=appstruct['person']['city'],
country=appstruct['person']['country'],
locale=appstruct['person']['_LOCALE_'],
date_of_birth=appstruct['person']['date_of_birth'],
email_is_confirmed=False,
email_confirm_code=randomstring,
#is_composer=('composer' in appstruct['activity']),
#is_lyricist=('lyricist' in appstruct['activity']),
#is_producer=('music producer' in appstruct['activity']),
#is_remixer=('remixer' in appstruct['activity']),
#is_dj=('dj' in appstruct['activity']),
date_of_submission=datetime.now(),
#invest_member=(
# appstruct['membership_info']['invest_member'] == u'yes'),
membership_type=appstruct['membership_info']['membership_type'],
member_of_colsoc=(
appstruct['membership_info']['member_of_colsoc'] == u'yes'),
name_of_colsoc=appstruct['membership_info']['name_of_colsoc'],
#opt_band=appstruct['opt_band'],
#opt_URL=appstruct['opt_URL'],
num_shares=appstruct['shares']['num_shares'],
)
dbsession = DBSession()
try:
_temp = request.url.split('?')[1].split('=')
if 'id' in _temp[0]:
_id = _temp[1]
#print("the id we want to recreate: %s" % _id)
# add a member with a DB id that had seen its entry deleted before
_mem = C3sMember.get_by_id(_id) # load from id
if isinstance(_mem, NoneType): # check deletion status
member.id = _id # set id as specified
except:
#print "no splitable url params found, creating new entry"
pass
# add member at next free DB id (default if member.id not set)
try:
dbsession.add(member)
dbsession.flush()
#print(member.id)
the_new_id = member.id
#appstruct['email_confirm_code'] = randomstring # ???
except InvalidRequestError, e: # pragma: no cover
print("InvalidRequestError! %s") % e
except IntegrityError, ie: # pragma: no cover
print("IntegrityError! %s") % ie