Add comments and additional docstrings to some functions on events module.
parent
4acb59e3cf
commit
c8bacee06c
|
@ -3,6 +3,8 @@ import json
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from . import backends
|
from . import backends
|
||||||
|
|
||||||
|
# The complete list of content types
|
||||||
|
# of allowed models for change events
|
||||||
watched_types = (
|
watched_types = (
|
||||||
("userstories", "userstory"),
|
("userstories", "userstory"),
|
||||||
("issues", "issue"),
|
("issues", "issue"),
|
||||||
|
@ -10,6 +12,9 @@ watched_types = (
|
||||||
|
|
||||||
|
|
||||||
def _get_type_for_model(model_instance):
|
def _get_type_for_model(model_instance):
|
||||||
|
"""
|
||||||
|
Get content type tuple from model instance.
|
||||||
|
"""
|
||||||
ct = ContentType.objects.get_for_model(model_instance)
|
ct = ContentType.objects.get_for_model(model_instance)
|
||||||
return (ct.app_label, ct.model)
|
return (ct.app_label, ct.model)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,17 @@ import threading
|
||||||
_local = threading.local()
|
_local = threading.local()
|
||||||
_local.session_id = None
|
_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
|
global _local
|
||||||
if not hasattr(_local, "session_id"):
|
if not hasattr(_local, "session_id"):
|
||||||
raise RuntimeException("No session identifier is found, "
|
raise RuntimeException("No session identifier is found, "
|
||||||
|
@ -18,6 +28,7 @@ class SessionIDMiddleware(object):
|
||||||
identifier to thread local storage (that only avaliable for
|
identifier to thread local storage (that only avaliable for
|
||||||
current thread).
|
current thread).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
global _local
|
global _local
|
||||||
session_id = request.META.get("HTTP_X_SESSION_ID", None)
|
session_id = request.META.get("HTTP_X_SESSION_ID", None)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
from django.db.models import signals
|
from django.db.models import signals
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue