本文整理汇总了Python中sqlahelper.get_base函数的典型用法代码示例。如果您正苦于以下问题:Python get_base函数的具体用法?Python get_base怎么用?Python get_base使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_base函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test1
def test1(self):
base = sqlahelper.get_base()
my_base = declarative.declarative_base()
sqlahelper.set_base(my_base)
base2 = sqlahelper.get_base()
try:
self.assertIsNot(base2, base)
self.assertIs(base2, my_base)
except AttributeError: # Python < 2.7
self.assertNotEqual(base2, base)
self.assertEqual(base2, my_base)
开发者ID:pyramid-collective,项目名称:SQLAHelper,代码行数:11,代码来源:tests.py
示例2: _init_ptah
def _init_ptah(self, handler=None, *args, **kw):
config.initialize(self.p_config, ("ptah", self.__class__.__module__), initsettings=False)
config.initialize_settings(self._settings, self.p_config)
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.drop_all()
Base.metadata.create_all()
transaction.commit()
开发者ID:WouterVH,项目名称:ptah,代码行数:9,代码来源:base.py
示例3: _init_ptah
def _init_ptah(self, settings=None, handler=None, *args, **kw):
if settings is None:
settings = self._settings
config.initialize(('ptah', self.__class__.__module__))
config.initialize_settings(settings, self.p_config)
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.drop_all()
Base.metadata.create_all()
transaction.commit()
开发者ID:blaflamme,项目名称:ptah,代码行数:11,代码来源:base.py
示例4: test_multiple_engines
def test_multiple_engines(self):
default = sa.create_engine(self.db1.url)
stats = sa.create_engine(self.db2.url)
sqlahelper.add_engine(default)
sqlahelper.add_engine(stats, "stats")
# Can we retrieve the engines?
self.assertIs(sqlahelper.get_engine(), default)
self.assertIs(sqlahelper.get_engine("default"), default)
self.assertIs(sqlahelper.get_engine("stats"), stats)
# Are the session binding and base binding set correctly?
self.assertIs(sqlahelper.get_session().bind, default)
self.assertIs(sqlahelper.get_base().metadata.bind, default)
开发者ID:pyramid-collective,项目名称:SQLAHelper,代码行数:12,代码来源:tests.py
示例5: test_multiple_engines_without_default
def test_multiple_engines_without_default(self):
db1 = sa.create_engine(self.db1.url)
db2 = sa.create_engine(self.db2.url)
sqlahelper.add_engine(db1, "db1")
sqlahelper.add_engine(db2, "db2")
# Can we retrieve the engines?
self.assertIs(sqlahelper.get_engine("db1"), db1)
self.assertIs(sqlahelper.get_engine("db2"), db2)
# There should be no default engine
self.assertIsNone(sqlahelper.get_session().bind)
self.assertIsNone(sqlahelper.get_base().metadata.bind)
self.assertIsNone(sqlahelper.get_engine())
开发者ID:pyramid-collective,项目名称:SQLAHelper,代码行数:12,代码来源:tests.py
示例6: _init_ptah
def _init_ptah(self, settings=None, handler=None, *args, **kw):
st = dict(self._settings)
if settings is not None:
st.update(settings)
config.initialize(('ptah', self.__class__.__module__),
reg = self.p_config.registry)
config.initialize_settings(st, self.p_config)
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.drop_all()
Base.metadata.create_all()
transaction.commit()
开发者ID:blaflamme,项目名称:ptah,代码行数:13,代码来源:base.py
示例7: ptah_initialize
def ptah_initialize(configurator, packages=None, autoinclude=False):
""" Initialize ptah packages.
Load all ptah packages and intialize ptah settings system.
This function automatically called by :py:func:`make_wsgi_app` function.
"""
import ptah
import sqlahelper
import transaction
from pyramid.exceptions import ConfigurationExecutionError
configurator.include('pyramid_tm')
configurator.begin()
try:
settings = configurator.registry.settings
# exclude
excludes = []
if 'ptah.excludes' in settings:
excludes.extend(s.strip()
for s in settings['ptah.excludes'].split())
# load packages
ptah.config.initialize(
configurator, packages, excludes, autoinclude, initsettings=True)
configurator.commit()
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.create_all()
# send AppStarting event
ptah.config.start(configurator)
# commit possible transaction
transaction.commit()
except Exception, e:
if isinstance(e, ConfigurationExecutionError):
e = e.evalue
if not isinstance(e, ptah.config.StopException):
ptah.config.shutdown()
e = ptah.config.StopException(e)
raise e
ptah.config.shutdown()
raise e
开发者ID:WouterVH,项目名称:ptah,代码行数:49,代码来源:__init__.py
示例8: init_ptah
def init_ptah(self, *args, **kw):
self.registry.settings.update(self._settings)
self.config.scan('ptah')
self.config.commit()
self.config.autocommit = True
ptah.init_settings(self.config, self.registry.settings)
if self._init_sqla:
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.drop_all()
Base.metadata.create_all()
transaction.commit()
开发者ID:runyaga,项目名称:ptah,代码行数:15,代码来源:testing.py
示例9: ptah_init
def ptah_init(configurator):
""" Initialize ptah packages.
Load all ptah packages and intialize ptah settings system.
This function automatically called by :py:func:`make_wsgi_app` function.
"""
import ptah
import transaction
import sqlahelper
configurator.include('pyramid_tm')
try:
settings = configurator.registry.settings
# exclude
excludes = []
if 'ptah.excludes' in settings:
excludes.extend(s.strip()
for s in settings['ptah.excludes'].split())
# load packages
ptah.config.initialize(None, excludes, configurator.registry)
# load settings
ptah.config.initialize_settings(settings, configurator)
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.create_all()
# send AppStarting event
ptah.config.start(configurator)
except Exception, e:
if not isinstance(e, ptah.config.StopException):
ptah.config.shutdown()
raise ptah.config.StopException(e)
ptah.config.shutdown()
raise
开发者ID:mcdonc,项目名称:ptah,代码行数:40,代码来源:__init__.py
示例10: main
def main():
if len(sys.argv) != 2:
sys.exit("Usage: python -m drkpr.scripts.create_db INI_FILE")
ini_file = sys.argv[1]
logging.config.fileConfig(ini_file)
log = logging.getLogger(__name__)
app = get_app(ini_file, "myapp")
settings = app.registry.settings
engine = sqlalchemy.engine_from_config(settings, prefix="sqlalchemy.",
pool_recycle=3600, convert_unicode=True)
sqlahelper.add_engine(engine)
Base = sqlahelper.get_base()
Session = sqlahelper.get_session()
log.info("Create testing user accounts ...")
random.seed("whatever")
for i in range(0,100):
sur_name = sur_names[random.randint(0, len(sur_names)-1)]
given_name = given_names[random.randint(0, len(given_names)-1)]
username = "%s.%s" % (sur_name, given_name)
try:
q = Session.query(model.DKUser)
r = q.get(username)
if not r:
user = model.DKUser()
user.username = username
user.roles = ":".join(["", model.ROLE_USER, ""])
user.passwd = hashlib.md5("cpksecurity").hexdigest()
user.master_email = "%[email protected]" % username
user.actived = True
Session.add(user)
log.info(" Account '%s' setup complete." % username)
else:
log.info("Account '%s' already setup." % username)
except Exception, e:
print e
开发者ID:dyno,项目名称:drkpr,代码行数:37,代码来源:mockup_db.py
示例11: SQLAModule
""" introspect module """
import urllib
import sqlahelper as psa
from sqlalchemy.orm.mapper import _mapper_registry
from pyramid.decorator import reify
from pyramid.httpexceptions import HTTPFound
import ptah
from ptah import config, view, form, manage
Session = psa.get_session()
metadata = psa.get_base().metadata
class SQLAModule(manage.PtahModule):
__doc__ = u'A listing of all tables with ability to view and edit records'
title = 'SQLAlchemy'
manage.module('sqla')
metadata = {}
def __getitem__(self, key):
try:
id, table = key.split('-', 1)
except:
raise KeyError(key)
md = self.metadata[id][0]
return Table(md.tables[table], self, self.request)
开发者ID:blaflamme,项目名称:ptah,代码行数:30,代码来源:sqla.py
示例12: get_bydata
def get_bydata(self, typ, data):
""" Get token for data """
t = self._sql_get_by_data.first(data=data, typ=typ.id)
if t is not None:
return t.token
def remove(self, token):
""" Remove token """
Session.query(Token).filter(
sqla.sql.or_(Token.token == token,
Token.valid > datetime.datetime.now())).delete()
service = TokenService()
Base = sqlh.get_base()
Session = sqlh.get_session()
class Token(Base):
__tablename__ = 'ptah_tokens'
id = sqla.Column(sqla.Integer, primary_key=True)
token = sqla.Column(sqla.Unicode(48))
valid = sqla.Column(sqla.DateTime)
data = sqla.Column(sqla.Unicode)
typ = sqla.Column(sqla.Unicode(48))
def __init__(self, typ, data):
super(Token, self).__init__()
开发者ID:runyaga,项目名称:ptah,代码行数:31,代码来源:token.py
示例13: main
def main():
if len(sys.argv) != 2:
sys.exit("Usage: python -m drkpr.scripts.create_db INI_FILE")
ini_file = sys.argv[1]
logging.config.fileConfig(ini_file)
log = logging.getLogger(__name__)
app = get_app(ini_file, "myapp")
settings = app.registry.settings
engine = sqlalchemy.engine_from_config(settings, prefix="sqlalchemy.",
pool_recycle=3600, convert_unicode=True)
sqlahelper.add_engine(engine)
Base = sqlahelper.get_base()
Session = sqlahelper.get_session()
# Create the tables if they don't already exist
log.info("Initialize database ...")
Base.metadata.create_all(bind=Session.bind, checkfirst=True)
#create default privileges
log.info("Populate default privileges ...")
log.info("nothing here...")
log.info("Populate default privileges done.")
#create default roles
log.info("Populate default roles ...")
q = Session.query(model.DKRole)
if not q.all():
records = [ model.DKRole(model.ROLE_SYSADMIN),
model.DKRole(model.ROLE_USER),
]
Session.add_all(records)
log.info("Populate default roles done.")
else:
log.info("Roles already exist.")
log.info("Populate default roles done.")
#create default system parameters
log.info("Populate default system parameters ...")
q = Session.query(model.DKSystem)
if not q.all():
records = [ model.DKSystem("master_key_status", model.SS_SERVICE_NO_KEY),
model.DKSystem("service_key_gen_status", model.SS_SERVICE_NOT_AVAIL),
model.DKSystem("service_key_revoke_status", model.SS_SERVICE_NOT_AVAIL),
]
Session.add_all(records)
log.info("Populate default system parameters done.")
else:
log.info("System parameters exists.")
#create default admin account
log.info("Create default admin account ...")
q = Session.query(model.DKUser)
r = q.get("sysadmin")
if not r:
user = model.DKUser()
user.username = "sysadmin"
user.roles = ":".join(["", model.ROLE_SYSADMIN, ""])
user.passwd = hashlib.md5("sysadmin").hexdigest()
user.master_email = "[email protected]"
user.actived = True
Session.add(user)
log.info("Admin account setup complete.")
else:
log.info("Admin account already setup.")
transaction.commit()
开发者ID:dyno,项目名称:drkpr,代码行数:68,代码来源:create_db.py
示例14: create_base
def create_base(basedotted):
"""dotted = foo.bar:Base"""
if basedotted:
return import_symbol(basedotted)
else:
return sqlahelper.get_base()
开发者ID:podhmo,项目名称:spectacles,代码行数:6,代码来源:alchemy.py
示例15: Copyright
# -*- coding: utf-8 -*-
"""
oflogviewer.models.meta
~~~~~~~~~~~~~~~~~~~~~~~
SQLAlchemyの初期化
:copyright: Copyright (c) 2015, National Institute of Information and Communications Technology.All rights reserved.
:license: GPL3, see LICENSE for more details.
"""
from sqlalchemy import create_engine
from sqlahelper import get_base, get_session, add_engine
__all__ = ['Base', 'Session', 'init_engine']
Base = get_base()
Session = get_session()
def init_engine(config):
engine = create_engine(
config.get('SQLALCHEMY_DATABASE_URI'),
echo=config.get('SQLALCHEMY_ECHO'),
pool_recycle=config.get('SQLALCHEMY_POOL_RECYCLE'),
convert_unicode=True
)
add_engine(engine)
开发者ID:nict-isp,项目名称:scn-admin,代码行数:27,代码来源:meta.py
示例16: member
return None
ticket_no = self.ticket_no
return project.get_ticket(ticket_no)
@reify
def member(self):
project = self.project
if project is None:
return None
authenticated_user = self.request.authenticated_user
if authenticated_user is None:
return None
return Member.query.filter(Member.user==authenticated_user).filter(Member.project==project).one()
Base = sqlahelper.get_base()
DBSession = sqlahelper.get_session()
class User(Base):
__tablename__ = 'users'
query = DBSession.query_property()
id = sa.Column(sa.Integer, primary_key=True)
user_name = sa.Column(sa.Unicode(255), unique=True)
_password = sa.Column("password", sa.String(255))
def set_password(self, password):
self._password = hashlib.sha1(password).hexdigest()
password = property(fset=set_password)
def validate_password(self, password):
开发者ID:rebeccaframework,项目名称:shirly,代码行数:31,代码来源:models.py
示例17: CrowdProvider
import ptah
import sqlalchemy as sqla
import sqlahelper as psa
Base = psa.get_base()
Session = psa.get_session()
class CrowdProvider(object):
#ptah.auth_provider('user+crowd')
def authenticate(self, creds):
login, password = creds['login'], creds['password']
user = CrowdUser.get_bylogin(login)
if user is not None:
if ptah.passwordTool.check(user.password, password):
return user
def get_principal_bylogin(self, login):
return CrowdUser.get_bylogin(login)
class CrowdUser(Base):
__tablename__ = 'ptah_crowd'
pid = sqla.Column(sqla.Integer, primary_key=True)
uri = sqla.Column(sqla.Unicode(45), unique=True)
name = sqla.Column(sqla.Unicode(255))
开发者ID:mcdonc,项目名称:ptah,代码行数:31,代码来源:provider.py
示例18: main
def main(global_config, **settings):
""" This is your application startup.
"""
config = Configurator(root_factory=APP_FACTORY, settings=settings,
session_factory = session_factory,
authentication_policy = auth_policy)
config.include('ptah')
config.include('pyramid_tm')
import sqlahelper, sqlalchemy
engine = sqlalchemy.engine_from_config(settings, 'sqlalchemy.')
sqlahelper.add_engine(engine)
# you could use ptah.ptah_init() and be home by now
# --- start ptah.ptah_init() ---
config.ptah_initialize(('nerdfilestest', 'ptah'))
config.commit()
# --- end ptah.ptah_init() ---
# create sql tables
Base = sqlahelper.get_base()
Base.metadata.create_all()
# your application configuration
root = APP_FACTORY()
# admin user
user = Session.query(User).first()
if user is None:
user = User('Admin', 'admin', '[email protected]', '12345')
Session.add(user)
# give manager role to admin
if user.uri not in root.__local_roles__:
root.__local_roles__[user.uri] = [Manager.id]
# set authcontext as admin user
ptah.authService.set_userid(user.uri)
# create default page
if 'front-page' not in root.keys():
page = Page(title=u'Welcome to Ptah')
page.text = open(
abspath_from_asset_spec('nerdfilestest:welcome.pt'), 'rb').read()
root['front-page'] = page
# We are not in a web request; we need to manually commit.
import transaction
transaction.commit()
# enable rest api
ptah.enable_rest_api(config)
# enable ptah-manage, see ptah.managers in .ini for users whom can access
config.add_route(
'ptah-manage','/ptah-manage/*traverse',
factory=ptah.manage.PtahManageRoute, use_global_views=True)
config.begin()
ptah.manage.CONFIG['managers'] = ['admin']
config.end()
config.scan()
return config.make_wsgi_app()
开发者ID:nerdfiles,项目名称:ptah-aha,代码行数:66,代码来源:app.py
注:本文中的sqlahelper.get_base函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论