Skip to content

Commit

Permalink
Merge branch 'bkeating-master' into develop
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bashu committed Sep 19, 2015
2 parents 09a7474 + 82f7095 commit aec31a9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions tracking/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from django.contrib.auth.models import AnonymousUser
from django.core.cache import cache
from django.core.urlresolvers import reverse, NoReverseMatch
from django.db.utils import DatabaseError
from django.db.utils import DatabaseError, IntegrityError
from django.http import Http404
from django.utils import timezone
from django.db import transaction

from tracking import utils
from tracking.models import Visitor, UntrackedUserAgent, BannedIP
Expand Down Expand Up @@ -143,7 +143,11 @@ def process_request(self, request):
visitor.page_views += 1
visitor.last_update = now
try:
sid = transaction.savepoint()
visitor.save()
transaction.savepoint_commit(sid)
except IntegrityError:
transaction.savepoint_rollback(sid)
except DatabaseError:
log.error('There was a problem saving visitor information:\n%s\n\n%s' % (traceback.format_exc(), locals()))

Expand Down
4 changes: 2 additions & 2 deletions tracking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def active(self, timeout=None):
now = timezone.now()
cutoff = now - timedelta(minutes=timeout)

return self.get_query_set().filter(last_update__gte=cutoff)
return self.get_queryset().filter(last_update__gte=cutoff)

class Visitor(models.Model):
session_key = models.CharField(max_length=40)
Expand Down Expand Up @@ -128,7 +128,7 @@ class Meta:
verbose_name_plural = _('Untracked User-Agents')

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

def __unicode__(self):
return self.ip_address
Expand Down

0 comments on commit aec31a9

Please sign in to comment.