Skip to content

Commit aec31a9

Browse files
committed
Merge branch 'bkeating-master' into develop
* bkeating-master: Removed rogue character ``IPAddressField`` is now ``GenericIPAddressField`` ``get_query_set`` is now ``get_queryset`` packet name change version bump pip install update rollback & safe point added missing import added catch Integrity exception added
2 parents 09a7474 + 82f7095 commit aec31a9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tracking/middleware.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from django.contrib.auth.models import AnonymousUser
99
from django.core.cache import cache
1010
from django.core.urlresolvers import reverse, NoReverseMatch
11-
from django.db.utils import DatabaseError
11+
from django.db.utils import DatabaseError, IntegrityError
1212
from django.http import Http404
13-
from django.utils import timezone
13+
from django.db import transaction
1414

1515
from tracking import utils
1616
from tracking.models import Visitor, UntrackedUserAgent, BannedIP
@@ -143,7 +143,11 @@ def process_request(self, request):
143143
visitor.page_views += 1
144144
visitor.last_update = now
145145
try:
146+
sid = transaction.savepoint()
146147
visitor.save()
148+
transaction.savepoint_commit(sid)
149+
except IntegrityError:
150+
transaction.savepoint_rollback(sid)
147151
except DatabaseError:
148152
log.error('There was a problem saving visitor information:\n%s\n\n%s' % (traceback.format_exc(), locals()))
149153

tracking/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def active(self, timeout=None):
3131
now = timezone.now()
3232
cutoff = now - timedelta(minutes=timeout)
3333

34-
return self.get_query_set().filter(last_update__gte=cutoff)
34+
return self.get_queryset().filter(last_update__gte=cutoff)
3535

3636
class Visitor(models.Model):
3737
session_key = models.CharField(max_length=40)
@@ -128,7 +128,7 @@ class Meta:
128128
verbose_name_plural = _('Untracked User-Agents')
129129

130130
class BannedIP(models.Model):
131-
ip_address = models.IPAddressField('IP Address', help_text=_('The IP address that should be banned'))
131+
ip_address = models.GenericIPAddressField('IP Address', help_text=_('The IP address that should be banned'))
132132

133133
def __unicode__(self):
134134
return self.ip_address

0 commit comments

Comments
 (0)