Created
January 26, 2011 04:13
-
-
Save johnboxall/796216 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from django.core.exceptions import ObjectDoesNotExist | |
| class InfoMiddleware(object): | |
| ''' | |
| Record refer and user-agent info about this dude. | |
| ''' | |
| def process_request(self, request): | |
| if request.user.is_anonymous(): | |
| if 'referer' not in request.session: | |
| request.session['referer'] = request.META.get('HTTP_REFERER') | |
| elif 'user_agent' not in request.session: | |
| user_agent = request.META.get('HTTP_USER_AGENT') | |
| try: | |
| profile = request.user.get_profile() | |
| except ObjectDoesNotExist: | |
| pass | |
| else: | |
| if profile.settings.get('user_agent') != user_agent: | |
| profile.settings['user_agent'] = user_agent | |
| profile.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment