old_contents: import logging
  
  from django.conf import settings
  from django.contrib.sites import models as sites
  from django.utils.translation import get_language
  from django_countries.fields import Country
  
  from . import analytics
  from ..discount.models import Sale
  from .utils import get_client_ip, get_country_by_ip, get_currency_for_country
  
  logger = logging.getLogger(__name__)
  
  
  class GoogleAnalytics(object):
      def process_request(self, request):
          client_id = analytics.get_client_id(request)
          path = request.path
          language = get_language()
          headers = request.META
          # FIXME: on production you might want to run this in background
          try:
              analytics.report_view(client_id, path=path, language=language,
                                    headers=headers)
          except Exception:
              logger.exception('Unable to update analytics')
  
  
  class DiscountMiddleware(object):
      def process_request(self, request):
          discounts = Sale.objects.all()
          discounts = discounts.prefetch_related('products', 'categories')
          request.discounts = discounts
  
  
  class CountryMiddleware(object):
  
      def process_request(self, request):
          client_ip = get_client_ip(request)
          if client_ip:
              request.country = get_country_by_ip(client_ip)
          if not request.country:
              request.country = Country(settings.DEFAULT_COUNTRY)
  
  
  class CurrencyMiddleware(object):
  
      def process_request(self, request):
          if hasattr(request, 'country') and request.country is not None:
              request.currency = get_currency_for_country(request.country)
          else:
              request.currency = settings.DEFAULT_CURRENCY
  
  
  class ClearSiteCacheMiddleware(object):
      def process_request(self, request):
          # print 'cache cleared'
          sm = sites.SiteManager()
          sm.clear_cache()
  
  
new_contents: import logging
  
  from django.conf import settings
  from django.contrib.sites import models as sites
  from django.utils.translation import get_language
  from django_countries.fields import Country
  
  from . import analytics
  from ..discount.models import Sale
  from .utils import get_client_ip, get_country_by_ip, get_currency_for_country
  
  logger = logging.getLogger(__name__)
  
  
  class GoogleAnalytics(object):
      def process_request(self, request):
          client_id = analytics.get_client_id(request)
          path = request.path
          language = get_language()
          headers = request.META
          # FIXME: on production you might want to run this in background
          try:
              analytics.report_view(client_id, path=path, language=language,
                                    headers=headers)
          except Exception:
              logger.exception('Unable to update analytics')
  
  
  class DiscountMiddleware(object):
      def process_request(self, request):
          discounts = Sale.objects.all()
          discounts = discounts.prefetch_related('products', 'categories')
          request.discounts = discounts
  
  
  class CountryMiddleware(object):
  
      def process_request(self, request):
          client_ip = get_client_ip(request)
          if client_ip:
              request.country = get_country_by_ip(client_ip)
          if not request.country:
              request.country = Country(settings.DEFAULT_COUNTRY)
  
  
  class CurrencyMiddleware(object):
  
      def process_request(self, request):
          if hasattr(request, 'country') and request.country is not None:
              request.currency = get_currency_for_country(request.country)
          else:
              request.currency = settings.DEFAULT_CURRENCY
  
  
  class ClearSiteCacheMiddleware(object):
      def process_request(self, request):
          # print 'cache cleared'
          sm = sites.SiteManager()
          sm.clear_cache()
  
subject: Fix pep8