From c8bacee06c6920b7d1565fd1e7ccea1252fcdf1a Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 24 Mar 2014 22:31:11 +0100 Subject: [PATCH] Add comments and additional docstrings to some functions on events module. --- taiga/events/changes.py | 5 +++++ taiga/events/middleware.py | 13 ++++++++++++- taiga/events/models.py | 1 - 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/taiga/events/changes.py b/taiga/events/changes.py index 71a80547..77eba96b 100644 --- a/taiga/events/changes.py +++ b/taiga/events/changes.py @@ -3,6 +3,8 @@ import json from django.contrib.contenttypes.models import ContentType from . import backends +# The complete list of content types +# of allowed models for change events watched_types = ( ("userstories", "userstory"), ("issues", "issue"), @@ -10,6 +12,9 @@ watched_types = ( def _get_type_for_model(model_instance): + """ + Get content type tuple from model instance. + """ ct = ContentType.objects.get_for_model(model_instance) return (ct.app_label, ct.model) diff --git a/taiga/events/middleware.py b/taiga/events/middleware.py index 6e28721e..ebd62624 100644 --- a/taiga/events/middleware.py +++ b/taiga/events/middleware.py @@ -3,7 +3,17 @@ import threading _local = threading.local() _local.session_id = None -def get_current_session_id(): + +def get_current_session_id() -> str: + """ + Get current session id for current + request. + + This function should be used only whithin + request context. Out of request context + it always return None + """ + global _local if not hasattr(_local, "session_id"): raise RuntimeException("No session identifier is found, " @@ -18,6 +28,7 @@ class SessionIDMiddleware(object): identifier to thread local storage (that only avaliable for current thread). """ + def process_request(self, request): global _local session_id = request.META.get("HTTP_X_SESSION_ID", None) diff --git a/taiga/events/models.py b/taiga/events/models.py index 93f19179..80d569d7 100644 --- a/taiga/events/models.py +++ b/taiga/events/models.py @@ -1,4 +1,3 @@ - from django.db.models import signals from django.dispatch import receiver