本文整理汇总了Python中models.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: entity_type_delete
def entity_type_delete(request):
dbsession = DBSession()
name = clean_matchdict_value(request, 'entity_type')
entity_type = dbsession.query(EntityType).filter(EntityType.name == name).one()
dbsession.delete(entity_type)
transaction.commit()
return {'status': 'success'}
示例2: event_delete
def event_delete(request):
dbsession = DBSession()
id = clean_matchdict_value(request, 'event')
event = dbsession.query(Event).filter(Event.id == id).one()
dbsession.delete(event)
transaction.commit()
return {'status': 'success'}
示例3: user_get
def user_get(request):
dbsession = DBSession()
name = clean_matchdict_value(request, 'user')
user = dbsession.query(User).filter(User.name == name).one()
user_data = dbsession.query(UserData).filter(UserData.user_id == user.id).one()
user_json = convert.decodeUser(request, dbsession, user, user_data)
return {'status': 'success', 'user': user_json}
示例4: action_delete
def action_delete(request):
dbsession = DBSession()
name = clean_matchdict_value(request, 'action')
action = dbsession.query(Action).filter(Action.name == name).one()
dbsession.delete(action)
transaction.commit()
return {'status': 'success'}
示例5: filemonitoring
def filemonitoring(self):
log = logging.getLogger(__name__)
if self._request.params:
# TODO: add this information to the file
md5_enabled = True if 'withmd5' in self._request.params and self._request.params['withmd5'] == '0' else False
all_files = self._request.params.getall('file')
complete_file, filenames, folders = self._get_monitored_files(self._request.params['folder'] + '/')
with transaction.manager:
for f in all_files:
if f in complete_file:
log.debug('Skipping file {0}, because it is already monitored'.format(f))
continue
(path, filename) = os.path.split(f)
dbobj = MonitoredFile(path, filename, f)
DBSession.add(dbobj)
DBSession.commit()
files_not_mentioned = [c for c in complete_file if c not in all_files]
# TODO: decide on this
log.info('TODO: Still have to decide whether files which are not selected should be deleted or not.'
'Affected files would be: {0}'.format(files_not_mentioned))
else:
log.info('Got an empty request, going to redirect to start page')
subreq = Request.blank('/')
return self._request.invoke_subrequest(subreq)
subreq = Request.blank(self._request.route_path('filebrowser'),
POST=dict(folder=self._request.params['folder'],
currentfolder=self._request.params['currentfolder'],
pathdescription='abs'))
return self._request.invoke_subrequest(subreq)
示例6: user_delete
def user_delete(request):
dbsession = DBSession()
name = clean_matchdict_value(request, 'user')
user = dbsession.query(User).filter(User.name == name).one()
dbsession.delete(user)
transaction.commit()
return {'status': 'success'}
示例7: group_delete
def group_delete(request):
dbsession = DBSession()
name = clean_matchdict_value(request, 'group')
group = dbsession.query(Group).filter(Group.name == name).one()
dbsession.delete(group)
transaction.commit()
return {'status': 'success'}
示例8: job_output
def job_output(self):
log = logging.getLogger(__name__)
jobid = self._request.matchdict['jobid']
log.info('Request job output for id:{0}'.format(jobid))
ssh_holder = self._request.registry.settings['ssh_holder']
ssh_jobmanager = SSHBasedJobManager(ssh_holder)
jobs = self._get_current_jobs(ssh_jobmanager, self._coltitles)
joboutput = ssh_jobmanager.get_job_output(jobid)
if 'error' in joboutput and joboutput['error'] is None:
db_joboutput = JobOutput(id=jobid, output=jsonpickle.encode(joboutput))
DBSession.add(db_joboutput)
DBSession.commit()
if 'error' in joboutput and joboutput['error'] is not None:
jobresult = joboutput['error']
else:
jobresult = joboutput['content']
jobresult = ''.join(jobresult)
if 'type' not in joboutput:
joboutput['type'] = 'type field missing'
return {'project': self._projectname,
'jobs': jobs,
'output': dict(jobid=jobid, output=jobresult, type=joboutput['type'])}
示例9: is_allowed
def is_allowed(request, routename, method='ALL', check_route=True):
"""
Given a request_object, routename and method; returns True if current user has access to that route,
otherwise returns False.
If check_route if False, does not check the DB to see if the route is in the list of protected routes
"""
if check_route:
route = DBSession.query(RoutePermission).filter_by(route_name=routename).first()
if not route:
return True
if not isinstance(method, list):
method = [method, ]
user_permissions = request.session.get('auth_user_permissions', [])
if request.session.get('auth_static_permission', None):
user_permissions.append(request.session.get('auth_static_permission', None))
has_permission = DBSession.query(func.count(RoutePermission.permission)).filter(
RoutePermission.route_name == routename).filter(
RoutePermission.method.in_(method)).filter(
RoutePermission.permission.in_(user_permissions)).scalar()
if has_permission > 0:
return True
else:
return False
示例10: main
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
LOG.debug("settings:{}".format(settings))
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.bind = engine
config = Configurator(settings=settings)
config.include('pyramid_chameleon')
config.add_static_view('static', 'static', cache_max_age=3600)
config.add_static_view('jasny-css', 'static/jasny-bootstrap/css', cache_max_age=3600)
config.add_static_view('jasny-js', 'static/jasny-bootstrap/js', cache_max_age=3600)
config.add_route('login', '/')
config.add_route('logout', '/logout')
config.add_route('show_empl', '/employee/{emp_no}',
factory=EmployeeRootFactory)
config.add_route('show_dept', '/department/{dept_no}',
factory=DeptRootFactory)
auth_engine = AuthEngine()
config.add_settings(auth_engine=auth_engine)
authn_policy = AuthTktAuthenticationPolicy(settings['secret_key'],
callback=auth_engine.get_groups,
hashalg='sha512')
config.set_authentication_policy(authn_policy)
config.set_authorization_policy(ACLAuthorizationPolicy())
query_parser = FormQueryParser()
config.add_settings(query_parser=query_parser)
config.scan()
return config.make_wsgi_app()
示例11: post_entry
def post_entry(request):
entry = m.Entry()
entry.start_datetime = datetime.datetime.now()
entry.updated_datetime = datetime.datetime.now()
DBSession.add(entry)
DBSession.flush()
return entry.entry_id
示例12: login
def login(request):
"""Returns a tuple of (authenticated) uid, and a message string.
If the user could not be authenticated (or they didn't try), the uid
will be None. If the user successfully logged in, sets a session
cookie for this session."""
session = DBSession()
uid = authenticated_userid(request)
if uid:
return session.query(User).get(uid), None
if 'user' in request.params and 'passwd' in request.params:
uid = request.params['user']
passwd = request.params['passwd']
user = session.query(User).get(uid)
if not user:
return None, "Invalid user or password."
if user.check_pw(passwd):
headers = remember(request, uid)
request.response.headerlist.extend(headers)
return user, "Logged in Successfully"
else:
return None, "Invalid user or password."
else:
return None, None
示例13: make_admin
def make_admin(config_path):
from intranet3.models import User
user_login = sys.argv[-1]
if len(sys.argv) < 4:
print u"Provide user login"
return
session = DBSession()
user = session.query(User).filter(User.email==user_login).first()
if not user:
print u"No such user: %s" % user_login
return
if 'admin' in user.groups:
print u'Removing %s from group admin' % user.name
groups = list(user.groups)
groups.remove('admin')
user.groups = groups
else:
print u'Adding %s to group admin' % user.name
groups = list(user.groups)
groups.append('admin')
user.groups = groups
session.add(user)
transaction.commit()
示例14: init_db
def init_db(config_path):
setup_logging(config_path)
settings = get_appsettings(config_path)
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
print 'Done'
示例15: order_delete
def order_delete(request):
dbsession = DBSession()
name = clean_matchdict_value(request, 'order')
order = dbsession.query(Order).filter(Order.id == id).one()
dbsession.delete(order)
transaction.commit()
return {'status': 'success'}