Skip to content

Commit

Permalink
Merge pull request #65 from cul-it/develop
Browse files Browse the repository at this point in the history
arxiv.base v0.9.1
  • Loading branch information
erickpeirson authored Jul 18, 2018
2 parents b046ad7 + c48df33 commit ca5251e
Show file tree
Hide file tree
Showing 16 changed files with 609 additions and 257 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ pytz = "*"
uwsgi = "*"
pydocstyle = "*"
"boto3" = "*"
wtforms = "*"

[dev-packages]
58 changes: 34 additions & 24 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 5 additions & 16 deletions arxiv/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,14 @@ def create_web_app() -> Flask:
"""

from typing import Optional
from flask import Blueprint, Flask
from typing import Optional, Any, Dict
from flask import Blueprint, Flask, Blueprint
from werkzeug.exceptions import NotFound

from arxiv.base.context_processors import config_url_builder
from arxiv.base import exceptions, urls, config
from arxiv.base.converter import ArXivConverter


def placeholder(*args, **kwargs):
"""Placeholder route for external endpoints."""
raise NotFound("This endpoint is not provided by this service.")


class Base(object):
"""Attaches a base UI blueprint and context processors to an app."""

Expand All @@ -63,15 +57,10 @@ def init_app(self, app: Flask) -> None:
)
app.register_blueprint(blueprint)

# Register base context processors (e.g. to inject global URLs).
app.context_processor(config_url_builder)

# Register base exception handlers.
for error, handler in exceptions.get_handlers():
app.errorhandler(error)(handler)

# Register URLs for other services. This allows us to use flask's
# ``url_for()`` function to generate URLs for services that are
# deployed at the same hostname.
for name, pattern in config.ARXIV_URLS:
app.add_url_rule(pattern, name, placeholder)
# Attach the external URL handler as a fallback for failed calls to
# url_for().
app.url_build_error_handlers.append(urls.external_url_handler)
80 changes: 46 additions & 34 deletions arxiv/base/config.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,58 @@
"""Flask configuration."""

from typing import Optional
import os
from urllib.parse import urlparse

SERVER_NAME = None

EXTERNAL_URLS = [
("twitter", os.environ.get("ARXIV_TWITTER_URL",
"https://twitter.com/arxiv")),
("blog", os.environ.get("ARXIV_BLOG_URL",
"https://blogs.cornell.edu/arxiv/")),
("wiki", os.environ.get("ARXIV_WIKI_URL",
"https://confluence.cornell.edu/display/arxivpub/"
"arXiv+Public+Wiki")),
("accessibility", os.environ.get("ARXIV_ACCESSIBILITY_URL",
"mailto:[email protected]")),
("library", os.environ.get("ARXIV_LIBRARY_URL",
"https://library.cornell.edu")),
("acknowledgment", os.environ.get(
"ARXIV_ACKNOWLEDGEMENT_URL",
"https://confluence.cornell.edu/x/ALlRF"
)),
]
"""External URLs, configurable via environment variables."""

ARXIV_URLS = [
("help", "/help"),
("contact", "/help/contact"),
("search_box", "/search"),
("search_advanced", "/search/advanced"),
("account", "/user"),
("login", "/user/login"),
("logout", "/user/logout"),
("home", "/"),
("pdf", "/pdf/<arxiv:paper_id>"),
A11Y_URL = os.environ.get("ARXIV_ACCESSIBILITY_URL",
"mailto:[email protected]")

BASE_SERVER = os.environ.get('BASE_SERVER', 'arxiv.org')

URLS = [
("help", "/help", BASE_SERVER),
("help_identifier", "/help/arxiv_identifier", BASE_SERVER),
("help_trackback", "/help/trackback", BASE_SERVER),
("help_mathjax", "/help/mathjax", BASE_SERVER),
("help_social_bookmarking", "/help/social_bookmarking", BASE_SERVER),
("contact", "/help/contact", BASE_SERVER),
("search_box", "/search", BASE_SERVER),
("search_advanced", "/search/advanced", BASE_SERVER),
("account", "/user", BASE_SERVER),
("login", "/user/login", BASE_SERVER),
("logout", "/user/logout", BASE_SERVER),
("home", "/", BASE_SERVER),
("ignore_me", "/IgnoreMe", BASE_SERVER), # Anti-robot honneypot.
("pdf", "/pdf/<arxiv:paper_id>", BASE_SERVER),
("twitter", "/arxiv", "twitter.com"),
("blog", "/arxiv", "blogs.cornell.edu"),
("wiki", "/display/arxivpub/arXiv+Public+Wiki", "confluence.cornell.edu"),
("library", "/", "library.cornell.edu"),
("acknowledgment", "/x/ALlRF", "confluence.cornell.edu")
]
"""
URLs for other services, for use with :func:`flask.url_for`.
URLs for external services, for use with :func:`flask.url_for`.
This only works for services at the same hostname, since Flask uses the
hostname on the request to generate the full URL. For addresses at a different
hostname, use :func:`arxiv.base.urls.config_url`, which relies on
``EXTERNAL_URLS`` in this configuration file.
For details, see :mod:`arxiv.base.urls`.
"""

# In order to provide something close to the config_url behavior, this will
# look for ARXIV_{endpoint}_URL variables in the environ, and update `URLS`
# accordingly.
for key, value in os.environ.items():
if key.startswith('ARXIV_') and key.endswith('_URL'):
endpoint = "_".join(key.split('_')[1:-1]).lower()
o = urlparse(value)
if not o.netloc: # Doesn't raise an exception.
continue
i: Optional[int]
try:
i = list(zip(*URLS))[0].index(endpoint)
except ValueError:
i = None
if i is not None:
URLS[i] = (endpoint, o.path, o.netloc)

ARXIV_BUSINESS_TZ = os.environ.get("ARXIV_BUSINESS_TZ", "US/Eastern")
9 changes: 0 additions & 9 deletions arxiv/base/context_processors.py

This file was deleted.

8 changes: 4 additions & 4 deletions arxiv/base/templates/base/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
<div class="column">
<ul class="nav-spaced">
<li><a href="{{ url_for('contact') }}">Contact</a></li>
<li><a href="{{ config_url('twitter') }}">Find us on Twitter</a></li>
<li><a href="{{ url_for('twitter') }}">Find us on Twitter</a></li>
</ul>
</div>
<div class="column">
<ul class="nav-spaced">
<li><a href="{{ config_url('blog') }}">Blog - the latest news</a></li>
<li><a href="{{ config_url('wiki') }}">Wiki - project documentation</a></li>
<li><a href="{{ url_for('blog') }}">Blog - the latest news</a></li>
<li><a href="{{ url_for('wiki') }}">Wiki - project documentation</a></li>
</ul>
</div>
<div class="column">
<ul class="nav-spaced">
<li><a href="{{ config_url('accessibility') }}">Web Accessibility Help</a></li>
<li><a href="{{ config.A11Y_URL }}">Web Accessibility Help</a></li>
<li><a href="{{ url_for('help') }}">Help with using arXiv</a></li>
</ul>
</div>
Expand Down
6 changes: 3 additions & 3 deletions arxiv/base/templates/base/header.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!-- contains Cornell logo and sponsor statement -->
<div class="attribution level is-marginless" role="banner">
<div class="level-left">
<a class="level-item" href="{{ config_url('library') }}"><img src="{{ url_for('base.static', filename='images/CUL-reduced-white-SMALL.svg') }}" alt="Cornell University Library" width="300" aria-label="logo" /></a>
<a class="level-item" href="{{ url_for('library') }}"><img src="{{ url_for('base.static', filename='images/CUL-reduced-white-SMALL.svg') }}" alt="Cornell University Library" width="300" aria-label="logo" /></a>
</div>
<div class="level-right"><p class="sponsors level-item is-marginless"><a href="{{ config_url('acknowledgment') }}">We gratefully acknowledge support from<br /> the Simons Foundation and member institutions</a></p></div>
<div class="level-right"><p class="sponsors level-item is-marginless"><a href="{{ url_for('acknowledgment') }}">We gratefully acknowledge support from<br /> the Simons Foundation and member institutions</a></p></div>
</div>
<!-- contains arXiv identity and search bar -->
<div class="identity level is-marginless">
<div class="level-left">
<h1 class="level-item"><a href="{{ url_for('home') }}" aria-label="arxiv-logo">arXiv.org</a></h1>
</div>
{{ macros.compactsearch(config_url, 'level-right') }}
{{ macros.compactsearch('level-right') }}
</div> <!-- closes identity -->

<!-- # TODO: reintroduce this once we have access to the user's session.
Expand Down
2 changes: 1 addition & 1 deletion arxiv/base/templates/base/macros.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{# macros to be available to all templates across arxiv #}

{% macro compactsearch(config_url, alignstyle="level-right") -%}
{% macro compactsearch(alignstyle="level-right") -%}
{# Creates an inline search widget with one input box, a dropdown for field
selection, a button, and two tiny help/advanced links. Can be wrapped with
Bulma's level element to align vertically with other elements in the same
Expand Down
19 changes: 0 additions & 19 deletions arxiv/base/tests/test_context_processors.py

This file was deleted.

Loading

0 comments on commit ca5251e

Please sign in to comment.