當前位置: 首頁>>代碼示例>>Python>>正文


Python current.session方法代碼示例

本文整理匯總了Python中gluon.current.session方法的典型用法代碼示例。如果您正苦於以下問題:Python current.session方法的具體用法?Python current.session怎麽用?Python current.session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gluon.current的用法示例。


在下文中一共展示了current.session方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: item_list

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def item_list():
    """Show the list of items in this desk"""
    desk = db.desk(request.args(0))

    if desk.id == application.getUserDesk().id:
        session.org_id = None
    session.desk_id = desk.id

    if not request.vars.item_per_load:
        item_per_load = 5
    else:
        item_per_load = int(request.vars.item_per_load)

    # make a query and load the items
    item_list = db(db.item.id.belongs(desk.item_list)).select(
        orderby=[~db.item.created_on],
        limitby=(0, item_per_load+1)
    )

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:22,代碼來源:desk.py

示例2: logout

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def logout(self, log=DEFAULT, onlogout=DEFAULT, **kwargs):
        """
        Logs out user
        """
        settings = self.settings
        session = current.session

        if onlogout is DEFAULT:
            onlogout = settings.logout_onlogout
        if onlogout:
            onlogout(self.user)
        if log is DEFAULT:
            log = self.messages['logout_log']
        if self.user:
            self.log_event(log, self.user)

        session.auth = None
        self.user = None
        if settings.renew_session_onlogout:
            session.renew(clear_session=not settings.keep_session_onlogout)

        return {'errors': None, 'message': self.messages.logged_out, 'user': None} 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:24,代碼來源:authapi.py

示例3: __init__

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def __init__(self):
        super(Application, self).__init__()

        # copy current context
        self.db = current.db
        self.T = current.T
        self.auth = current.auth
        self.request = current.request
        self.response = current.response
        self.session = current.session
        self.mail = current.mail
        self.conf = current.conf
        self.registry = Storage()
        self.cache = Cache(self.request) 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:16,代碼來源:app.py

示例4: create

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def create():
    fields = []

    fld_headline = db.item.headline
    fields.extend([fld_headline, db.item.keywords, db.item.genre])
    fdl_item_type = db.item.item_type
    fdl_item_type.writable = False
    fdl_item_type.readable = False
    fdl_item_type.default = 'photoset'

    form = SQLFORM.factory(
        *fields,
        table_name='plugin_photo_set'  # to allow the correct form name
    )

    if form.process(dbio=False).accepted:
        # item_id = CT_REG.photoset.create_item(form.vars)
        item_id = application.createItem('photoset', form.vars)
        form.vars.item_id = item_id
        if session.plugin_photoset:
            form.vars.photoset = session.plugin_photoset.photos
        else:
            form.vars.phoset = []
        db.plugin_photoset_content.insert(
            **db.plugin_photoset_content._filter_fields(
                form.vars
            )
        )
        application.indexItem(item_id)
        session.plugin_photoset = None
        redirect(URL('default', 'index.html'))

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:35,代碼來源:plugin_photoset.py

示例5: create

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def create():
    if not session.marked_items:
        session.flash = T('You must mark some items first')
        redirect(URL('default', 'index'))

    fields = []
    # i need the input of the based item fields
    fdl_headline = db.item.headline
    fields.append(fdl_headline)
    fdl_keywords = db.item.keywords
    keywords_list = []
    for item_id in session.marked_items:
        _item = application.getItemByUUID(item_id)
        keywords_list.extend(_item.keywords)
    keywords_list = list(set(keywords_list))  # remove any dup
    fdl_keywords.default = keywords_list
    fields.append(fdl_keywords)
    fields.append(db.item.genre)
    fdl_item_type = db.item.item_type
    fdl_item_type.writable = False
    fdl_item_type.readable = False
    fdl_item_type.default = 'package'
    fields.append(db.plugin_package_content.description)

    form = SQLFORM.factory(
        *fields,
        table_name='plugin_package_item'  # to allow the correct file name
    )

    if form.process(dbio=False).accepted:
        form.vars.item_id = application.createItem('package', form.vars)
        form.vars.item_list = session.marked_items
        db.plugin_package_content.insert(
            **db.plugin_package_content._filter_fields(form.vars)
        )
        application.indexItem(form.vars.item_id)
        session.marked_items = []
        redirect(URL('default', 'index'))

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:42,代碼來源:plugin_package.py

示例6: search

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def search():
    if not request.vars.item_per_load:
        item_per_load = 5
    else:
        item_per_load = int(request.vars.item_per_load)

    desk = db.desk(session.desk_id)

    search_keys = request.vars.search_keys
    results = Whoosh().search(search_keys, 1, pagelen=item_per_load+1)

    # remove from result the item not accesible for the user
    # TODO: e more elegant way of doing this
    results = [x for x in results if application.canReadItem(x)]
    # --
    query = db.item.unique_id.belongs(results)

    if request.vars.opt == 'desk':
        # search only in desk
        query &= db.item.id.belongs(desk.item_list)

    item_list = db(
        query
    ).select(
        orderby=[~db.item.created_on],
        limitby=(0, item_per_load+1)
    )


    response.view = 'desk/item_list.load'
    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:33,代碼來源:item.py

示例7: view

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def view():
    """
    Show the list of desks in this org
    """
    org = db.organization(request.args(0))
    session.org_id = org.id
    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:9,代碼來源:org.py

示例8: index

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def index():
    """Show the list of items in this desk"""
    desk = db.desk(request.args(0))

    if desk.id == application.getUserDesk().id:
        session.org_id = None
    session.desk_id = desk.id
    if session.marked_items is None:
        session.marked_items = []

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:13,代碼來源:desk.py

