本文整理汇总了Python中penelope.core.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类penelope.core.models.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Environment_get_known_users
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def Environment_get_known_users(self, cnx=None):
project_id = self.config.get('por-dashboard', 'project-id')
project = None
if project_id:
db = DBSession()
project = db.query(Project).get(project_id)
for user in db.query(User).all():
if user.roles_in_context(project):
yield user.login, user.fullname, user.email
示例2: render
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def render(self):
result = {}
result['main_template'] = get_renderer(
'penelope.core:skins/main_template.pt').implementation()
result['main'] = get_renderer(
'penelope.core.forms:templates/master.pt').implementation()
schema = WizardSchema().clone()
wizard_fanstatic.need()
form = WizardForm(schema,
action=self.request.current_route_url(),
formid='wizard',
method='POST',
buttons=[
SubmitButton(title=u'Submit'),
ResetButton(title=u'Reset'),
])
form['new_users'].widget = SequenceWidget()
form['users'].widget = SequenceWidget(min_len=1)
users = DBSession.query(User).order_by(User.fullname)
form['users']['user']['usernames'].widget.values = [('', '')] + \
[(str(u.id), u.fullname) for u in users]
roles = DBSession.query(Role).order_by(Role.name)
form['users']['user']['role'].widget.values = [('', '')] + \
[(str(role.id), role.name) for role in roles]
form['new_users']['new_user']['role'].widget.values = [('', '')] + \
[(str(role.id), role.name) for role in roles]
form['milestones'].widget = SequenceWidget(min_len=1)
form['contracts'].title = ''
form['contracts']['customer_requests'].widget = SequenceWidget(min_len=3)
controls = self.request.POST.items()
if controls != []:
try:
appstruct = form.validate(controls)
self.handle_save(form, appstruct)
except ValidationFailure as e:
result['form'] = e.render()
return result
appstruct = {}
appstruct['contracts'] ={'customer_requests': []}
appstruct['contracts']['customer_requests'].append({'ticket': True,
'title': u'Project management'})
appstruct['contracts']['customer_requests'].append({'ticket': True,
'title': u'Analisi'})
appstruct['contracts']['customer_requests'].append({'ticket': True,
'title': u'Supporto'})
result['form'] = form.render(appstruct=appstruct)
return result
示例3: test_password_set
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def test_password_set(self):
email = u'[email protected]'
self.add_user(email)
session = DBSession()
self.assertEqual(session.query(User).filter_by(email=email).one().password, None)
token = self.generate_token(email)['token']
from penelope.core.security.views import change_password
request = Request(method='POST', params={'token': token,
'password': 'topsecret',
'password_repeat': 'topsecret'})
response = change_password(request)
self.assertEqual(response.headers.get('Location'),'/login_form')
self.assertNotEqual(session.query(User).filter_by(email=email).one().password, None)
示例4: test_token_store_cleanup
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def test_token_store_cleanup(self):
email = u'[email protected]'
self.add_user(email)
self.generate_token(email)['token']
token2 = self.generate_token(email)['token']
session = DBSession()
self.assertEqual(len(session.query(PasswordResetToken).join(User).filter(User.email == email).all()),1)
from penelope.core.security.views import change_password
request = Request(method='POST', params={'token': token2,
'password': 'topsecret',
'password_repeat': 'topsecret'})
response = change_password(request)
self.assertEqual(response.headers.get('Location'),'/login_form')
self.assertEqual(len(session.query(PasswordResetToken).join(User).filter(User.email == email).all()),0)
示例5: report_index
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def report_index(context, request):
users = DBSession.query(User).order_by(User.fullname)
users = filter_users_with_timeentries(users)
projects = sorted(request.filter_viewables(qry_active_projects()), key=unicodelower)
customers = sorted(set(p.customer for p in projects), key=unicodelower)
current_uid = request.authenticated_user.id
saved_queries = DBSession.query(SavedQuery).filter(SavedQuery.author_id==current_uid)
return {
'users': users,
'customers': customers,
'projects': projects,
'saved_queries': saved_queries.all()
}
示例6: timeentry_crstate_validation_errors
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def timeentry_crstate_validation_errors(project_id, tickets, request):
# XXX this check is deactivated for now (see #312)
return []
project = DBSession.query(Project).get(project_id)
customer_requests = ticket_store.get_requests_from_tickets(project, tickets)
for ticket_id, cr_id in customer_requests:
cr = DBSession.query(CustomerRequest).get(cr_id)
if cr.workflow_state != 'estimated':
return ['Customer Request is not estimated']
return []
示例7: __call__
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def __call__(self):
te_ids = set(int(s[3:])
for s, checkbox_state in self.request.POST.iteritems()
if s.startswith('te_') and checkbox_state=='on')
tes = DBSession.query(TimeEntry).filter(TimeEntry.id.in_(te_ids))
new_state = self.request.POST.get('new_state', None)
new_cr = self.request.POST.get('new_cr', None)
if new_cr:
new_cr = DBSession.query(CustomerRequest).get(new_cr)
return {'back_url': '%s/reports/report_state_change?%s' % (self.request.application_url, self.request.query_string),
'post': self.request.POST.items(),
'tes': tes,
'new_state': new_state,
'new_cr': new_cr}
示例8: state_cr_change
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def state_cr_change(self):
new_state = self.request.POST['new_state']
new_cr = self.request.POST['new_cr']
invoice_number = self.request.POST['invoice_number']
te_ids = set(int(s[3:])
for s, checkbox_state in self.request.POST.iteritems()
if s.startswith('te_') and checkbox_state=='on')
qry = DBSession.query(TimeEntry).filter(TimeEntry.id.in_(te_ids))
done_state = set()
done_cr = set()
errors = {}
for te in qry:
if new_state:
try:
workflow = get_workflow(te, te.__class__.__name__)
workflow.transition_to_state(te, self.request, new_state, skip_same=True)
done_state.add(te.id)
if new_state == 'invoiced' and invoice_number:
te.invoice_number = invoice_number
except WorkflowError as msg:
errors[te.id] = msg
if new_cr:
done_cr.add(te.id)
te.customer_request_id = new_cr
return done_state, done_cr, errors
示例9: search
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def search(self, limit, author_id, project_id, date_from, date_to, searchtext):
qry = DBSession.query(TimeEntry)
qry = qry.filter(TimeEntry.author_id==author_id)
if project_id is not colander.null:
qry = qry.filter(TimeEntry.project_id==project_id)
if date_from is not colander.null:
qry = qry.filter(TimeEntry.date>=date_from)
if date_to is not colander.null:
qry = qry.filter(TimeEntry.date<=date_to)
if searchtext is not colander.null:
qry = qry.filter(TimeEntry.description.ilike(u'%{0}%'.format(searchtext)))
qry = qry.order_by(sa.desc(TimeEntry.date), sa.desc(TimeEntry.start), sa.desc(TimeEntry.creation_date))
if limit:
qry = qry.limit(limit)
qry = self.request.filter_viewables(qry)
entries_by_date = []
entries_count = 0
for k, g in itertools.groupby(qry, operator.attrgetter('date')):
g = list(g)
entries_by_date.append((k, g))
entries_count += len(g)
return entries_by_date, entries_count
示例10: activate_iteration
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def activate_iteration(context, request):
docid = request.params.get('docid')
if not docid:
return view_iterations(context, request, validation_error=u'Missing document_id')
#query = gdata.spreadsheet.service.CellQuery()
#first take project names
#query['min-col'] = '3'
#query['max-col'] = '3'
#query['min-row'] = '5'
#cr_raw = get_cell_values(request, query)
session = DBSession()
#deactivate all CR
#for cr in session.query(CustomerRequest):
# cr.active = False
#activate selected CR
#cr_ids = set([item for sublist in [a.split(',') for a in cr_raw] for item in sublist])
#crs = session.query(CustomerRequest).filter(CustomerRequest.id.in_(cr_ids))
#for cr in crs:
# cr.active = True
gc = session.query(GlobalConfig).get(1)
gc.active_iteration_url = docid
return manage_iterations(context,request)
示例11: get_customer_by_name
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def get_customer_by_name(request, customer_name):
"""
This method search for customer by name
"""
session = DBSession()
if not isinstance(customer_name, basestring):
return {
'status:': False,
'message': u'Customer name parameter must be a string!',
}
try:
customer = session.query(Customer).filter_by(name=customer_name).one()
except orm_exc.NoResultFound:
return {
'status': False,
'message': u'No customer found in db for %s name' % customer_name,
}
return {
'status': True,
'message': u'Customer found.',
'name': customer.name,
'projects': [x.name for x in customer.projects],
}
示例12: view_home
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def view_home(request):
"""
Default home view
"""
fanstatic_resources.dashboard_home.need()
session = DBSession()
user = request.authenticated_user
projects = session.query(Project)
my_projects = projects\
.filter(Project.users_favorite(user))\
.order_by(Project.customer_id).all()
my_projects = request.filter_viewables(my_projects)
active_projects = set(projects.filter(Project.active))
active_projects = sorted(request.filter_viewables(active_projects.difference(my_projects)), key=unicodelower)
listings = []
listing_columns = 4
listings.append({'title': 'Active projects',
'projgroups': tuple(chunks(tuple(active_projects), listing_columns)),})
kanbanboards = user.kanban_boards
return {
'my_projects': my_projects,
'kanbanboards': kanbanboards,
'listings': listings,
'can_see_kanbanboards': request.has_permission('listing', KanbanBoard),
'get_application_link': get_application_link,
}
示例13: notify_feedly
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def notify_feedly(self, ticket, comment, author):
from penelope.core.activity_stream import add_activity
users_to_notify = set()
users_to_notify.add(ticket.values.get('reporter'))
users_to_notify.add(ticket.values.get('owner'))
try:
users_to_notify.remove(author)
except KeyError:
pass
absolute_path = '/trac/{trac_id}/ticket/{ticket_id}'.format(ticket_id=ticket.id, trac_id=self.env.config['por-dashboard'].get('project-id'))
message = "Ticket #{ticket} has been {comment} in {trac_name}.".format(ticket=ticket.id, comment=comment, trac_name=self.config['project'].get('name'))
created_by = author
user_ids = []
for email in users_to_notify:
try:
user_ids.append(DBSession.query(User.id).filter(User.email==email).one().id)
except sqlalchemy.orm.exc.NoResultFound:
pass
try:
add_activity(user_ids, message, absolute_path, created_by)
except ConnectionError:
pass
示例14: create_initial_application_acl
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def create_initial_application_acl(mapper, connection, target):
if target.application_type == SVN:
acl_rules = [
('internal_developer', 'edit'),
('internal_developer', 'view'),
('external_developer', 'edit'),
('external_developer', 'view'),
]
else:
acl_rules = [
('internal_developer', 'view'),
('external_developer', 'view'),
('secretary', 'view'),
('secretary', 'edit'),
]
if target.application_type == 'trac':
acl_rules.append(('customer', 'view'))
for role_id, permission_name in acl_rules:
acl = DBSession.query(ApplicationACL).get((target.id, role_id, permission_name))
if not acl:
acl = ApplicationACL(application_id=target.id,
role_id=role_id,
permission_name=permission_name)
DBSession.add(acl)
else:
# XXX this should not happen.
pass
示例15: unusedEmail
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import query [as 别名]
def unusedEmail(value):
user = DBSession.query(User.id).filter(User.email == value).first()
if user:
return "email '%s' is already associated to another user" % \
value
else:
return True