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


Python DBSession.query方法代码示例

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


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

示例1: handle_if_company_tags

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def handle_if_company_tags(i, v, splits=False):
    from alchemist.models.user_company import BaseCompany
    from alchemist.models.base import DBSession

    obj = BaseCompany
    tags = []
    if splits == False:
        splits = [',']
    split = splits.pop()
    for tag in v.split(split):
        if not tag.strip():
            continue
        if splits:
            tags.extend(handle_if_company_tags(i, tag, splits))
            continue
        try:
            ftag = DBSession.query(obj).get(int(tag))
        except:
            ftag = DBSession.query(obj).filter(obj.name == tag.strip()).first()
            if not ftag:
                ftag = obj(name=tag.strip())
        if ftag:
            tags.append(ftag)
    v = tags
    return v
开发者ID:umar93132,项目名称:portal,代码行数:27,代码来源:misc.py

示例2: __setattr__

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
 def __setattr__(self, name, value):
     if name == 'user_id':
         if not self._user:
             self._user = DBSession.query(User).get(value)
         types = self._user.type.split(',')
         types.append(self.__tablename__)
         self._user.type = ','.join(set(types))
         return super(UserMixin, self).__setattr__(name, value)
     if 'tags' in name:
         name = 'tags'
     if hasattr(User, name):
         if not self._user and self.user_id:
             self._user = DBSession.query(User).get(self.user_id)
         if not self._user:
             _user = User()
             DBSession.add(_user)
             DBSession.flush()
             self.user_id = _user.id
         else:
             DBSession.add(self._user)
         try:
             return setattr(self._user, name, value)
         except DetachedInstanceError:
             DBSession.add(self._user)
             return setattr(self._user, name, value)
     else:
         return super(UserMixin, self).__setattr__(name, value)
开发者ID:umar93132,项目名称:portal,代码行数:29,代码来源:user.py

示例3: handle_if_company

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def handle_if_company(k, v, required=True, request=False):
    from alchemist.models.base import DBSession
    from alchemist.models.company import BaseCompany
    from alchemist.models.settings import Settings

    if k in ['company', 'company_id']:
        is_name = False
        try:
            company_id = int(v)
            company = DBSession.query(BaseCompany).get(company_id)
        except:
            v = v.replace(new_company_text, '')
            company = DBSession.query(BaseCompany).filter(BaseCompany.name == v).first()
            if not company:
                company = DBSession.query(BaseCompany).filter(BaseCompany.name.startswith(v.strip())).first()
            is_name = True
        assert not required or company, 'The company does not exist.'
        if not company and is_name:
            company = BaseCompany()
            company.name = v
            if request and request.referer and 'add/founder' in request.referer:
                company.is_alchemist = True
                company.alchemistclass = int(Settings.get('alchemistclass'))
                company.companytype = 'startup'
            DBSession.add(company)
            DBSession.flush()
        return company.id if k == 'company_id' else company
    return v
开发者ID:umar93132,项目名称:portal,代码行数:30,代码来源:misc.py

示例4: get_records

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def get_records(request, type, max_records, action_verb='export'):
    ids, excl_ids = get_ids(request)
    sess_query = request.session.get('query')
    filters = {User: [User.id.in_(ids)] if ids else user_where_from_query({'query': sess_query}),
               BaseCompany: [BaseCompany.id.in_(ids)] if ids else where_from_query({'sessquery': sess_query})}
    filters = filters[type]
    if excl_ids:
        filters.append(type.id.notin_(excl_ids))
    if not request.user.is_admin:
        filters.append(type.activated == True)
    if type == User:
        filters.append(User.primary_type != None)
    elif type == BaseCompany and 'alchemist_startup' in request.referer:
        filters.append(BaseCompany.is_alchemist == True)
        filters.append(BaseCompany.companytype == 'startup')

    if not (ids or (request.session.get('select_all') and sess_query is not None)):
        request.session.flash('We didn\'t find anything to %s' % action_verb, 'error')
        return False
    if len(ids) > max_records:
        request.session.flash('You cannot %s more than %s %s' % (action_verb, max_records,
                                                                 {BaseCompany: 'companies', User: 'contacts'}[type]),
                              'error')
        return False
    records = DBSession.query(type).outerjoin(User.company) if type == User else DBSession.query(type)
    records = records.filter(*filters).limit(max_records + 1).all()
    if len(records) > max_records:
        request.session.flash('You cannot %s more than %s %s' % (action_verb, max_records,
                                                                 {BaseCompany: 'companies', User: 'contacts'}[type]),
                              'error')
        return False
    return records
开发者ID:umar93132,项目名称:portal,代码行数:34,代码来源:list.py

