Skip to content

Commit

Permalink
Final platform config
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Dec 20, 2023
1 parent 0636014 commit 34092d4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion .platform/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"https://{default}/":
type: upstream
upstream: app:http

# "https://{default}/media":
# type: redirect
# to: "https://develop-sr3snxi-rasrzs7pi6sd4.uk-1.platformsh.site/media"
4 changes: 2 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
import logging
import re
from datetime import datetime

from app.lib import cache
Expand All @@ -13,7 +13,7 @@ def create_app(config_class=Config):
app = Flask(__name__, static_url_path="/static")
app.config.from_object(config_class)

gunicorn_error_logger = logging.getLogger('gunicorn.error')
gunicorn_error_logger = logging.getLogger("gunicorn.error")
app.logger.handlers.extend(gunicorn_error_logger.handlers)
app.logger.setLevel(gunicorn_error_logger.level)

Expand Down
1 change: 1 addition & 0 deletions app/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .cache import cache
from .cache_key_prefix import cache_key_prefix
from .pagination_list import pagination_list
6 changes: 6 additions & 0 deletions app/lib/cache_key_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from flask import request


def cache_key_prefix():
"""Make a key that includes GET parameters."""
return request.full_path
15 changes: 5 additions & 10 deletions app/search/routes.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
from app.lib import cache
from app.lib import cache, cache_key_prefix
from app.search import bp
from flask import render_template, request


def make_cache_key_prefix():
"""Make a key that includes GET parameters."""
return request.full_path


@bp.route("/")
@cache.cached(key_prefix=make_cache_key_prefix)
@cache.cached(key_prefix=cache_key_prefix)
def index():
query = request.args["q"] if "q" in request.args else ""
return render_template(
Expand All @@ -19,7 +14,7 @@ def index():


@bp.route("/featured/")
@cache.cached(key_prefix=make_cache_key_prefix)
@cache.cached(key_prefix=cache_key_prefix)
def featured():
query = request.args["q"] if "q" in request.args else ""
return render_template(
Expand All @@ -29,7 +24,7 @@ def featured():


@bp.route("/catalogue/")
@cache.cached(key_prefix=make_cache_key_prefix)
@cache.cached(key_prefix=cache_key_prefix)
def catalogue():
query = request.args["q"] if "q" in request.args else ""
return render_template(
Expand All @@ -38,7 +33,7 @@ def catalogue():


@bp.route("/website/")
@cache.cached(key_prefix=make_cache_key_prefix)
@cache.cached(key_prefix=cache_key_prefix)
def website():
query = request.args["q"] if "q" in request.args else ""
return render_template(
Expand Down
2 changes: 1 addition & 1 deletion app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
},
'exit': {
'text': 'See this page on the Wagtail site',
'href': 'https://feature-headless-4batnpq-rasrzs7pi6sd4.uk-1.platformsh.site' + request.path,
'href': 'https://feature-headless-4batnpq-rasrzs7pi6sd4.uk-1.platformsh.site' + request.full_path,
'target': '_blank'
},
'navigation': navigationItems
Expand Down
4 changes: 3 additions & 1 deletion app/wagtail/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def wagtail_request_handler(uri, params={}):
except requests.exceptions.JSONDecodeError:
current_app.logger.error("API provided non-JSON response")
raise ConnectionError("API provided non-JSON response")
current_app.logger.error(f"API responded with {r.status_code} status for {url}")
current_app.logger.error(
f"API responded with {r.status_code} status for {url}"
)
print("no conn")
raise ConnectionError("Request to API failed")

Expand Down
13 changes: 4 additions & 9 deletions app/wagtail/routes.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
from app.lib import cache
from app.lib import cache, cache_key_prefix
from app.wagtail import bp
from app.wagtail.render import render_content_page
from flask import render_template, request, current_app
from flask import current_app, render_template, request

from .api import page_details_by_uri, page_preview


def make_cache_key_prefix():
"""Make a key that includes GET parameters."""
return request.full_path


@bp.route("/preview/")
def preview_page(key_prefix=make_cache_key_prefix):
def preview_page(key_prefix=cache_key_prefix):
content_type = request.args.get("content_type")
token = request.args.get("token")
page_data = page_preview(content_type, token)
return render_content_page(page_data)


@bp.route("/<path:path>/")
@cache.cached(key_prefix=make_cache_key_prefix)
@cache.cached(key_prefix=cache_key_prefix)
def explore_page(path):
try:
page_data = page_details_by_uri(path)
Expand Down

0 comments on commit 34092d4

Please sign in to comment.