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


Python models.Session方法代码示例

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


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

示例1: get_expirable_session_var

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def get_expirable_session_var(session: Session, var_name: str, default_value: Any=None,
                              delete: bool=False) -> Any:
    if var_name not in session:
        return default_value

    try:
        value, expire_at = (session[var_name]['value'], session[var_name]['expire_at'])
    except (KeyError, TypeError):
        logging.warning("get_expirable_session_var: error getting %s", var_name, exc_info=True)
        return default_value

    if timestamp_to_datetime(expire_at) < timezone_now():
        del session[var_name]
        return default_value

    if delete:
        del session[var_name]
    return value 
开发者ID:zulip,项目名称:zulip,代码行数:20,代码来源:sessions.py

示例2: is_locked

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def is_locked(self) -> bool:
        """Check if the workflow is locked.

        :return: Is the given workflow locked?
        """
        if not self.session_key:
            # No key in the workflow, then it is not locked.
            return False

        session = Session.objects.filter(session_key=self.session_key).first()
        if not session:
            # Session does not exist, then it is not locked
            return False

        # Session is in the workflow and in the session table. Locked if expire
        # date is beyond the current time.
        return session.expire_date >= timezone.now() 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:19,代码来源:workflow.py

示例3: _wf_lock_and_update

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def _wf_lock_and_update(
    session: SessionStore,
    user: get_user_model(),
    workflow: models.Workflow,
    create_session: Optional[bool] = False,
) -> models.Workflow:
    """Lock a workflow and updates the value in the session.

    :param session: Session being used
    :param user: User requesting the lock
    :param workflow: Workflow being modified
    :param create_session: Boolean encoding if a session needs to be created.
    :param workflow: Object to store
    """
    workflow.lock(session, user, create_session)
    # Update nrows in case it was asynch modified
    _store_workflow_nrows_in_session(session, workflow)

    return workflow 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:21,代码来源:session_ops.py

示例4: sessionend_handler

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def sessionend_handler(sender, **kwargs):
    # cleanup session (temp) data
    logging.debug('Session closing, cleanup ..')
    session = kwargs.get('instance').session_key
    if session != '':
        tempdir = os.path.join('data', 'session', session)
        if os.path.exists(tempdir):
            logging.debug('Deleting %s ..' % tempdir)
            shutil.rmtree(tempdir) 
开发者ID:CiscoDevNet,项目名称:yang-explorer,代码行数:11,代码来源:models.py

示例5: get_session_user

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def get_session_user(session: Session) -> Optional[int]:
    return get_session_dict_user(session.get_decoded()) 
开发者ID:zulip,项目名称:zulip,代码行数:4,代码来源:sessions.py

示例6: user_sessions

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def user_sessions(user_profile: UserProfile) -> List[Session]:
    return [s for s in Session.objects.all()
            if get_session_user(s) == user_profile.id] 
开发者ID:zulip,项目名称:zulip,代码行数:5,代码来源:sessions.py

示例7: delete_session

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def delete_session(session: Session) -> None:
    session_engine.SessionStore(session.session_key).delete() 
开发者ID:zulip,项目名称:zulip,代码行数:4,代码来源:sessions.py

示例8: delete_user_sessions

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def delete_user_sessions(user_profile: UserProfile) -> None:
    for session in Session.objects.all():
        if get_session_user(session) == user_profile.id:
            delete_session(session) 
开发者ID:zulip,项目名称:zulip,代码行数:6,代码来源:sessions.py

示例9: delete_realm_user_sessions

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def delete_realm_user_sessions(realm: Realm) -> None:
    realm_user_ids = [user_profile.id for user_profile in
                      UserProfile.objects.filter(realm=realm)]
    for session in Session.objects.filter(expire_date__gte=timezone_now()):
        if get_session_user(session) in realm_user_ids:
            delete_session(session) 
开发者ID:zulip,项目名称:zulip,代码行数:8,代码来源:sessions.py

示例10: delete_all_deactivated_user_sessions

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def delete_all_deactivated_user_sessions() -> None:
    for session in Session.objects.all():
        user_profile_id = get_session_user(session)
        if user_profile_id is None:  # nocoverage  # TODO: Investigate why we lost coverage on this
            continue
        user_profile = get_user_profile_by_id(user_profile_id)
        if not user_profile.is_active or user_profile.realm.deactivated:
            logging.info("Deactivating session for deactivated user %s", user_profile.id)
            delete_session(session) 
开发者ID:zulip,项目名称:zulip,代码行数:11,代码来源:sessions.py

示例11: set_expirable_session_var

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def set_expirable_session_var(session: Session, var_name: str, var_value: Any, expiry_seconds: int) -> None:
    expire_at = datetime_to_timestamp(timezone_now() + timedelta(seconds=expiry_seconds))
    session[var_name] = {'value': var_value, 'expire_at': expire_at} 
开发者ID:zulip,项目名称:zulip,代码行数:5,代码来源:sessions.py

示例12: session_cache_items

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def session_cache_items(items_for_remote_cache: Dict[str, str],
                        session: Session) -> None:
    if settings.SESSION_ENGINE != "django.contrib.sessions.backends.cached_db":
        # If we're not using the cached_db session engine, we there
        # will be no store.cache_key attribute, and in any case we
        # don't need to fill the cache, since it won't exist.
        return
    store = session_engine.SessionStore(session_key=session.session_key)
    items_for_remote_cache[store.cache_key] = store.decode(session.session_data) 
开发者ID:zulip,项目名称:zulip,代码行数:11,代码来源:cache_helpers.py

示例13: get_user_locking_workflow

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def get_user_locking_workflow(self):
        """Get the user that is locking a workflow.

        Given a workflow that is supposed to be locked, it returns the user
        that is locking it.

        :return: The user object that is locking this workflow
        """
        session = Session.objects.get(session_key=self.session_key)
        session_data = session.get_decoded()
        return get_user_model().objects.get(
            id=session_data.get('_auth_user_id')) 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:14,代码来源:workflow.py

示例14: _store_workflow_nrows_in_session

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def _store_workflow_nrows_in_session(
    session: SessionStore,
    wflow: models.Workflow
):
    """Store the workflow id and name in the request.session dictionary.

    :param session: Session object to store the worklfow
    :param wflow: Workflow object
    :return: Nothing. Store the id and the name in the session
    """
    session['ontask_workflow_rows'] = wflow.nrows
    session.save() 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:14,代码来源:session_ops.py

示例15: build_request

# 需要导入模块: from django.contrib.sessions import models [as 别名]
# 或者: from django.contrib.sessions.models import Session [as 别名]
def build_request(self, **kwargs):
        request_kwargs = {
            "request_id": kwargs.get("request_id", 1),
            "scope": kwargs.get(
                "scope",
                {
                    "user": kwargs.get("user", AnonymousUser()),
                    "session": kwargs.get("session", Session()),
                    "headers": kwargs.get("headers", ()),
                },
            ),
            "workflow": kwargs.get("workflow", Workflow()),
            "path": kwargs.get("path", "test.path"),
            "arguments": kwargs.get("arguments", {}),
        }
        for key in list(request_kwargs["scope"].keys()) + list(request_kwargs.keys()):
            try:
                del kwargs[key]
            except KeyError:
                pass

        # Turn other params, like `wf_module_id=123`, into
        # `arguments={'wf_module_id':123}`
        request_kwargs["arguments"].update(kwargs)

        return HandlerRequest(**request_kwargs) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:28,代码来源:util.py


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