Mercurial > public > sg101
comparison gpp/core/functions.py @ 227:423c39ee44e0
Rework the who's online middleware and template tag for #87.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 06 Jul 2010 03:02:20 +0000 |
parents | 500e5875a306 |
children | 27bee3ac85e6 |
comparison
equal
deleted
inserted
replaced
226:405468b8e3b9 | 227:423c39ee44e0 |
---|---|
1 """This file houses various core utility functions for GPP""" | 1 """This file houses various core utility functions for GPP""" |
2 import datetime | 2 import datetime |
3 import re | |
3 | 4 |
4 import django.core.mail | 5 import django.core.mail |
5 from django.contrib.sites.models import Site | 6 from django.contrib.sites.models import Site |
6 from django.conf import settings | 7 from django.conf import settings |
7 | 8 |
63 year_range = str(BASE_YEAR) | 64 year_range = str(BASE_YEAR) |
64 else: | 65 else: |
65 year_range = "%d - %d" % (BASE_YEAR, curr_year) | 66 year_range = "%d - %d" % (BASE_YEAR, curr_year) |
66 | 67 |
67 return 'Copyright (C) %s, SurfGuitar101.com' % year_range | 68 return 'Copyright (C) %s, SurfGuitar101.com' % year_range |
69 | |
70 | |
71 IP_PAT = re.compile('(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})') | |
72 | |
73 def get_ip(request): | |
74 """Returns the IP from the request or None if it cannot be retrieved.""" | |
75 ip = request.META.get('HTTP_X_FORWARDED_FOR', | |
76 request.META.get('REMOTE_ADDR')) | |
77 | |
78 if ip: | |
79 match = IP_PAT.match(ip) | |
80 ip = match.group(1) if match else None | |
81 | |
82 return ip |