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


Python base.SessionBase方法代码示例

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


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

示例1: __init__

# 需要导入模块: from django.contrib.sessions.backends import base [as 别名]
# 或者: from django.contrib.sessions.backends.base import SessionBase [as 别名]
def __init__(
        self,
        session: Optional[SessionBase] = None,
        initial_values: Optional[Dict] = None,
    ):
        """Initialize the store with the given arguments."""
        super().__init__()
        self.__store = {}
        if session:
            in_session = session.get(PAYLOAD_SESSION_DICTIONARY)
            if in_session:
                self.__store = in_session

        if initial_values:
            self.__store.update(initial_values)
        if session:
            self.store_in_session(session) 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:19,代码来源:manage_session.py

示例2: get_user_from_session

# 需要导入模块: from django.contrib.sessions.backends import base [as 别名]
# 或者: from django.contrib.sessions.backends.base import SessionBase [as 别名]
def get_user_from_session(session: SessionBase) -> Union[User, AnonymousUser]:
    """
    Get User object (or AnonymousUser() if not logged in) from session.
    """
    try:
        user_id = session[SESSION_KEY]
        backend_path = session[BACKEND_SESSION_KEY]
        backend = load_backend(backend_path)
        return backend.get_user(user_id) or AnonymousUser()
    except KeyError:
        return AnonymousUser() 
开发者ID:django-cas-ng,项目名称:django-cas-ng,代码行数:13,代码来源:utils.py

示例3: generic

# 需要导入模块: from django.contrib.sessions.backends import base [as 别名]
# 或者: from django.contrib.sessions.backends.base import SessionBase [as 别名]
def generic(self, *args, **kwargs):
        request = super().generic(*args, **kwargs)
        request.session = SessionBase()
        request.user = self.user
        request._messages = default_storage(request)
        return request 
开发者ID:betagouv,项目名称:mrs,代码行数:8,代码来源:conftest.py

示例4: flush

# 需要导入模块: from django.contrib.sessions.backends import base [as 别名]
# 或者: from django.contrib.sessions.backends.base import SessionBase [as 别名]
def flush(cls, session: SessionBase):
        """Remove the table from the session."""
        session.pop(PAYLOAD_SESSION_DICTIONARY, None) 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:5,代码来源:manage_session.py

示例5: store_in_session

# 需要导入模块: from django.contrib.sessions.backends import base [as 别名]
# 或者: from django.contrib.sessions.backends.base import SessionBase [as 别名]
def store_in_session(self, session: SessionBase):
        """Set the payload in the current session.

        :param session: Session object
        """
        session[PAYLOAD_SESSION_DICTIONARY] = self.__store
        session.save() 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:9,代码来源:manage_session.py

示例6: create_and_send_zip

# 需要导入模块: from django.contrib.sessions.backends import base [as 别名]
# 或者: from django.contrib.sessions.backends.base import SessionBase [as 别名]
def create_and_send_zip(
    session: SessionBase,
    action: models.Action,
    item_column: models.Column,
    user_fname_column: Optional[models.Column],
    payload: SessionPayload,
) -> http.HttpResponse:
    """Process the list of tuples in files and create the ZIP BytesIO object.

    :param session: Session object while creating a zip (need it to flush it)
    :param action: Action being used for ZIP
    :param item_column: Column used to itemize the zip
    :param user_fname_column: Optional column to create file name
    :param payload: Dictionary with additional parameters to create the ZIP
    :return: HttpResponse to send back with the ZIP download header
    """
    files = _create_eval_data_tuple(
        action,
        item_column,
        payload.get('exclude_values', []),
        user_fname_column)
    file_name_template = _create_filename_template(payload, user_fname_column)

    # Create the ZIP and return it for download
    sbuf = BytesIO()
    zip_file_obj = zipfile.ZipFile(sbuf, 'w')
    for user_fname, part_id, msg_body in files:
        if payload['zip_for_moodle']:
            # If a zip for Moodle, field is Participant [number]. Take the
            # number only
            part_id = part_id.split()[1]

        zip_file_obj.writestr(
            file_name_template.format(user_fname=user_fname, part_id=part_id),
            str(msg_body),
        )
    zip_file_obj.close()

    SessionPayload.flush(session)

    suffix = datetime.now().strftime('%y%m%d_%H%M%S')
    # Attach the compressed value to the response and send
    compressed_content = sbuf.getvalue()
    response = http.HttpResponse(compressed_content)
    response['Content-Type'] = 'application/x-zip-compressed'
    response['Content-Transfer-Encoding'] = 'binary'
    response['Content-Disposition'] = (
        'attachment; filename="ontask_zip_action_{0}.zip"'.format(suffix))
    response['Content-Length'] = str(len(compressed_content))

    return response 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:53,代码来源:zip.py


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