summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-08-13 10:45:42 (GMT)
committerBenjamin Dauvergne <bdauvergne@entrouvert.com>2019-08-13 10:45:58 (GMT)
commit0a6ebe49a97a4b24f9c65e75c1c1bdbd22b59854 (patch)
treed0e9dc332cba08cfafbf269be8bdd952387ac9c5
parentd782655ff45bf6124d440d7a0a672528c2554367 (diff)
downloadcombo-wip/35384-envoyer-l-IP-du-client-dans-les-.zip
combo-wip/35384-envoyer-l-IP-du-client-dans-les-.tar.gz
combo-wip/35384-envoyer-l-IP-du-client-dans-les-.tar.bz2
wcs: pass ip of client to tracking-code API (#35384)wip/35384-envoyer-l-IP-du-client-dans-les-
-rw-r--r--combo/apps/wcs/views.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/combo/apps/wcs/views.py b/combo/apps/wcs/views.py
index 09d4660..59ece03 100644
--- a/combo/apps/wcs/views.py
+++ b/combo/apps/wcs/views.py
@@ -41,7 +41,7 @@ class TrackingCodeView(View):
return super(TrackingCodeView, self).dispatch(*args, **kwargs)
@classmethod
- def search(self, code, wcs_site=None):
+ def search(self, code, ip=None, wcs_site=None):
code = code.strip().upper()
if wcs_site:
wcs_sites = [get_wcs_services().get(wcs_site)]
@@ -49,8 +49,10 @@ class TrackingCodeView(View):
wcs_sites = get_wcs_services().values()
for wcs_site in wcs_sites:
- response = requests.get('/api/code/' + urlquote(code),
- remote_service=wcs_site, log_errors=False)
+ url = '/api/code/' + urlquote(code)
+ if ip:
+ url += '?ip=' + urlquote(ip)
+ response = requests.get(url, remote_service=wcs_site, log_errors=False)
if response.status_code == 200 and response.json().get('err') == 0:
return response.json().get('load_url')
@@ -65,7 +67,7 @@ class TrackingCodeView(View):
return HttpResponseBadRequest('Missing code')
code = request.POST['code']
- url = self.search(code, wcs_site=cell.wcs_site)
+ url = self.search(code, ip=request.META.get('REMOTE_ADDR'), wcs_site=cell.wcs_site)
if url:
return HttpResponseRedirect(url)
@@ -89,7 +91,7 @@ def tracking_code_search(request):
query = request.GET.get('q') or ''
query = query.strip().upper()
if re.match(r'^[BCDFGHJKLMNPQRSTVWXZ]{8}$', query):
- url = TrackingCodeView.search(query)
+ url = TrackingCodeView.search(query, ip=request.META.get('REMOTE_ADDR'))
if url:
hits.append({
'text': _('Use tracking code %s') % query,