Skip to content

Commit

Permalink
Merge pull request #175 from arXiv/develop
Browse files Browse the repository at this point in the history
Pre-release merge for browse v0.3.2.5
  • Loading branch information
mhl10 authored Jul 27, 2020
2 parents 1cc2f2d + 5970733 commit bb2b1c7
Show file tree
Hide file tree
Showing 20 changed files with 677 additions and 249 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jinja2 = "==2.10.1"
flask-s3 = "*"
arxiv-base = "==0.16.8"
retry = "==0.9.2"
geoip2 = "*"

[dev-packages]
pylama = "*"
Expand Down
353 changes: 195 additions & 158 deletions Pipfile.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions browse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import dateutil.parser
from datetime import datetime, timedelta

APP_VERSION = "0.3.2"
APP_VERSION = "0.3.2.5"
"""The application version """

ON = "yes"
Expand Down Expand Up @@ -341,8 +341,14 @@
TRACKBACK_SECRET = os.environ.get("TRACKBACK_SECRET", "baz")
"""Used in linking to trackbacks in /tb pages."""

LABS_BIBEXPLORER_ENABLED = os.environ.get("LABS_BIBEXPLORER_ENABLED", True)
"""arXiv Labs bibex enabled/disabled."""
LABS_ENABLED = bool(int(os.environ.get("LABS_ENABLED", "1")))
"""arXiv Labs global enable/disable."""

LABS_BIBEXPLORER_ENABLED = bool(int(os.environ.get("LABS_BIBEXPLORER_ENABLED", "1")))
"""arXiv Labs Bibliographic Explorer enable/disable."""

LABS_CORE_RECOMMENDER_ENABLED = bool(int(os.environ.get('LABS_CORE_RECOMMENDER_ENABLED', "0")))
"""CORE Recommender enabled/disabled."""

# Auth settings
AUTH_SESSION_COOKIE_NAME = "ARXIVNG_SESSION_ID"
Expand Down
35 changes: 30 additions & 5 deletions browse/routes/ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Provides the user intefaces for browse."""
import re
import geoip2.database

from datetime import datetime
from typing import Callable, Dict, Mapping, Union, Tuple, Any
from flask import Blueprint, render_template, request, Response, session, \
Expand All @@ -18,10 +20,21 @@
from browse.controllers.year import year_page

logger = logging.getLogger(__name__)
geoip_reader = None

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


@blueprint.before_app_first_request
def load_global_data() -> None:
"""Load global data."""
global geoip_reader
try:
geoip_reader = geoip2.database.Reader('data/GeoLite2-City.mmdb')
except Exception as ex:
logger.debug(f'problem loading geoip database: {ex}')


@blueprint.context_processor
def inject_now() -> Dict:
"""Inject current datetime into request context."""
Expand All @@ -31,6 +44,20 @@ def inject_now() -> Dict:
@blueprint.before_request
def before_request() -> None:
"""Get instituional affiliation from session."""
global geoip_reader
if geoip_reader and 'contintent' not in session:
session['continent'] = None
try:
response = geoip_reader.city(request.remote_addr)
logger.debug(f'continent {response.continent.code}')
session['continent'] = {
'code': response.continent.code,
'name': response.continent.names['en']
}

except Exception as ex:
logger.debug(f'problem getting match on IP: {ex}')

if 'institution' not in session:
logger.debug('Adding institution to session')
session['institution'] = get_institution(request.remote_addr)
Expand Down Expand Up @@ -91,11 +118,11 @@ def abstract(arxiv_id: str) -> Any:
mimetype='text/plain')
return render_template('abs/abs.html', **response), code, headers
elif code == status.HTTP_301_MOVED_PERMANENTLY:
return redirect(headers['Location'], code=code)
return redirect(headers['Location'], code=code)
elif code == status.HTTP_304_NOT_MODIFIED:
return '', code, headers
return '', code, headers

raise InternalServerError('Unexpected error')
raise InternalServerError('Unexpected error')

@blueprint.route('category_taxonomy', methods=['GET'])
def category_taxonomy() -> Any:
Expand Down Expand Up @@ -183,7 +210,6 @@ def clickthrough() -> Response:
def list_articles(context: str, subcontext: str) -> Response:
"""
List articles by context, month etc.
Context might be a context or an archive; Subcontext should be
'recent', 'new' or a string of format YYMM.
"""
Expand Down Expand Up @@ -340,7 +366,6 @@ def archive(archive: str): # type: ignore
def archive_with_extra(archive: str, junk: str): # type: ignore
"""
Archive page with extra, 301 redirect to just the archive.
This handles some odd URLs that have ended up in search engines.
See also ARXIVOPS-2119.
"""
Expand Down
1 change: 0 additions & 1 deletion browse/services/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def get_sequential_id(paper_id: Identifier,
context: str = 'all',
is_next: bool = True) -> Optional[str]:
"""Get the next or previous paper ID in sequence."""

if not isinstance(paper_id, Identifier) or not paper_id.month or not paper_id.year:
return None

Expand Down
Loading

0 comments on commit bb2b1c7

Please sign in to comment.