Skip to content

Commit

Permalink
Merge pull request #85 from arXiv/user-banner-improvements
Browse files Browse the repository at this point in the history
Support date range config/logic for displaying user banner
  • Loading branch information
mhl10 authored Apr 18, 2019
2 parents 2915840 + 5c86e58 commit 525f8b6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
17 changes: 17 additions & 0 deletions browse/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""
import os
import warnings
import dateutil.parser
from datetime import datetime, timedelta

VERSION = '0.2.1'
"""The application version """
Expand Down Expand Up @@ -269,6 +271,21 @@
BROWSE_USER_BANNER_ENABLED = os.environ.get(
'BROWSE_USER_BANNER_ENABLED', False)
"""Enable/disable user banner."""
try:
BROWSE_USER_BANNER_START_DATE = dateutil.parser.parse(
os.environ.get('BROWSE_USER_BANNER_START_DATE')
).replace(hour=0, minute=0, second=0)
except Exception:
warnings.warn("Bad value for BROWSE_USER_BANNER_START_DATE")
BROWSE_USER_BANNER_START_DATE = datetime.now() - timedelta(days=1)

try:
BROWSE_USER_BANNER_END_DATE = dateutil.parser.parse(
os.environ.get('BROWSE_USER_BANNER_END_DATE')
).replace(hour=23, minute=59, second=59)
except Exception:
warnings.warn("Bad value for BROWSE_USER_BANNER_END_DATE")
BROWSE_USER_BANNER_END_DATE = datetime.now() + timedelta(days=1)

DOCUMENT_LATEST_VERSIONS_PATH = os.environ.get(
'DOCUMENT_LATEST_VERSIONS_PATH', 'tests/data/abs_files/ftp')
Expand Down
6 changes: 6 additions & 0 deletions browse/routes/ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Provides the user intefaces for browse."""
import re
from datetime import datetime
from typing import Callable, Dict, Mapping, Union
from flask import Blueprint, render_template, request, Response, session, \
current_app, url_for, redirect
Expand All @@ -20,6 +21,11 @@
blueprint = Blueprint('browse', __name__, url_prefix='/')


@blueprint.context_processor
def inject_now() -> None:
return dict(request_datetime=datetime.now())


@blueprint.before_request
def before_request() -> None:
"""Get instituional affiliation from session."""
Expand Down
2 changes: 1 addition & 1 deletion browse/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<!-- End Matomo Code -->
{% endif -%}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
{% if config['BROWSE_USER_BANNER_ENABLED'] %}
{% if config['BROWSE_USER_BANNER_ENABLED'] and (config['BROWSE_USER_BANNER_START_DATE'] < request_datetime) and (config['BROWSE_USER_BANNER_END_DATE'] > request_datetime) %}
<link rel="stylesheet" type="text/css" media="screen" href="//static.arxiv.org/css/slider.css?v=1.1" />
<script language="javascript" src="//code.jquery.com/jquery-latest.min.js"></script>
<script language="javascript" src="//static.arxiv.org/js/donate.js"></script>
Expand Down

0 comments on commit 525f8b6

Please sign in to comment.