from rowandale.apps.stats.models import PathHitCounter

class PathCounter(object):
    def process_response(self, request, response):
        """
        If the request was successful, update the hit counter for the
        path which was requested.
        """
        if response.status_code == 200 and \
           not request.path.startswith('/admin'):
            counter, created = PathHitCounter.objects.get_or_create(
                                   path=request.path, defaults={'hits': 0})
            counter.hits += 1
            counter.save()
        return response
