本文整理汇总了Python中dmirr.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
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'))
示例2: post
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))
示例3: post
def post(self, *a, **kw):
errors = _h.get_validation_errors()
project = _h.get_project_by_name(kw.get('project_label', None))
if not project:
errors['project'] = "Project does not exist"
_h.protect_obj_modify(project)
_existing_p = _h.get_product_by_name(kw.get('label', None))
if _existing_p:
errors['label'] = "%s already exists!" % kw.get('label', None)
p = Product()
p.label = unicode(re.sub(' ', '_', kw['label']).lower())
p.display_name = unicode(kw.get('display_name', None))
p.desc = kw.get('desc', None)
if len(errors) > 0:
return dict(errors=errors, project=project, product=p)
p.project = project
DBSession.add(p)
transaction.commit()
flash(_("%s created successfully!" % kw['display_name']), 'info')
redirect(url('/product/new?project=%s' % kw['project_label']))
示例4: put
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']))
示例5: assign_project
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
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: edit
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)
示例8: get_all
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)
示例9: edit
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)
示例10: put
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))
示例11: get_one
def get_one(self, label, *a, **kw):
p = DBSession.query(Project).filter_by(label=label).first()
site_hosts = []
for s in p.sites:
for h in s.hosts:
h.sync_base_path = s.sync_base_path
site_hosts.append(h)
return dict(errors={}, project=p, site_hosts=site_hosts)
示例12: _add_site_sync_path
def _add_site_sync_path(self, site_id, project_id, sync_path):
s = DBSession.query(Site).filter_by(id=site_id).first()
p = DBSession.query(Project).filter_by(id=project_id).first()
alt = DBSession.query(SiteSyncPath).filter_by(site_id=s.id)\
.filter_by(project_id=p.id).first()
if alt:
alt.sync_path = sync_path
transaction.commit()
return alt
alt = SiteSyncPath()
alt.site = s
alt.project = p
alt.sync_path = sync_path
DBSession.add(alt)
transaction.commit()
return alt
示例13: new
def new(self, *a, **kw):
product = _h.get_product_by_name(kw.get('product', None))
all_archs = DBSession.query(Arch).all()
if not product:
raise HTTPNotFound
_h.protect_obj_modify(product.project)
r = ProductRelease()
r.label = kw.get('label', '')
r.display_name = kw.get('display_name', '')
r.desc = kw.get('desc', '')
arch = DBSession.query(Arch)\
.filter_by(label=kw.get('arch_label', 'noarch'))\
.first()
r.path = kw.get('path', '')
return dict(page='product_release', errors={}, project=product.project, product=product, all_archs=all_archs, arch=arch, release=r)
示例14: delete
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'))
示例15: change_email
def change_email(self, **kw):
u = db.query(model.User).filter_by(user_name=kw['u'])\
.filter_by(verify_code=kw['vc']).first()
if not u:
flash(_('Email verification failed. %s was not found or invalid code!' % kw['u']), 'warning')
redirect(url('/dashboard'))
u.email_address = kw['e']
db.flush()
flash(_('%s successfully changed email address to %s!' % (u.display_name, u.email_address)),
'info')
transaction.commit()
redirect(url('/dashboard'))