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


Python base.DBSession类代码示例

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


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

示例1: __setattr__

 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,代码行数:27,代码来源:user.py

示例2: get_records

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,代码行数:32,代码来源:list.py

示例3: handle_if_tags

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,代码行数:30,代码来源:misc.py

示例4: add_empty_connection

def add_empty_connection(request):
    user = User(primary_type='base')
    user.activated = True
    user.login_enabled = False
    DBSession.add(user)
    DBSession.flush()
    return HTTPFound('/base/%s' % user.id)
开发者ID:RaHus,项目名称:portal,代码行数:7,代码来源:administration.py

示例5: handle_if_company_tags

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,代码行数:25,代码来源:misc.py

示例6: initial_data

 def initial_data(cls):
     data = ("Pre-Seed", "Seed", "Series A", "Series B", "Series C", "Series D and higher")
     stages = []
     for title in data:
         stage = cls(title=title)
         stages.append(stage)
     DBSession.add_all(stages)
     return stages
开发者ID:RaHus,项目名称:portal,代码行数:8,代码来源:stage_interest.py

示例7: list_answers

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,代码行数:10,代码来源:questions.py

示例8: mark_unwanted

def mark_unwanted(request):
    unwanted_user = int(request.matchdict.get('user_id'))
    weekly_focus = request.user.weekly_focus.lower().replace(' ', '_')
    rp = request.POST.get
    DBSession.add(UnWanted(by_user=request.user, user_id=unwanted_user,
                           weekly_focus=weekly_focus, connected=rp('connected') == 'true',
                           rating=rp('rating'), feedback=rp('feedback')))
    cache = get_region('main')
    cache.invalidate()
    return HTTPFound(request.referer or '/')
开发者ID:umar93132,项目名称:portal,代码行数:10,代码来源:actions.py

示例9: company

 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,代码行数:10,代码来源:user.py

示例10: create_conn

def create_conn(by_user_id, to_id):
    try:
        conn = Connection(by_user_id=by_user_id, user_id=to_id)
    except:
        logging.error('Please specify by_user_id and to_id fields', exc_info=1)
        return
    DBSession.add(conn)
    DBSession.flush()
    _, conn.code = gen_ver_code(conn.id, 14)
    return conn
开发者ID:RaHus,项目名称:portal,代码行数:10,代码来源:connect_me.py

示例11: remove_connection

def remove_connection(request):
    auth_user = User.bid(request.authenticated_userid)
    assert auth_user, 'No user'
    conn_id = request.matchdict.get('conn_id')
    conn = DBSession.query(Connection).filter(Connection.id == conn_id, Connection.by_user_id == auth_user.id).first()
    assert conn, 'You are not authorized to perform this action'
    DBSession.delete(conn)
    DBSession.flush()

    return ''
开发者ID:umar93132,项目名称:portal,代码行数:10,代码来源:connect_me.py

示例12: list_questions

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,代码行数:11,代码来源:questions.py

示例13: main

def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    session_factory = session_factory_from_settings(settings)
    authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy,
                          session_factory=session_factory)

    config.include('pyramid_jinja2')
    add_jinja2_extension(config, ext.do)
    add_jinja2_extension(config, ext.loopcontrols)
    add_jinja2_extension(config, SelectiveHTMLCompress)
    add_jinja2_search_path(config, 'alchemist:general/layout/')
    add_jinja2_search_path(config, 'alchemist:general/blocks/')
    add_jinja2_search_path(config, 'alchemist:general/helpers/')

    config.include('pyramid_mailer')

    scheduler.add_jobstore('sqlalchemy', url=settings['sqlalchemy.url'])
    scheduler_tz = settings.get('scheduler.timezone')
    if scheduler_tz:
        scheduler.configure(timezone=scheduler_tz)
    scheduler.pyramid_registry = config.registry

    def get_user(request):
        id = authenticated_userid(request)
        if not id:
            return None
        return User.bid(id)

    config.add_request_method(get_user, 'user', reify=True)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('export-dumps', 'export-dumps', cache_max_age=3600)
    config.add_static_view('img', 'static/img', cache_max_age=3600)
    config.add_static_view('css', 'static/css', cache_max_age=3600)
    config.add_static_view('js', 'static/js', cache_max_age=3600)
    config.add_static_view('fonts', 'static/fonts', cache_max_age=3600)
    config.add_static_view('upload', 'upload', cache_max_age=3600)

    config.scan('alchemist')
    # it's important that this is after scan
    # TODO: make a venusian? decorator, maybe will not need the include then
    config.include('alchemist:qaforum.emails')
    scheduler.start()

    return config.make_wsgi_app()
开发者ID:RaHus,项目名称:portal,代码行数:54,代码来源:__init__.py

示例14: list_trackings

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,代码行数:12,代码来源:questions.py

示例15: add_company_to_notablecustomers_view

def add_company_to_notablecustomers_view(request):
    if request.method == 'POST':
        current_company_id = request.POST.get('company_id', False)
        current_company = DBSession.query(BaseCompany).filter(BaseCompany.id == current_company_id).first()
        assert current_company, 'The company you are trying to edit does not exist'
        new_company_name = request.POST.get('name')
        new_company = BaseCompany(name=new_company_name)
        DBSession.add(new_company)
        current_company.notablecustomers.append(new_company)
        return {'item': current_company,
                'is_my_comp': request.user and request.user.company_id and
                              request.user.company_id == current_company.id}
开发者ID:RaHus,项目名称:portal,代码行数:12,代码来源:administration.py


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