Skip to content

Commit

Permalink
Merge pull request #8 from golnazads/master
Browse files Browse the repository at this point in the history
preventing flask to add the domain name to the redirect url
  • Loading branch information
golnazads authored Apr 6, 2018
2 parents 57bee66 + a4323ea commit 9323acd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions resolverway/templates/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>NASA/ADS Search (Beta Interface)</title>
<title>NASA/ADS Search</title>
</head>
<body>
<div class="header-container">
<h3><A HREF="https://ui.adsabs.harvard.edu">NASA/ADS Search</a> (Beta Interface)</h3>
<h3><A HREF="{{ url }}">NASA/ADS Search</a></h3>
<hr>
</div>
<div class="main-container">
Expand Down
2 changes: 1 addition & 1 deletion resolverway/tests/unittests/stubdata/data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

html_data = '''<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>NASA/ADS Search (Beta Interface)</title>\n</head>\n<body>\n <div class="header-container">\n <h3><A HREF="https://ui.adsabs.harvard.edu">NASA/ADS Search</a> (Beta Interface)</h3>\n <hr>\n </div>\n <div class="main-container">\n \n <h3> links for <b>1987gady.book.....B</b></h3>\n <dl>\n \n <dt><a href="http://arxiv.org/abs/1307.6556">http://arxiv.org/abs/1307.6556</a></dt>\n \n <br>\n \n <dt><a href="http://arxiv.org/pdf/1307.6556">http://arxiv.org/pdf/1307.6556</a></dt>\n \n <br>\n \n <dt><a href="http://dx.doi.org/10.1093%2Fmnras%2Fstt1379">http://dx.doi.org/10.1093%2Fmnras%2Fstt1379</a></dt>\n \n <br>\n \n <dt><a href="http://mnras.oxfordjournals.org/content/435/3/1904.full.pdf">http://mnras.oxfordjournals.org/content/435/3/1904.full.pdf</a></dt>\n \n <br>\n \n </dl>\n \n </div>\n <div class="footer-container">\n </div>\n</body>\n</html>\n'''
html_data = '''<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <title>NASA/ADS Search</title>\n</head>\n<body>\n <div class="header-container">\n <h3><A HREF="">NASA/ADS Search</a></h3>\n <hr>\n </div>\n <div class="main-container">\n \n <h3> links for <b>1987gady.book.....B</b></h3>\n <dl>\n \n <dt><a href="http://arxiv.org/abs/1307.6556">http://arxiv.org/abs/1307.6556</a></dt>\n \n <br>\n \n <dt><a href="http://arxiv.org/pdf/1307.6556">http://arxiv.org/pdf/1307.6556</a></dt>\n \n <br>\n \n <dt><a href="http://dx.doi.org/10.1093%2Fmnras%2Fstt1379">http://dx.doi.org/10.1093%2Fmnras%2Fstt1379</a></dt>\n \n <br>\n \n <dt><a href="http://mnras.oxfordjournals.org/content/435/3/1904.full.pdf">http://mnras.oxfordjournals.org/content/435/3/1904.full.pdf</a></dt>\n \n <br>\n \n </dl>\n \n </div>\n <div class="footer-container">\n </div>\n</body>\n</html>\n'''
10 changes: 7 additions & 3 deletions resolverway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self, bibcode, link_type, url):
self.access_token = None
self.referrer = None

def redirect(self, link):
response = redirect(link, 302)
response.autocorrect_location_header = False
return response, 302

def process_resolver_response(self, the_json_response):
action = the_json_response.get('action', '')
Expand All @@ -38,7 +42,7 @@ def process_resolver_response(self, the_json_response):
if link:
current_app.logger.info('redirecting to %s' %(link))
log_request(self.bibcode, self.username, self.link_type, link, self.referrer, self.client_id, self.access_token)
return redirect(link, 302), 302
return self.redirect(link)

# when action is to display, there are more than one link, so render template to display links
if (action == 'display'):
Expand All @@ -48,7 +52,7 @@ def process_resolver_response(self, the_json_response):
if records:
current_app.logger.debug('rendering template with data %s' %(records))
log_request(self.bibcode, self.username, self.link_type, self.url, self.referrer, self.client_id, self.access_token)
return render_template('list.html', link_type=self.link_type.title(),
return render_template('list.html', url="", link_type=self.link_type.title(),
links=records, bibcode=self.bibcode), 200

# if we get here there is an error, so display error template
Expand Down Expand Up @@ -77,7 +81,7 @@ def process_request(self):
if (self.url != None):
current_app.logger.debug('received to redirect to %s' %(self.url))
log_request(self.bibcode, self.username, self.link_type, self.url, self.referrer, self.client_id, self.access_token)
return redirect(self.url, 302), 302
return self.redirect(self.url)

try:
# if no url then send request to resolver_service to get link(s)
Expand Down

0 comments on commit 9323acd

Please sign in to comment.