示例9: edit

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def edit():
    desk = db.desk(request.args(0))
    session.desk_id = desk.id

    db.desk.item_list.readable = False
    db.desk.item_list.writable = False
    form = SQLFORM(db.desk, record=desk, showid=False)

    if form.process().accepted:
        redirect(URL('index', args=[desk.id]))

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:14,代碼來源:desk.py

示例10: delete

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def delete():
    desk = db.desk(request.args(0))
    session.desk_id = desk.id

    db.desk.item_list.readable = False
    db.desk.item_list.writable = False
    form = SQLFORM.confirm(
        T("Are you sure?"),
        {T('Cancel'): URL('index', args=[desk.id])})

    if form.accepted:
        # empty move all the items in the desk to the owners desk
        for item_id in desk.item_list:
            item = db.item(item_id)
            owner = db.auth_user(item.created_by)
            owner_desk = application.getUserDesk(user=owner)
            owner_desk_items = owner_desk.item_list
            owner_desk_items.append(item_id)
            owner_desk.update_record(item_list=owner_desk_items)

        # remove desk from org
        org = db(
            db.organization.desks.contains(desk.id)
        ).select().first()
        desk_list = org.desks
        desk_list.remove(desk.id)
        org.update_record(desks=desk_list)
        # delete the desk from db.
        del db.desk[desk.id]
        # cleanup context
        session.desk_id = None
        # go to org view
        redirect(URL('org','view', args=[org.id]))

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:37,代碼來源:desk.py

示例11: create

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def create():
    org = db.organization(session.org_id)
    tbl = db.desk
    tbl.item_list.readable = False
    tbl.item_list.writable = False
    tbl.name.requires = IS_NOT_EMPTY()

    form = SQLFORM(db.desk)
    form.add_button(T('Cancel'), URL('org', 'view', args=[org.id]))

    if form.process().accepted:
        # add the new desk to the org list
        desk_id = form.vars.id
        # add current users as the one with permission to update manage
        # this desk
        auth.add_permission(
            auth.user_group(auth.user.id),
            'update',
            db.desk,
            desk_id)
        desk_list = org.desks
        desk_list.insert(0, desk_id)
        org.update_record(desks=desk_list)
        # return to the org desk list
        redirect(URL('org', 'view', args=[org.id]))

    return locals() 
開發者ID:ybenitezf,項目名稱:nstock,代碼行數:29,代碼來源:desk.py

示例12: accessToken

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def accessToken(self):
        """Return the access token generated by the authenticating server.

        If token is already in the session that one will be used.
        Otherwise the token is fetched from the auth server.

        """

        if self.session.access_token:
            # return the token (TODO: does it expire?)

            return self.session.access_token
        if self.session.request_token:
            # Exchange the request token with an authorization token.
            token = self.session.request_token
            self.session.request_token = None

            # Build an authorized client
            # OAuth1.0a put the verifier!
            token.set_verifier(self.request.vars.oauth_verifier)
            client = oauth.Client(self.consumer, token)

            resp, content = client.request(self.access_token_url, "POST")
            if str(resp['status']) != '200':
                self.session.request_token = None
                self.globals['redirect'](self.globals[
                                         'URL'](f='user', args='logout'))

            self.session.access_token = oauth.Token.from_string(content)

            return self.session.access_token

        self.session.access_token = None
        return None 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:36,代碼來源:oauth10a_account.py

示例13: __init__

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def __init__(self, g, client_id, client_secret, auth_url, token_url, access_token_url, socket_timeout=60):
        self.globals = g
        self.client_id = client_id
        self.client_secret = client_secret
        self.code = None
        self.request = current.request
        self.session = current.session
        self.auth_url = auth_url
        self.token_url = token_url
        self.access_token_url = access_token_url
        self.socket_timeout = socket_timeout

        # consumer init
        self.consumer = oauth.Consumer(self.client_id, self.client_secret) 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:16,代碼來源:oauth10a_account.py

示例14: logout_url

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def logout_url(self, next="/"):
        self.session.request_token = None
        self.session.access_token = None
        return next 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:6,代碼來源:oauth10a_account.py

示例15: __oauth_login

# 需要導入模塊: from gluon import current [as 別名]
# 或者: from gluon.current import session [as 別名]
def __oauth_login(self, next):
        '''This method redirects the user to the authenticating form
        on authentication server if the authentication code
        and the authentication token are not available to the
        application yet.

        Once the authentication code has been received this method is
        called to set the access token into the session by calling
        accessToken()
        '''

        if not self.accessToken():
            # setup the client
            client = oauth.Client(self.consumer, None, timeout=self.socket_timeout)
            # Get a request token.
            # oauth_callback *is REQUIRED* for OAuth1.0a
            # putting it in the body seems to work.
            callback_url = self.__redirect_uri(next)
            data = urlencode(dict(oauth_callback=callback_url))
            resp, content = client.request(self.token_url, "POST", body=data)
            if resp['status'] != '200':
                self.session.request_token = None
                self.globals['redirect'](self.globals[
                                         'URL'](f='user', args='logout'))

            # Store the request token in session.
            request_token = self.session.request_token = oauth.Token.from_string(content)

            # Redirect the user to the authentication URL and pass the callback url.
            data = urlencode(dict(oauth_token=request_token.key,
                                  oauth_callback=callback_url))
            auth_request_url = self.auth_url + '?' + data

            HTTP = self.globals['HTTP']

            raise HTTP(302,
                       "You are not authenticated: you are being redirected to the <a href='" + auth_request_url + "'> authentication server</a>",
                       Location=auth_request_url)

        return None 
開發者ID:HackPucBemobi,項目名稱:touch-pay-client,代碼行數:42,代碼來源:oauth10a_account.py


注:本文中的gluon.current.session方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。