-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
352 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
Change Log | ||
---------- | ||
|
||
DEV | ||
~~~ | ||
|
||
* Added support for regions | ||
|
||
2.1.0 | ||
~~~~~ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Initial regions | ||
|
||
- model: account.Region | ||
pk: 1 | ||
fields: | ||
name: Default region |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from threading import current_thread | ||
|
||
from django.conf import settings | ||
|
||
from ralph.account.models import Region | ||
|
||
|
||
_requests = {} | ||
|
||
|
||
def get_actual_regions(): | ||
thread_name = current_thread().name | ||
if thread_name not in _requests: | ||
return Region.objects.filter( | ||
name=settings.DEFAULT_REGION_NAME, | ||
) | ||
return _requests[thread_name]['regions'] | ||
|
||
|
||
class RegionMiddleware(object): | ||
def process_request(self, request): | ||
if hasattr(request, 'user') and not request.user.is_anonymous(): | ||
data = { | ||
'user_id': request.user.id, | ||
'regions': request.user.profile.get_regions(), | ||
} | ||
_requests[current_thread().name] = data | ||
|
||
def process_response(self, request, response): | ||
if hasattr(request, 'user') and not request.user.is_anonymous(): | ||
_requests.pop(current_thread().name, None) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters