add method to convert .*/ paths to .*/index
This commit is contained in:
parent
76bdc28a9f
commit
11073b4811
@ -4,7 +4,20 @@ from flask import Blueprint
|
|||||||
bp = Blueprint('journal_views', __name__, url_prefix='/')
|
bp = Blueprint('journal_views', __name__, url_prefix='/')
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/', defaults={'path': 'INDEX'})
|
@bp.route('/', defaults={'path': 'index'})
|
||||||
@bp.route('/<path:path>')
|
@bp.route('/<path:path>')
|
||||||
def display_journal_entry(path):
|
def display_journal_entry(path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def journal_file_resolver(path):
|
||||||
|
"""Manipulate the request path to find appropriate journal files.
|
||||||
|
|
||||||
|
* convert dir requests to index files
|
||||||
|
|
||||||
|
Worth noting, Flask already does stuff like convert '/foo/../../../bar' to
|
||||||
|
'/bar', so we don't need to take care around file access here.
|
||||||
|
"""
|
||||||
|
if path.endswith('/'):
|
||||||
|
path = f'{path}index'
|
||||||
|
return path
|
||||||
|
14
tests/test_journal.py
Normal file
14
tests/test_journal.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
"""Test journal views and helper methods."""
|
||||||
|
from incorporealcms.journal import journal_file_resolver
|
||||||
|
|
||||||
|
|
||||||
|
def test_journal_file_resolver_dir_to_index():
|
||||||
|
assert journal_file_resolver('/foo/') == '/foo/index'
|
||||||
|
|
||||||
|
|
||||||
|
def test_journal_file_resolver_subdir_to_index():
|
||||||
|
assert journal_file_resolver('/foo/bar/') == '/foo/bar/index'
|
||||||
|
|
||||||
|
|
||||||
|
def test_journal_file_resolver_other_requests_fine():
|
||||||
|
assert journal_file_resolver('/foo/baz') == '/foo/baz'
|
Loading…
Reference in New Issue
Block a user