本文整理汇总了Python中dmirr.model.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dmirr.model.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def delete(self, user_name=None, *a, **kw):
u = db.query(model.User).filter_by(user_name=user_name).first()
admins = db.query(model.Group).filter_by(group_name='dmirr_admin')\
.all()
_display_name = u.display_name
if not u:
raise HTTPNotFound
_h.protect_user_obj(u)
came_from = url('/user/%s/edit' % u.user_name)
if u.user_name in admins and len(admins) == 1:
flash(_("Can not delete the only site administrator."), 'warning')
redirect(came_from)
confirmed = kw.get('confirmed', None)
if not confirmed:
display_name = u.display_name
action = url('/user/%s/delete' % u.user_name)
return dict(errors={}, display_name=display_name, action=action,
came_from=came_from)
else:
db.delete(u)
transaction.commit()
flash(_("%s and all associated data have been deleted." % \
_display_name), 'info')
redirect(url('/logout_handler'))
示例2: put
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def put(self, site_label=None, *a, **kw):
errors = _h.get_validation_errors()
s = DBSession.query(Site).filter_by(label=site_label).first()
group = _h.get_group_by_name(kw.get('group_name', None))
all_p = DBSession.query(Project).all()
_h.protect_obj(s)
if not s:
raise HTTPNotFound
if not group:
errors['group'] = 'Group does not exist!'
s.label = unicode(re.sub(' ', '_', kw['label']).lower())
s.display_name = unicode(kw.get('display_name', None))
s.desc = kw.get('desc', None)
s.url = unicode(kw.get('url', None))
s.contact_name = unicode(kw.get('contact_name', None))
s.contact_email = unicode(kw.get('contact_email', None))
s.sync_base_path = unicode(kw.get('sync_base_path', None))
s.user = request.identity['user']
s.group = group
if len(errors) > 0:
all_projects = [x for x in all_p if x not in s.projects]
all_hosts = [x for x in request.identity['user'].hosts \
if x not in s.hosts]
transaction.doom()
return dict(page='site', errors=errors, site=s,
all_projects=all_projects, all_hosts=all_hosts)
transaction.commit()
flash(_("%s updated successfully!" % kw['display_name']), 'info')
redirect(url('/site/%s/edit' % kw['label']))
示例3: put
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def put(self, host_id=None, *a, **kw):
h = DBSession.query(Host).filter_by(id=host_id).first()
if not h:
raise HTTPNotFound
errors = _h.get_validation_errors()
h.user = request.identity['user']
h.group = _h.get_group_by_name(kw.get('group_name', None))
h.address = unicode(kw['address'].strip())
h.online_status = DBSession.query(Status)\
.filter_by(label='Offline').first()
res = self._get_geoip_data(h.address)
if not res:
errors['host_address'] = "The host '%s' could not be " + \
"identified via GeoIP. Please " + \
"ensure the hostname resolves" % h.address
if errors:
transaction.doom()
return dict(errors=errors, host=h)
h.city = unicode(res.get('city', None))
h.region_name = unicode(res.get('region_name', None))
h.longitude = res.get('longitude', None)
h.latitude = res.get('latitude', None)
h.country_name = unicode(res.get('country_name', None))
h.country_code = unicode(res.get('country_code', None))
h.country_code3 = unicode(res.get('country_code3', None))
h.postal_code = res.get('postal_code', None)
flash(_("%s updated successfully!" % kw['address']), 'info')
redirect(url('/dashboard'))
示例4: edit
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def edit(self, project_label=None, *a, **kw):
p = DBSession.query(Project).filter_by(label=project_label).first()
all_protocols = DBSession.query(SyncProtocol).all()
_h.protect_obj_modify(p)
# only groups that both the logged in user, and the owner of the
# project share.
all_groups = []
for group in request.identity['user'].groups:
if p.user in group.users:
all_groups.append(group)
for group in p.user.groups:
if request.identity['user'] in group.users:
all_groups.append(group)
all_hosts = []
for host in request.identity['user'].hosts:
if host.group in all_groups and not host in all_hosts:
all_hosts.append(host)
elif host.user == p.user:
all_hosts.append(host)
for group in all_groups:
for host in group.hosts:
if not host in all_hosts:
all_hosts.append(host)
all_h = [x for x in all_hosts if x not in p.hosts]
return dict(page='project', errors={}, project=p,
all_protocols=all_protocols, all_hosts=all_h)
示例5: assign_project
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def assign_project(self, site_id, *a, **kw):
errors = _h.get_validation_errors()
s = DBSession.query(Site).filter_by(id=site_id).first()
p = DBSession.query(Project).filter_by(id=kw.get('project_id', None))\
.first()
all_p = DBSession.query(Project).all()
_h.protect_obj(s)
_h.protect_obj(p)
if not s:
raise HTTPNotFound
if not p:
raise HTTPNotFound
all_projects = [x for x in all_p if x not in s.projects]
if errors:
transaction.doom()
return dict(errors=errors, site=s, all_projects=all_projects)
_s_label = s.label
s.projects.append(p)
if kw.get('sync_path', None):
self._add_site_sync_path(s.id, p.id, kw['sync_path'])
else:
transaction.doom()
flash(_('Site sync path required for each project.'), 'warning')
redirect(url("/site/%s/edit#mirrored_projects" % _s_label))
transaction.commit()
redirect(url("/site/%s/edit#projects" % _s_label))
示例6: put
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def put(self, project_id=None, *a, **kw):
errors = _h.get_validation_errors()
p = DBSession.query(Project).filter_by(id=project_id).first()
if not p:
raise HTTPNotFound
if kw['label'] != p.label:
other_p = DBSession.query(Project).filter_by(label=kw['label'])\
.first()
if other_p:
errors['label'] = "%s already exists, use another label." % \
other_p.label
group = _h.get_group_by_name(kw.get('group_name', None))
protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
all_protocols = DBSession.query(SyncProtocol).all()
_h.protect_obj_modify(p)
p.display_name = unicode(kw['display_name'])
p.desc = kw['desc']
p.url = unicode(kw['url'])
p.sync_base_path = unicode(kw.get('sync_base_path', None))
p.sync_flags = unicode(kw.get('sync_flags', None))
p.sync_protocol = protocol
p.group = group
if len(errors) > 0:
transaction.doom()
return dict(errors=errors, project=p, all_protocols=all_protocols)
p.label = unicode(re.sub(' ', '_', kw['label']).lower())
_label = p.label
transaction.commit()
flash(_("%s updated successfully!" % kw['display_name']), 'info')
redirect(url('/project/%s/edit' % _label))
示例7: get_all
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def get_all(self, *a, **kw):
view = kw.get('view', None)
if view and view == 'user':
ps = DBSession.query(Project)\
.filter_by(user_id=request.identity['user'].user_id).all()
else:
ps = DBSession.query(Project).all()
return dict(page="project", errors={}, page_title="dMirr Projects",
projects=ps)
示例8: get_group_by_name
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def get_group_by_name(group_name=None):
if not group_name:
group_name = 'dmirr_no_group'
group = db.query(model.Group)\
.filter_by(group_name=group_name)\
.first()
return group
示例9: post
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def post(self, *a, **kw):
errors = _h.get_validation_errors()
group = _h.get_group_by_name(kw.get('group_name', None))
protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
all_protocols = DBSession.query(SyncProtocol).all()
if not group:
errors['group'] = 'Group does not exist!'
if not protocol:
errors['sync_protocol'] = 'Sync Protocol does not exist!'
p = Project()
p.label = unicode(re.sub(' ', '_', kw['label']).lower())
_label = p.label
p.display_name = unicode(kw.get('display_name', None))
p.desc = kw.get('desc', None)
p.url = unicode(kw.get('url', None))
p.user = request.identity['user']
p.sync_base_path = unicode(kw.get('sync_base_path', None))
p.sync_flags = unicode(kw.get('sync_flags', None))
p.group = group
p.sync_protocol = protocol
if len(errors) > 0:
transaction.doom()
return dict(page="project", errors=errors, project=p,
all_protocols=all_protocols)
DBSession.add(p)
transaction.commit()
flash(_("%s created successfully!" % kw['display_name']), 'info')
redirect(url('/project/%s/edit' % _label))
示例10: get_all
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def get_all(self, *a, **kw):
protected_users = []
users = db.query(model.User).all()
for u in users:
protected_users.append(self._strip_private(u))
return dict(errors={}, page='user', page_title="dMirr Users",
users=protected_users)
示例11: put
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def put(self, product_label=None, *a, **kw):
p = DBSession.query(Product).filter_by(label=product_label).first()
project = p.project
_project_label = project.label
if not p:
raise HTTPNotFound
if not project:
raise HTTPNotFound
_h.protect_obj_modify(project)
_h.protect_obj_modify(p.project)
errors = _h.get_validation_errors()
if kw.get('label', None) != p.label:
_existing_p = _h.get_product_by_name(kw.get('label', None))
if _existing_p:
errors['label'] = "%s already exists!" % kw.get('label', None)
p.label = unicode(re.sub(' ', '_', kw['label']).lower())
p.display_name = unicode(kw['display_name'])
p.desc = kw['desc']
p.project = project
if errors:
transaction.doom()
return dict(project=p.project, errors=errors, product=p)
transaction.commit()
flash(_("%s updated successfully!" % kw['display_name']), 'info')
redirect(url("/project/%s/edit#products" % _project_label))
示例12: validate_unique_group_name
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def validate_unique_group_name(value_dict, state, validator):
# first for edit forms
if value_dict.has_key('group_id'):
g1 = db.query(model.Group).filter_by(group_id=value_dict['group_id'])\
.first()
if g1 and g1.group_name != value_dict['group_name']:
g2 = db.query(model.Group)\
.filter_by(group_name=value_dict['gropu_name']).first()
if g2:
return {'group_name':'The group name already exists.'}
# or new form
else:
g1 = db.query(model.Group)\
.filter_by(group_name=value_dict['group_name']).first()
if g1:
return {'group_name':'The group name already exists.'}
示例13: validate_unique_email
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def validate_unique_email(value_dict, state, validator):
# first for edit forms
if value_dict.has_key('user_id'):
u1 = db.query(model.User).filter_by(user_id=value_dict['user_id'])\
.first()
if u1.email_address != value_dict['email_address']:
u2 = db.query(model.User)\
.filter_by(email_address=value_dict['email_address']).first()
if u2:
return {'email_address':'The address already exists.'}
# or new form
else:
u1 = db.query(model.User)\
.filter_by(email_address=value_dict['email_address']).first()
if u1:
return {'email_address':'The address already exists.'}
示例14: validate_unique_user_name
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def validate_unique_user_name(value_dict, state, validator):
# first for edit forms
if value_dict.has_key('user_id'):
u1 = db.query(model.User).filter_by(user_id=value_dict['user_id'])\
.first()
if u1 and u1.user_name != value_dict['user_name']:
u2 = db.query(model.User)\
.filter_by(user_name=value_dict['user_name']).first()
if u2:
return {'user_name':'The user name already exists.'}
# or new form
else:
u1 = db.query(model.User)\
.filter_by(user_name=value_dict['user_name']).first()
if u1:
return {'user_name':'The user name already exists.'}
示例15: edit
# 需要导入模块: from dmirr.model import DBSession [as 别名]
# 或者: from dmirr.model.DBSession import query [as 别名]
def edit(self, site_label=None, *a, **kw):
s = _h.get_site_by_name(site_label)
all_projects = DBSession.query(Project).all()
# only groups that both the logged in user, and the owner of the
# site share.
all_groups = []
for group in request.identity['user'].groups:
if s.user in group.users:
all_groups.append(group)
for group in s.user.groups:
if request.identity['user'] in group.users:
all_groups.append(group)
all_hosts = []
for host in request.identity['user'].hosts:
if host.group in all_groups and not host in all_hosts:
all_hosts.append(host)
elif host.user == s.user:
all_hosts.append(host)
for group in all_groups:
for host in group.hosts:
if not host in all_hosts:
all_hosts.append(host)
if not s:
raise HTTPNotFound
_h.protect_obj_modify(s)
# I love python...
all_p = [x for x in all_projects if x not in s.projects]
all_h = [x for x in all_hosts if x not in s.hosts]
return dict(errors={}, site=s, all_projects=all_p, all_hosts=all_h)