Skip to content

Commit

Permalink
Merge pull request #118 from arXiv/develop
Browse files Browse the repository at this point in the history
Pre-release merge for v0.15.5
  • Loading branch information
mhl10 authored Apr 18, 2019
2 parents 32e6ad0 + 5080d2e commit 60ad7ee
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 64 deletions.
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pytz = "*"
uwsgi = "*"
"boto3" = "==1.9.108"
wtforms = "*"
"e1839a8" = {path = "."}
bleach = "*"
"flask-s3" = "*"
"backports-datetime-fromisoformat" = "==1.0.0"
Expand Down
96 changes: 50 additions & 46 deletions Pipfile.lock

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

15 changes: 14 additions & 1 deletion arxiv/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ def init_app(self, app: Flask) -> None:
# Set the static url path.
app_version = app.config.get("APP_VERSION", "null")
app_static_path = f'/static/{app.name}/{app_version}'

base_static_url_path = f'/static/base/{base_config.BASE_VERSION}'

# In some cases, we want an app to handle all of its static files, e.g.
# when deploying in a development environment. Setting the
# configuration param RELATIVE_STATIC_PATHS to True will cause
# ``/{RELATIVE_STATIC_PATHS}`` to be prepended to the static paths for
# base assets. This should have no impact on static paths for
# blueprints.
if app.config.get('RELATIVE_STATIC_PATHS'):
prefix = app.config.get('RELATIVE_STATIC_PREFIX', '').strip('/')
base_static_url_path = f'/{prefix}{base_static_url_path}'

app.static_url_path = app_static_path

# The base blueprint attaches static assets and templates. These are
Expand All @@ -64,7 +77,7 @@ def init_app(self, app: Flask) -> None:
__name__,
template_folder='templates',
static_folder='static',
static_url_path=f'/static/base/{base_config.BASE_VERSION}'
static_url_path=base_static_url_path
)
app.register_blueprint(blueprint)

Expand Down
10 changes: 9 additions & 1 deletion arxiv/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

ARXIV_BUSINESS_TZ = os.environ.get("ARXIV_BUSINESS_TZ", "US/Eastern")

BASE_VERSION = "0.15.4"
BASE_VERSION = "0.15.5"
"""The version of the arxiv-base package."""

APP_VERSION = "0.15.4"
Expand All @@ -91,3 +91,11 @@
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', 'nope')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', 'nope')
AWS_REGION = os.environ.get('AWS_REGION', 'us-east-1')

# In some cases, we want an app to handle all of its static files, e.g. when
# deploying in a development environment. Setting the configuration param
# RELATIVE_STATIC_PATHS to True will cause ``/{RELATIVE_STATIC_PREFIX}`` to be
# prepended to the static paths for base assets. This should have no impact on
# static paths for blueprints.
RELATIVE_STATIC_PATHS = bool(int(os.environ.get('RELATIVE_STATIC_PATHS', '0')))
RELATIVE_STATIC_PREFIX = os.environ.get('RELATIVE_STATIC_PREFIX', '')
4 changes: 2 additions & 2 deletions arxiv/base/templates/base/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h1 class="title mathjax"><span class="descriptor">Title:</span>{{ title|tex2utf
<td class="tablecell label">Subjects:</td>
<td class="tablecell subjects">
<span class="primary-subject">{{ primary_category|get_category_display }}</span>
{%- for category in secondary_categories -%}; {{ category|get_category_display }}{%- endfor -%}
{%- for category in secondary_categories|sort(attribute='id') -%}; {{ category|get_category_display }}{%- endfor -%}
</td>
</tr>
{%- if msc_class %}
Expand Down Expand Up @@ -229,7 +229,7 @@ <h1 class="title mathjax"><span class="descriptor">Title:</span>{{ title|tex2utf

Title: {{ title }}
Authors: {{ authors }}
Categories: {{ primary_category }}{%- for category in secondary_categories -%} {{ category }}{%- endfor %}
Categories: {{ primary_category }}{%- for category in secondary_categories|sort(attribute='id') -%} {{ category }}{%- endfor %}
{% if comments -%}{{ ("Comments: " + comments)|wordwrap(77, wrapstring="\n ") }}{%- endif %}
{% if msc_class -%}MSC classes: {{ msc_class }}{%- endif %}
{% if acm_class -%}ACM classes: {{ acm_class }}{%- endif %}
Expand Down
50 changes: 49 additions & 1 deletion arxiv/base/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,60 @@
"""Tests for :mod:`arxiv.base.urls`."""

from unittest import TestCase, mock
from flask import Flask, url_for
from flask import Flask, url_for, Blueprint
from arxiv.base import urls, Base
from arxiv.base.exceptions import ConfigurationError
from werkzeug.routing import BuildError


class TestStaticURLs(TestCase):
"""Test building static URLs."""

def test_static_urls(self):
"""We have vanilla Flask app with a blueprint."""
self.app = Flask('test')
self.app.config['SERVER_NAME'] = 'nope.com'
Base(self.app)

self.app.register_blueprint(Blueprint('fooprint', __name__,
url_prefix='/foo',
static_folder='static',
static_url_path='baz'))

with self.app.app_context():
url = url_for('base.static', filename='css/abs.css')
self.assertTrue(url.startswith('http://nope.com/static/base/'))
url = url_for('fooprint.static', filename='img/foo.jpg')
self.assertTrue(url.startswith('http://nope.com/foo/static/test/'))

def test_relative_static_urls(self):
"""Relative static paths are enabled."""
self.app = Flask('test')
self.app.config['SERVER_NAME'] = 'nope.com'
self.app.config.update({
'SITE_HUMAN_NAME': 'The test site of testiness',
'SITE_HUMAN_SHORT_NAME': 'Test site',
'RELATIVE_STATIC_PATHS': True,
'RELATIVE_STATIC_PREFIX': 'oof',
'SITE_URL_PREFIX': '/test'
})
Base(self.app)

self.app.register_blueprint(Blueprint('fooprint', __name__,
url_prefix='/foo',
static_folder='static',
static_url_path='baz'))

with self.app.app_context():
url = url_for('base.static', filename='css/abs.css')
self.assertTrue(url.startswith('http://nope.com/oof/static/base/'),
'The static URL for base starts with the'
' configured prefix.')
url = url_for('fooprint.static', filename='img/foo.jpg')
self.assertFalse(url.startswith('http://nope.com/oof'),
'The blueprint static path is not affected.')


class TestGetURLMap(TestCase):
"""Tests for :func:`arxiv.base.urls.get_url_map`."""

Expand Down
Loading

0 comments on commit 60ad7ee

Please sign in to comment.