Configure PayPal integration and cart checkout error display
This commit is contained in:
1 parent
62065828e1
commit
cf07fc5d9b
98 files changed
+1430
-281
No files matched your search
+47
-9
@@ -45,20 +45,43 @@ def geo_reader(path):
|
||||
except maxminddb.InvalidDatabaseError as exc:
|
||||
raise ValueError('Invalid country database') from exc
|
||||
|
||||
def location_for(request):
|
||||
empty = {'country': '', 'region': '', 'city': ''}
|
||||
|
||||
def country_for(request):
|
||||
if not settings.SLX_GEOIP_DB:
|
||||
return ''
|
||||
header = 'HTTP_X_SLX_CLIENT_IP' if settings.SLX_TRUST_CADDY_IP else 'REMOTE_ADDR'
|
||||
return empty
|
||||
|
||||
header = (
|
||||
'HTTP_X_SLX_CLIENT_IP'
|
||||
if settings.SLX_TRUST_CADDY_IP
|
||||
else 'REMOTE_ADDR'
|
||||
)
|
||||
|
||||
try:
|
||||
ip = ipaddress.ip_address(request.META.get(header, ''))
|
||||
|
||||
if not ip.is_global:
|
||||
return ''
|
||||
return empty
|
||||
|
||||
row = geo_reader(settings.SLX_GEOIP_DB).get(str(ip)) or {}
|
||||
code = row.get('country', {}).get('iso_code', '')
|
||||
return code if re.fullmatch(r'[A-Z]{2}', code) else ''
|
||||
|
||||
country = row.get('country', {}).get('iso_code', '')
|
||||
subdivisions = row.get('subdivisions') or []
|
||||
|
||||
region = ''
|
||||
if subdivisions:
|
||||
region = subdivisions[0].get('names', {}).get('en', '')
|
||||
|
||||
city = row.get('city', {}).get('names', {}).get('en', '')
|
||||
|
||||
return {
|
||||
'country': country if re.fullmatch(r'[A-Z]{2}', country) else '',
|
||||
'region': region[:120],
|
||||
'city': city[:120],
|
||||
}
|
||||
|
||||
except (ValueError, OSError, ImportError, RuntimeError):
|
||||
return ''
|
||||
return empty
|
||||
|
||||
|
||||
def view_total(kind, ident):
|
||||
@@ -86,12 +109,27 @@ class TrafficMiddleware:
|
||||
or any('prefetch' in request.META.get(header, '').lower() for header in ('HTTP_SEC_PURPOSE', 'HTTP_PURPOSE'))
|
||||
or not request.META.get('HTTP_USER_AGENT') or BOT.search(request.META['HTTP_USER_AGENT'])):
|
||||
return response
|
||||
|
||||
kind, target = getattr(request, 'slx_view_target', ('site', 0))
|
||||
|
||||
try:
|
||||
row, created = TrafficDaily.objects.get_or_create(day=timezone.localdate(), kind=kind, target_id=target,
|
||||
route=match.url_name, country=country_for(request), source=source_origin(request))
|
||||
location = location_for(request)
|
||||
|
||||
row, created = TrafficDaily.objects.get_or_create(
|
||||
day=timezone.localdate(),
|
||||
kind=kind,
|
||||
target_id=target,
|
||||
route=match.url_name,
|
||||
country=location['country'],
|
||||
region=location['region'],
|
||||
city=location['city'],
|
||||
source=source_origin(request),
|
||||
)
|
||||
|
||||
if not created:
|
||||
TrafficDaily.objects.filter(pk=row.pk).update(views=F('views') + 1)
|
||||
|
||||
except DatabaseError:
|
||||
logger.warning('SLX traffic could not be recorded.')
|
||||
|
||||
return response
|
||||
Reference in new issue
Block a user