本文整理汇总了Python中c3smembership.models.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
self.config.registry.settings['c3smembership.url'] = 'http://foo.com'
self.config.registry.settings['c3smembership.mailaddr'] = '[email protected]'
DBSession.remove()
self.session = _initTestingDB()
示例2: tearDown
def tearDown(self):
"""
clean up after a test case
"""
DBSession.close()
DBSession.remove()
testing.tearDown()
示例3: verify_mailaddress_conf
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'',
}
示例4: setUp
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()
示例5: tearDown
def tearDown(self):
# maybe I need to check and remove globals here,
# so the other tests are not compromised
#del engine
from c3smembership.models import DBSession
DBSession.close()
DBSession.remove()
示例6: init
def init():
#config_uri = 'development.ini'
#setup_logging(config_uri)
#settings = get_appsettings(config_uri)
#engine = engine_from_config('sqlite://')
engine = engine_from_config({'sqlalchemy.url': 'sqlite://'})
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
示例7: main
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
engine = engine_from_config(settings, 'sqlalchemy.')
session_factory = session_factory_from_settings(settings)
authn_policy = AuthTktAuthenticationPolicy(
's0secret!!',
callback=groupfinder,)
authz_policy = ACLAuthorizationPolicy()
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings,
authentication_policy=authn_policy,
authorization_policy=authz_policy,
session_factory=session_factory,
root_factory=Root)
# using a custom request with user information
config.set_request_factory(RequestWithUserAttribute)
config.include('pyramid_mailer')
config.add_translation_dirs(
'colander:locale/',
'deform:locale/',
'c3smembership:locale/')
config.add_static_view('static',
'c3smembership:static', cache_max_age=3600)
config.add_subscriber('c3smembership.subscribers.add_base_template',
'pyramid.events.BeforeRender')
config.add_subscriber('c3smembership.subscribers.add_locale_to_cookie',
'pyramid.events.NewRequest')
# home is /, the membership application form
config.add_route('join', '/')
# info pages
config.add_route('disclaimer', '/disclaimer')
config.add_route('faq', '/faq')
config.add_route('statute', '/statute')
config.add_route('manifesto', '/manifesto')
# success and further steps
config.add_route('success', '/success')
config.add_route('success_check_email', '/check_email')
config.add_route('verify_email_password', '/verify/{email}/{code}')
config.add_route('success_pdf', '/C3S_SCE_AFM_{namepart}.pdf')
# routes & views for staff
config.add_route('dashboard', '/dashboard/{number}')
config.add_route('detail', '/detail/{memberid}')
config.add_route('switch_sig', '/switch_sig/{memberid}')
config.add_route('switch_pay', '/switch_pay/{memberid}')
config.add_route('delete_entry', '/delete/{memberid}')
config.add_route('login', '/login')
config.add_route('logout', '/logout')
config.scan()
return config.make_wsgi_app()
示例8: setUp
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)
示例9: setUp
def setUp(self):
"""
set up everything for a test case
"""
self.config = testing.setUp()
self.config.include('pyramid_mailer.testing')
try:
DBSession.remove()
except:
pass
self.session = _initTestingDB()
示例10: _initTestingDB
def _initTestingDB():
from sqlalchemy import create_engine
from c3smembership.models import DBSession
from c3smembership.models import Base
from c3smembership.models import initialize_sql
engine = create_engine('sqlite:///:memory:')
#session = initialize_sql(create_engine('sqlite:///:memory:'))
DBSession.configure(bind=engine)
Base.metadata.bind = engine
Base.metadata.create_all(engine)
return DBSession
示例11: setUp
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()
示例12: _initTestingDB
def _initTestingDB():
#from sqlalchemy import create_engine
#from c3smembership.models import initialize_sql
#session = initialize_sql(create_engine('sqlite:///memory'))
#session = DBSession
my_settings = {
'sqlalchemy.url': 'sqlite:///:memory:', }
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',
)
member2 = C3sMember( # german
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"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.add(member2)
return DBSession
示例13: setUp
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()
示例14: join_c3s
#.........这里部分代码省略.........
],
use_ajax=True,
renderer=zpt_renderer
)
# if the form has NOT been used and submitted, remove error messages if any
if not 'submit' in request.POST:
request.session.pop_flash()
# if the form has been used and SUBMITTED, check contents
if 'submit' in request.POST:
controls = request.POST.items()
try:
appstruct = form.validate(controls)
#print("the appstruct from the form: %s \n") % appstruct
#for thing in appstruct:
# print("the thing: %s") % thing
# print("type: %s") % type(thing)
# 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, e:
#print("the appstruct from the form: %s \n") % appstruct
#for thing in appstruct:
# print("the thing: %s") % thing
# print("type: %s") % type(thing)
print(e)
#message.append(
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 ''.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
from datetime import datetime
from sqlalchemy.exc import (
InvalidRequestError,
IntegrityError
)
# 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=appstruct['person']['password'],
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:
dbsession.add(member)
appstruct['email_confirm_code'] = randomstring
except InvalidRequestError, e: # pragma: no cover
print("InvalidRequestError! %s") % e
示例15: main
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(),
#.........这里部分代码省略.........