当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.query方法代码示例

本文整理汇总了Python中por.models.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在por.models.DBSession的用法示例。


在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: password_reset

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
def password_reset(request):
    email = request.params.get('email')
    try:
        session = DBSession()
        user = DBSession.query(User).filter_by(email=email).one()
        ptoken = DBSession.query(PasswordResetToken).get(user.id)
        if not ptoken:
            ptoken = PasswordResetToken(user_id=user.id)
        token = str(uuid4())
        ptoken.token = token 
        session.add(ptoken)
    except NoResultFound:
        token = None

    if token:
#        settings = request.registry.settings
        mailer = get_mailer(request)
        headers = {"header": u'Password reset',
                   "message": u'Please click on the link bellow to reset your penelope account\'s password.',
                   "link": '%s/change_password?token=%s' % (request.application_url, token),
                   "action": 'Reset password'}
        message = Message(subject=u"Password reset request",
                          recipients=[email],
                          body=u'Password reset',
                          extra_headers={'X-MC-Template': 'general',
                                         'X-MC-MergeVars': json.dumps(headers)})
        mailer.send(message)
    return {'request': request, 'token': token}
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:30,代码来源:views.py

示例2: test_password_set

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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 por.dashboard.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)
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:15,代码来源:test_password.py

示例3: render

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
    def render(self):
        result = {}
        result['main_template'] = get_renderer(
                'por.dashboard:skins/main_template.pt').implementation()
        result['main'] = get_renderer(
                'por.dashboard.forms:templates/master.pt').implementation()

        schema = WizardSchema().clone()
        wizard_fanstatic.need()
        form = WizardForm(schema,
                          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=2)

        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'Analisi'})
        appstruct['contracts']['customer_requests'].append({'ticket': True,
                                                            'title': u'Supporto'})
        result['form'] = form.render(appstruct=appstruct)
        return result
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:52,代码来源:wizard.py

示例4: test_token_store_cleanup

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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 por.dashboard.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)
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:16,代码来源:test_password.py

示例5: test_project_modification_date

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
 def test_project_modification_date(self):
     project_name = u'C project'
     session = DBSession()
     project = Project(name=project_name)
     session.add(project)
     transaction.commit()
     project = session.query(Project).filter_by(name=project_name).first()
     old_date = project.modification_date
     project.name = u'A modified project'
     time.sleep(0.1)
     transaction.commit()
     project = session.query(Project).filter_by(name=u'A modified project').first()
     new_date = project.modification_date
     self.assertNotEqual(old_date, new_date)
开发者ID:getpenelope,项目名称:por.models,代码行数:16,代码来源:test_tp.py

示例6: timeentry_crstate_validation_errors

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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, request=request)

    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 []
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:16,代码来源:api.py

示例7: report_index

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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()
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:16,代码来源:__init__.py

示例8: unusedEmail

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:9,代码来源:wizard.py

示例9: search

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:34,代码来源:my_entries.py

示例10: latest_entries

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
def latest_entries(context, request):
    """
    Returns an HTML fragment with tables of the latest time entries
    """

    qry = DBSession.query(TimeEntry)

    current_user = request.environ.get('repoze.who.identity')['user']
    qry = qry.filter(TimeEntry.author_id==current_user.id)

    qry = qry.order_by(sa.desc(TimeEntry.date), sa.desc(TimeEntry.start), sa.desc(TimeEntry.creation_date))
    time_entries_today = qry.filter(TimeEntry.date==datetime.date.today()).all()
    today_total = timedelta_as_human_str(sum([a.hours for a in time_entries_today], datetime.timedelta()))

    latest_limit = 20
    time_entries_latest = qry.limit(latest_limit)

    return {
            'context': context,
            'request': request,
            'time_entries_today': time_entries_today,
            'today_total': today_total,
            'time_entries_latest': time_entries_latest,
            'time_entries_latest_limit': latest_limit,
            'report_my_from_date': datetime.date.today() - datetime.timedelta(days=6),
            'today': datetime.date.today(),
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:29,代码来源:tp.py

示例11: get_user_by_openid

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
def get_user_by_openid(request, openid):
    """
    This method search for user using one of the possible user openids
    """
    session = DBSession()

    if not isinstance(openid, basestring):
        return {
                'status:': False,
                'message': u'Openid parameter must be a string!',
                }

    try:
        user = session.query(User).join('openids').filter_by(openid=openid).one()
    except orm_exc.NoResultFound:

        return {
                'status': False,
                'message': u'No user found in db for %s openid' % openid,
                }

    return {
            'status': True,
            'message': u'User found.',
            'email': user.email,
            'login': user.login,
            'openids': [x.openid for x in user.openids],
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:30,代码来源:api.py

示例12: get_user_by_email

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
def get_user_by_email(request, email):
    """
    This method search for user using his email address
    """
    session = DBSession()
    if not isinstance(email, basestring):
        return {
                'status:': False,
                'message': u'Email parameter must be a string!',
                }
    try:
        user = session.query(User).filter_by(email=email).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No user found in db for %s mail address' % email,
                }

    return {
            'status': True,
            'message': u'User found.',
            'email': user.email,
            'login': user.login,
            'openids': [x.openid for x in user.openids]
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:27,代码来源:api.py

示例13: get_project_by_name

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
def get_project_by_name(request, project_name):
    """
    This method search for project by name
    """
    session = DBSession()

    if not isinstance(project_name, basestring):
        return {
                'status:': False,
                'message': u'Project name parameter must be a string!',
                }

    try:
        project = session.query(Project).filter_by(name=project_name).one()
    except orm_exc.NoResultFound:
        return {
                'status': False,
                'message': u'No project found in db for %s name' % project_name,
                }

    return {
            'status': True,
            'message': u'Project found.',
            'name': project.name,
            'id': project.id,
            'customer': project.customer.name,
            'applications': [x.name for x in project.applications],
            'customer_requests': [(x.id, x.name,) for x in project.customer_requests],
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:31,代码来源:api.py

示例14: get_customer_by_name

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.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],
            }
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:28,代码来源:api.py

示例15: state_contract_change

# 需要导入模块: from por.models import DBSession [as 别名]
# 或者: from por.models.DBSession import query [as 别名]
    def state_contract_change(self):
        new_state = self.request.POST['new_state']
        new_contract = self.request.POST['new_contract']
        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_contract = 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_contract:
                done_contract.add(te.id)
                te.contract_id = new_contract

        return done_state, done_contract, errors
开发者ID:getpenelope,项目名称:por.dashboard,代码行数:32,代码来源:state_change.py


注:本文中的por.models.DBSession.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。