Skip to content

Commit bb2b1c7

Browse files
authored
Merge pull request #175 from arXiv/develop
Pre-release merge for browse v0.3.2.5
2 parents 1cc2f2d + 5970733 commit bb2b1c7

File tree

20 files changed

+677
-249
lines changed

20 files changed

+677
-249
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jinja2 = "==2.10.1"
2424
flask-s3 = "*"
2525
arxiv-base = "==0.16.8"
2626
retry = "==0.9.2"
27+
geoip2 = "*"
2728

2829
[dev-packages]
2930
pylama = "*"

Pipfile.lock

Lines changed: 195 additions & 158 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browse/config.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import dateutil.parser
99
from datetime import datetime, timedelta
1010

11-
APP_VERSION = "0.3.2"
11+
APP_VERSION = "0.3.2.5"
1212
"""The application version """
1313

1414
ON = "yes"
@@ -341,8 +341,14 @@
341341
TRACKBACK_SECRET = os.environ.get("TRACKBACK_SECRET", "baz")
342342
"""Used in linking to trackbacks in /tb pages."""
343343

344-
LABS_BIBEXPLORER_ENABLED = os.environ.get("LABS_BIBEXPLORER_ENABLED", True)
345-
"""arXiv Labs bibex enabled/disabled."""
344+
LABS_ENABLED = bool(int(os.environ.get("LABS_ENABLED", "1")))
345+
"""arXiv Labs global enable/disable."""
346+
347+
LABS_BIBEXPLORER_ENABLED = bool(int(os.environ.get("LABS_BIBEXPLORER_ENABLED", "1")))
348+
"""arXiv Labs Bibliographic Explorer enable/disable."""
349+
350+
LABS_CORE_RECOMMENDER_ENABLED = bool(int(os.environ.get('LABS_CORE_RECOMMENDER_ENABLED', "0")))
351+
"""CORE Recommender enabled/disabled."""
346352

347353
# Auth settings
348354
AUTH_SESSION_COOKIE_NAME = "ARXIVNG_SESSION_ID"

browse/routes/ui.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Provides the user intefaces for browse."""
22
import re
3+
import geoip2.database
4+
35
from datetime import datetime
46
from typing import Callable, Dict, Mapping, Union, Tuple, Any
57
from flask import Blueprint, render_template, request, Response, session, \
@@ -18,10 +20,21 @@
1820
from browse.controllers.year import year_page
1921

2022
logger = logging.getLogger(__name__)
23+
geoip_reader = None
2124

2225
blueprint = Blueprint('browse', __name__, url_prefix='/')
2326

2427

28+
@blueprint.before_app_first_request
29+
def load_global_data() -> None:
30+
"""Load global data."""
31+
global geoip_reader
32+
try:
33+
geoip_reader = geoip2.database.Reader('data/GeoLite2-City.mmdb')
34+
except Exception as ex:
35+
logger.debug(f'problem loading geoip database: {ex}')
36+
37+
2538
@blueprint.context_processor
2639
def inject_now() -> Dict:
2740
"""Inject current datetime into request context."""
@@ -31,6 +44,20 @@ def inject_now() -> Dict:
3144
@blueprint.before_request
3245
def before_request() -> None:
3346
"""Get instituional affiliation from session."""
47+
global geoip_reader
48+
if geoip_reader and 'contintent' not in session:
49+
session['continent'] = None
50+
try:
51+
response = geoip_reader.city(request.remote_addr)
52+
logger.debug(f'continent {response.continent.code}')
53+
session['continent'] = {
54+
'code': response.continent.code,
55+
'name': response.continent.names['en']
56+
}
57+
58+
except Exception as ex:
59+
logger.debug(f'problem getting match on IP: {ex}')
60+
3461
if 'institution' not in session:
3562
logger.debug('Adding institution to session')
3663
session['institution'] = get_institution(request.remote_addr)
@@ -91,11 +118,11 @@ def abstract(arxiv_id: str) -> Any:
91118
mimetype='text/plain')
92119
return render_template('abs/abs.html', **response), code, headers
93120
elif code == status.HTTP_301_MOVED_PERMANENTLY:
94-
return redirect(headers['Location'], code=code)
121+
return redirect(headers['Location'], code=code)
95122
elif code == status.HTTP_304_NOT_MODIFIED:
96-
return '', code, headers
123+
return '', code, headers
97124

98-
raise InternalServerError('Unexpected error')
125+
raise InternalServerError('Unexpected error')
99126

100127
@blueprint.route('category_taxonomy', methods=['GET'])
101128
def category_taxonomy() -> Any:
@@ -183,7 +210,6 @@ def clickthrough() -> Response:
183210
def list_articles(context: str, subcontext: str) -> Response:
184211
"""
185212
List articles by context, month etc.
186-
187213
Context might be a context or an archive; Subcontext should be
188214
'recent', 'new' or a string of format YYMM.
189215
"""
@@ -340,7 +366,6 @@ def archive(archive: str): # type: ignore
340366
def archive_with_extra(archive: str, junk: str): # type: ignore
341367
"""
342368
Archive page with extra, 301 redirect to just the archive.
343-
344369
This handles some odd URLs that have ended up in search engines.
345370
See also ARXIVOPS-2119.
346371
"""

browse/services/database/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ def get_sequential_id(paper_id: Identifier,
241241
context: str = 'all',
242242
is_next: bool = True) -> Optional[str]:
243243
"""Get the next or previous paper ID in sequence."""
244-
245244
if not isinstance(paper_id, Identifier) or not paper_id.month or not paper_id.year:
246245
return None
247246

0 commit comments

Comments
 (0)