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


Python models.DBSession类代码示例

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


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

示例1: activate

def activate(request):
    """
    """
    user_id = request.matchdict.get('user_id')
    user = AuthUser.get_by_id(user_id)
    submitted_hmac = request.matchdict.get('hmac')
    current_time = time.time()
    time_key = int(base64.b64decode(submitted_hmac[10:]))
    if current_time < time_key:
        hmac_key = hmac.new('%s:%s:%d' % (str(user.id), \
                            apex_settings('auth_secret'), time_key), \
                            user.email).hexdigest()[0:10]
        if hmac_key == submitted_hmac[0:10]:
            user.active = 'Y'
            DBSession.merge(user)
            DBSession.flush()
            flash(_('Account activated. Please log in.'))
            activated_route = apex_settings('activated_route')
            if not activated_route:
                activated_route = 'apex_login'
            return HTTPFound(location=route_url(activated_route, request))

    flash(_('Invalid request, please try again'))
    return HTTPFound(location=route_url(apex_settings('came_from_route'), \
                                        request))
开发者ID:akirisolutions-zz,项目名称:apex,代码行数:25,代码来源:views.py

示例2: profile_edit

def profile_edit(request):
    form = ProfileRecordForm(request.POST)
    if 'record_id' in request.matchdict:
        record = get_profile_record(request.matchdict['id'], \
            request.matchdict['record_id'])
        if not request.POST:
            form.record_type.data = record.record_type
            form.name.data = record.name
            form.contents.data = record.contents
    else:
        record = Profile_Record(profile_id=request.matchdict['id'])

    if request.method == 'POST' and form.validate():
        if request.POST['record_type'] in ['TXT', 'SPF']:
            request.POST['contents'] = '"' + request.POST['contents'] \
                .replace('"','') + '"'
        record = merge_session_with_post(record, request.POST.items())
        DBSession.merge(record)
        DBSession.flush()
        return HTTPFound(location= \
            route_url('apex_route53_profile_edit', request, \
            id=request.matchdict['id']))
    return {'title':'Edit Profile Records', \
        'form':form, \
        'profile':get_profile(request.matchdict['id']), \
        'profile_records':get_profile_records(request.matchdict['id'])}
开发者ID:cd34,项目名称:apex-route53,代码行数:26,代码来源:views.py

示例3: setUpClass

 def setUpClass(cls):
     """ must add default route 'home' and include apex
         we also must create a default user/pass/group to test
     """
     cls.engine = engine_from_config(settings, prefix='sqlalchemy.')
     DBSession.configure(bind=cls.engine)
     Base.metadata.create_all(cls.engine)
开发者ID:nicfit,项目名称:apex,代码行数:7,代码来源:__init__.py

示例4: create_user

def create_user(**kwargs):
    """

::

    from apex.lib.libapex import create_user

    create_user(username='test', password='my_password', active='Y', group='group')


    Returns: AuthUser object
    """
    user = AuthUser()

    if 'group' in kwargs:
        try:
            group = DBSession.query(AuthGroup). \
            filter(AuthGroup.name==kwargs['group']).one()

            user.groups.append(group)
        except NoResultFound:
            pass

        del kwargs['group']

    for key, value in kwargs.items():
        setattr(user, key, value)

    DBSession.add(user)
    DBSession.flush()
    return user
开发者ID:nathanielbaxter,项目名称:apex,代码行数:31,代码来源:libapex.py

示例5: edit

def edit(request):
    """ edit(request)
        no return value, called with route_url('apex_edit', request)

        This function will only work if you have set apex.auth_profile.

        This is a very simple edit function it works off your auth_profile
        class, all columns inside your auth_profile class will be rendered.
    """
    title = _('Edit')

    ProfileForm = model_form(
        model=get_module(apex_settings('auth_profile')),
        base_class=ExtendedForm,
        exclude=('id', 'user_id'),
    )

    record = AuthUser.get_profile(request)
    form = ProfileForm(obj=record)
    if request.method == 'POST' and form.validate():
        record = merge_session_with_post(record, request.POST.items())
        DBSession.merge(record)
        DBSession.flush()
        flash(_('Profile Updated'))
        return HTTPFound(location=request.url)

    return {'title': title, 'form': form, 'action': 'edit'}
开发者ID:mobyle2-legacy,项目名称:apex,代码行数:27,代码来源:views.py

示例6: profile_delete

def profile_delete(request):
    record = get_profile_record(request.matchdict['id'], \
        request.matchdict['record_id'])
    DBSession.delete(record)
    DBSession.flush()
    return HTTPFound(location= \
        route_url('apex_route53_profile_edit', request, \
        id=request.matchdict['id']))
开发者ID:cd34,项目名称:apex-route53,代码行数:8,代码来源:views.py

示例7: __acl__

 def __acl__(self):
     dbsession = DBSession()
     groups = dbsession.query(AuthGroup.name).all()
     defaultlist = [ (Allow, Everyone, 'view'),
             (Allow, Authenticated, 'authenticated'),]
     for g in groups:
         defaultlist.append( (Allow, 'group:%s' % g, g[0]) )
     return defaultlist
开发者ID:nathanielbaxter,项目名称:apex,代码行数:8,代码来源:libapex.py

示例8: profiles

def profiles(request):
    form = ProfileForm(request.POST)
    if request.method == 'POST' and form.validate():
        record = Profile()
        record = merge_session_with_post(record, request.POST.items())
        DBSession.merge(record)
        DBSession.flush()
        return HTTPFound(location= \
            route_url('apex_route53_profiles', request))
    return {'title':'Profiles', 'form':form, 'profiles':get_profiles()}
