File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ to the database.
6
6
Installation
7
7
------------
8
8
9
+ .. image :: https://travis-ci.org/ui/django-cached_authentication_middleware.png?branch=master
10
+
11
+
9
12
* Install via pypi::
10
13
11
14
pip install django-cached_authentication_middleware
@@ -32,6 +35,31 @@ Installation
32
35
33
36
And you're done!
34
37
38
+ Cached Auth Preprocessor
39
+ ------------------------
40
+
41
+ Sometimes you want to preprocess to ``User `` instance before storing
42
+ it into cache. ``cached_auth `` allows you to define
43
+ ``settings.CACHED_AUTH_PREPROCESSOR ``, a callable that takes two arguments, ``user `` & ``request `` and returns a ``User `` instance.
44
+
45
+ A classic example of this would be to attach ``Profile `` data
46
+ to ``User `` object so calling ``request.user.profile `` does not incur a
47
+ database hit. Here's how we can implement it.
48
+
49
+ ```python
50
+
51
+ def attach_profile(user, request):
52
+ try:
53
+ user.get_profile()
54
+ # Handle exception for user with no profile and AnonymousUser
55
+ except (Profile.DoesNotExist, AttributeError):
56
+ pass
57
+
58
+
59
+ # In settings.py:
60
+ CACHED_AUTH_PREPROCESSOR = 'path.to.module.attach_profile'
61
+ ` ``
62
+
35
63
Running Tests
36
64
-------------
37
65
@@ -46,6 +74,12 @@ To run the test suite with Django custom user (this will run only on Django 1.5)
46
74
Changelog
47
75
---------
48
76
77
+ Version 0.2.0
78
+ =============
79
+
80
+ * Added support for Django 1.5's customer user model
81
+ * Added ``CACHED_AUTH_PREPROCESSOR `` setting
82
+
49
83
Version 0.1.1
50
84
=============
51
85
You can’t perform that action at this time.
0 commit comments