示例5: handle_if_tags

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def handle_if_tags(i, v, splits=False, is_admin=False, otype='area_of_expertise'):
    from alchemist.models.tag import Tag
    from alchemist.models.base import DBSession

    obj = None
    if i == 'tags' or i.endswith('tags') or i == 'areas_of_interest':
        obj = Tag
    if obj:
        tags = []
        if splits == False:
            splits = [',']
        split = splits.pop()
        if v is not None:
            for tag in v.split(split):
                tag = tag.replace(new_tag_text, '')
                if not tag.strip():
                    continue
                if splits:
                    tags.extend(handle_if_tags(i, tag, splits=splits, is_admin=is_admin, otype=otype))
                    continue
                try:
                    ftag = DBSession.query(obj).get(int(tag))
                except:
                    ftag = DBSession.query(obj).filter(obj.text == tag.strip()).first()
                if not ftag and is_admin:
                    ftag = obj(text=tag.strip(), only_type=otype)
                if ftag:
                    tags.append(ftag)
        v = tags
    return v
开发者ID:umar93132,项目名称:portal,代码行数:32,代码来源:misc.py

示例6: list_answers

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def list_answers(page, page_size, query, request):
    queryAll = DBSession.query(Questions).join(Answers).filter(Answers.user_id == request.user.id)
    user_filter = get_filters(request) if query is not None else []

    results = queryAll.filter(*user_filter). \
        limit(page_size).offset(page * page_size)
    total = DBSession.query(func.count(Questions.id)).join(Answers).filter(Answers.user_id == request.user.id).filter(
        *user_filter). \
        limit(page_size).offset(page * page_size).scalar()
    return results, total
开发者ID:RaHus,项目名称:portal,代码行数:12,代码来源:questions.py

示例7: company

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
 def company(self, value):
     if self.company and value and self.company.id == value.id:
         return
     if self.company:
         DBSession.query(UserXCompany).filter(UserXCompany.company == self.company,
                                              UserXCompany.user == self,
                                              UserXCompany.end_date == None). \
             update({'end_date': utcnow().datetime})
     DBSession.add(UserXCompany(company=value, user=self, start_date=utcnow().datetime,
                                relation=TypeOfRelation.employee))
开发者ID:RaHus,项目名称:portal,代码行数:12,代码来源:user.py

示例8: list_questions

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def list_questions(page, page_size, query, request):
    user_filter = get_filters(request) if query is not None else []
    if request.matchdict.get('type') == 'questions':
        user_filter.append(Questions.user_id == request.user.id)
    user_filter.append(and_(Questions.user_id != None))
    results = DBSession.query(Questions).filter(*user_filter).order_by(desc(Questions.created_at)). \
        limit(page_size).offset(page * page_size)
    total = DBSession.query(func.count(Questions.id)).filter(*user_filter). \
        limit(page_size).offset(page * page_size).scalar()

    return results, total
开发者ID:RaHus,项目名称:portal,代码行数:13,代码来源:questions.py

示例9: list_trackings

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def list_trackings(page, page_size, query, request):
    queryAll = DBSession.query(Questions).join(Trackers).filter(Trackers.tracker_id == request.user.id,
                                                                Trackers.is_bookmark == (
                                                                    request.matchdict.get('type') == 'bookmarked'))
    user_filter = get_filters(request) if query is not None else []

    results = queryAll.filter(*user_filter).order_by(desc(Questions.created_at)). \
        limit(page_size).offset(page * page_size)
    total = DBSession.query(func.count(Questions.id)).join(Trackers).filter(
        Trackers.tracker_id == request.user.id).filter(*user_filter). \
        limit(page_size).offset(page * page_size).scalar()
    return results, total
开发者ID:RaHus,项目名称:portal,代码行数:14,代码来源:questions.py

示例10: startup_wishcustomers

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
 def startup_wishcustomers(self, companies):
     cids = map(attrgetter('id'), self.startup_wishcustomers)
     cids_new = map(attrgetter('id'), companies)
     for company in self.startup_wishcustomers:
         if company.id not in cids_new:
             DBSession.query(CompanyXCompany).filter(CompanyXCompany.company == company,
                                                     CompanyXCompany.by_company == self,
                                                     CompanyXCompany.relation == TypeOfRelation.wishlistcustomer).delete()
     for company in companies:
         if company.id not in cids:
             self.related_companies.append(
                 CompanyXCompany(company=company, by_company=self, relation=TypeOfRelation.wishlistcustomer))
开发者ID:RaHus,项目名称:portal,代码行数:14,代码来源:company.py

示例11: vote_to_answer

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def vote_to_answer(request):
    aid = request.POST.get('aid', -1)
    answer = DBSession.query(Answers).filter(Answers.id == aid).first()
    vote = DBSession.query(AnswerVotes).filter(AnswerVotes.answer_id == aid).filter(
        AnswerVotes.user_id == request.user.id).first()
    if vote is not None:
        DBSession.delete(vote)
    else:
        vote = AnswerVotes(answer=answer, user=request.user)
        DBSession.add(vote)
    vote_count = DBSession.query(func.count(AnswerVotes.id)).filter(AnswerVotes.answer_id == aid).scalar()
    return {'votes': vote_count}
开发者ID:RaHus,项目名称:portal,代码行数:14,代码来源:questions.py

示例12: list_companies

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def list_companies(self, page, page_size, query, request):
    filtr = [BaseCompany.name.ilike('%' + query + '%')]
    if not request.user or not request.user.is_admin:
        filtr.append(BaseCompany.activated == True)
    results = DBSession.query(BaseCompany.id, BaseCompany.name). \
        filter(*filtr).limit(page_size).offset(page * page_size).all()
    total = DBSession.query(func.count(BaseCompany.id)). \
        filter(*filtr).scalar()
    if self and page == total / page_size and len(query) > 2:
        nt = request.params.get('new_text')
        query = query.replace(nt or new_company_text, '')
        results.append((query, query + (nt or new_company_text)))
    return results, total
开发者ID:umar93132,项目名称:portal,代码行数:15,代码来源:company.py

示例13: render

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def render(request):
    conn = None
    existing_connection = request.params.get('conn_id')
    if existing_connection:
        conn = DBSession.query(Connection).get(int(existing_connection))
    type = request.matchdict.get('type')
    if not type and conn and conn.user.primary_type:
        type = conn.user.primary_type
    if type == 'mentor' or type == 'faculty':
        by_user = conn.by_user if conn else request.user
        to = conn.user if conn else User.bid(request.matchdict.get('to_id'))
        if not existing_connection:
            conn_data = {'by_user_cust_name': by_user.nicename,
                         'by_user_cust_email': by_user.email,
                         'by_user_cust_linkedin': by_user.linkedin_profile,
                         'by_user_cust_co_name': by_user.company.name if by_user.company else '',
                         'by_user_cust_co_website': by_user.company.website if by_user.company else '',
                         'by_user_cust_co_desc': by_user.company.description if by_user.company else '',
                         'by_user_cust_co_teamdesc': by_user.company.startup_teamdescription if by_user.company else '',
                         'type': 'RM'
                         }
        else:
            conn_data = {}
        conn = create_or_update_conn(by_user.id, existing_connection, to.id, **conn_data)
        message = conn.message if conn and conn.message else ''
        deleteonclose = 'connect/list' not in request.referrer
        return render_to_response('mentoring/request_meeting_modal.jinja2',
                                  {'to': to,
                                   'from': by_user,
                                   'conn': conn,
                                   'deleteonclose': deleteonclose,
                                   'message': message}, request)
    elif type == 'company':
        if conn:
            company = conn.company
        else:
            company = DBSession.query(BaseCompany).get(request.matchdict.get('to_id'))
        main_poc = find_poc(company, request)
        return render_to_response('company/connect_company_modal.jinja2',
                                  {'to': company,
                                   'main_poc': main_poc[0],
                                   'conn': conn,
                                   'by_user': conn.by_user if conn else request.user,
                                   'message': conn.message if conn else ''}, request)
    else:
        return render_to_response('connect_me/connect_me_modal.jinja2',
                                  {'to': conn.user if conn else User.bid(request.matchdict.get('to_id')),
                                   'from': conn.by_user if conn else request.user,
                                   'conn': conn,
                                   'message': conn.message if conn else ''}, request)
开发者ID:RaHus,项目名称:portal,代码行数:52,代码来源:connect_me.py

示例14: primary_type

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
 def primary_type(self, val):
     current_prim = DBSession.query(RoleXUser).filter(RoleXUser.is_primary == True,
                                                      RoleXUser.user_id == self.id).first()
     if current_prim and current_prim.role.title != val:
         current_prim.is_primary = False
     existing_role = DBSession.query(RoleXUser).join(Role).filter(Role.title == val,
                                                                  RoleXUser.user_id == self.id).first()
     if existing_role:
         existing_role.is_primary = True
     else:
         role = DBSession.query(Role).filter(Role.title == val).first()
         if role:
             role_x_user = RoleXUser(role=role, user=self, is_primary=True)
             Session.object_session(self).add(role_x_user)
开发者ID:RaHus,项目名称:portal,代码行数:16,代码来源:user.py

示例15: addto_track

# 需要导入模块: from alchemist.models.base import DBSession [as 别名]
# 或者: from alchemist.models.base.DBSession import query [as 别名]
def addto_track(request):
    qid = request.POST.get('qid', -1)
    question = DBSession.query(Questions).filter(Questions.id == qid).first()
    bookmark_ = (request.POST.get('type') == 'bookmark')
    existed = DBSession.query(Trackers).filter(Trackers.questions_id == qid).filter(
        Trackers.tracker_id == request.user.id,
        Trackers.is_bookmark == bookmark_).first()
    if existed:
        DBSession.delete(existed)
        return {'type': 'removed'}
    else:
        tracker = Trackers(tracker=request.user, question=question, is_bookmark=bookmark_)
        DBSession.add(tracker)
        return {'type': 'added'}
开发者ID:RaHus,项目名称:portal,代码行数:16,代码来源:questions.py


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