开发者ID:cd34,项目名称:apex-route53,代码行数:10,代码来源:views.py

示例9: create_user

    def create_user(self, username):
        user = AuthUser(username=username, password=self.data["password"], email=self.data["email"])
        DBSession.add(user)
        settings = get_current_registry().settings
        if settings.has_key("apex.default_user_group"):
            group = DBSession.query(AuthGroup).filter(AuthGroup.name == settings["apex.default_user_group"]).one()
            user.groups.append(group)
        DBSession.flush()

        return user
开发者ID:webjunkie01,项目名称:apex,代码行数:10,代码来源:forms.py

示例10: register

def register(request):
    """ register(request):
    no return value, called with route_url('apex_register', request)
    """
    title = _('Register')
    came_from = request.params.get('came_from', \
                    route_url(apex_settings('came_from_route'), request))
    velruse_forms = generate_velruse_forms(request, came_from)

    #This fixes the issue with RegisterForm throwing an UnboundLocalError
    if apex_settings('register_form_class'):
        RegisterForm = get_module(apex_settings('register_form_class'))
    else:
        from apex.forms import RegisterForm

    if 'local' not in apex_settings('provider_exclude', []):
        if asbool(apex_settings('use_recaptcha_on_register')):
            if apex_settings('recaptcha_public_key') and apex_settings('recaptcha_private_key'):
                RegisterForm.captcha = RecaptchaField(
                    public_key=apex_settings('recaptcha_public_key'),
                    private_key=apex_settings('recaptcha_private_key'),
                )

        form = RegisterForm(request.POST, captcha={'ip_address': request.environ['REMOTE_ADDR']})
    else:
        form = None

    if request.method == 'POST' and form.validate():
        user = form.save()
        need_verif = apex_settings('need_mail_verification')
        response = HTTPFound(location=came_from)
        if need_verif:
            try:
                DBSession.add(user)
            except:
                pass
            begin_activation_email_process(request, user)
            user.active = 'N'
            DBSession.flush()
            flash(_('User sucessfully created, '
                    'please verify your account by clicking '
                    'on the link in the mail you just received from us !'), 'success')

            response = HTTPFound(location=came_from)
        else:
            transaction.commit()
            headers = apex_remember(request, user.id, internal_user=True)
            response = HTTPFound(location=came_from, headers=headers)
        return response

    return {'title': title,
            'form': form,
            'velruse_forms': velruse_forms,
            'action': 'register'}
开发者ID:mobyle2-legacy,项目名称:apex,代码行数:54,代码来源:views.py

示例11: apexid_from_token

def apexid_from_token(token):
    """ Returns the apex id from the OpenID Token
    """
    dbsession = DBSession()
    auth = json.loads(dbsession.query(KeyStorage.value). \
                      filter(KeyStorage.key==token).one()[0])
    if 'profile' in auth:
        auth['id'] = auth['profile']['accounts'][0]['userid']
        auth['provider'] = auth['profile']['accounts'][0]['domain']
        return auth
    return None
开发者ID:nathanielbaxter,项目名称:apex,代码行数:11,代码来源:libapex.py

示例12: apex_remember

def apex_remember(request, user_id):
    if asbool(apex_settings('log_logins')):
        if apex_settings('log_login_header'):
            ip_addr=request.environ.get(apex_settings('log_login_header'), \
                    u'invalid value - apex.log_login_header')
        else:
             ip_addr=request.environ['REMOTE_ADDR']
        record = AuthUserLog(user_id=user_id, ip_addr=ip_addr)
        DBSession.add(record)
        DBSession.flush()
    return remember(request, user_id)
开发者ID:nathanielbaxter,项目名称:apex,代码行数:11,代码来源:libapex.py

示例13: webhosts

def webhosts(request):
    form = ProviderForm(request.POST)
    providers = DBSession.query(Provider).order_by(Provider.name).all()
    record = Provider()

    if request.method == 'POST' and form.validate():
        record = merge_session_with_post(record, request.POST.items())
        DBSession.merge(record)
        DBSession.flush()
        return HTTPFound(location= \
            route_url('apex_route53_webhosts', request))
    return {'title':'Web Hosts', 'form':form, 'providers':providers}
开发者ID:cd34,项目名称:apex-route53,代码行数:12,代码来源:views.py

示例14: create_user

    def create_user(self, auth_id, login):
        id = DBSession.query(AuthID).filter(AuthID.id==auth_id).one()
        user = AuthUser(
            login=login,
            password=self.data['password'],
            email=self.data['email'],
        )
        id.users.append(user)
        DBSession.add(user)
        DBSession.flush()

        return user
开发者ID:LeoKudrik,项目名称:apex,代码行数:12,代码来源:forms.py

示例15: apexid_from_token

def apexid_from_token(token):
    """ Returns the apex id from the OpenID Token
    """
    dbsession = DBSession()
    auth = json.loads(dbsession.query(KeyStorage.value). \
                      filter(KeyStorage.key==token).one()[0])
    if 'profile' in auth:
        id = apexid_from_url(auth['profile']['providerName'], \
                             auth['profile']['identifier'])
        auth['apexid'] = id
        return auth
    return None
开发者ID:webjunkie01,项目名称:apex,代码行数:12,代码来源:libapex.py


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