from at_django_boilerplate.utils.geolocation import get_ip_and_country


class CountryDetectionMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        ip, country,currency = get_ip_and_country(request)
        request.session['country'] = country
        request.session['currency'] = currency
        return self.get_response(request)
