diff options
author | 2018-03-04 16:33:01 +0000 | |
---|---|---|
committer | 2018-03-04 16:33:01 +0000 | |
commit | 5099ae7055b313d1a93d53069c2cfbb0ca0dcf5a (patch) | |
tree | e8d4b781a38b17502f24e1fd9f444926e88544d6 /pysite | |
parent | Fix navbar dropdown (diff) |
Info pages #13xan #13xak (#36)
* Info pages and templates
* Info pages and templates
* Info pages and templates
* Update navigation and fix up HTML
* Navigation HTML spacing for readability
* Fix error views not using `self.render()`
* `render()` method should accept Any for context values
* Change header linking CSS to a dedicated class
* Rules page
* Basic resources page setup
* Fix headers for new CSS class
* Resource categories and initial resource data
* Add link to JSON file on GH - won't work until the branch is merged
* Remove info overview page and redirect info root url to resources
* Flake8
* Add some tests
* Line lengths
Diffstat (limited to 'pysite')
-rw-r--r-- | pysite/base_route.py | 4 | ||||
-rw-r--r-- | pysite/views/error_handlers/http_4xx.py | 24 | ||||
-rw-r--r-- | pysite/views/error_handlers/http_5xx.py | 39 | ||||
-rw-r--r-- | pysite/views/main/info/index.py | 12 | ||||
-rw-r--r-- | pysite/views/main/info/resources.py | 21 | ||||
-rw-r--r-- | pysite/views/main/info/rules.py | 10 |
6 files changed, 74 insertions, 36 deletions
diff --git a/pysite/base_route.py b/pysite/base_route.py index 400a4649..f389b56e 100644 --- a/pysite/base_route.py +++ b/pysite/base_route.py @@ -1,6 +1,6 @@ # coding=utf-8 from collections import Iterable -from typing import Any, Dict +from typing import Any from flask import Blueprint, Response, jsonify, render_template from flask.views import MethodView @@ -17,7 +17,7 @@ class BaseView(MethodView): name = None # type: str - def render(self, *template_names: str, **context: Dict[str, Any]) -> str: + def render(self, *template_names: str, **context: Any) -> str: """ Render some templates and get them back in a form that you can simply return from your view function. diff --git a/pysite/views/error_handlers/http_4xx.py b/pysite/views/error_handlers/http_4xx.py index 5717feae..74d43d6c 100644 --- a/pysite/views/error_handlers/http_4xx.py +++ b/pysite/views/error_handlers/http_4xx.py @@ -1,5 +1,5 @@ # coding=utf-8 -from flask import render_template, request +from flask import request from werkzeug.exceptions import HTTPException from pysite.base_route import ErrorView @@ -13,17 +13,19 @@ class Error400View(ErrorView): def get(self, error: HTTPException): error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") - return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, - error_message=error_desc + - " If you believe we have made a mistake, please " - "<a href='https://github.com" - "/discord-python/site/issues'>open an issue on our GitHub</a>."), error.code + return self.render( + "errors/error.html", code=error.code, req=request, error_title=error_desc, + error_message=error_desc + + " If you believe we have made a mistake, please " + "<a href='https://github.com/discord-python/site/issues'>open an issue on our GitHub</a>." + ), error.code def post(self, error: HTTPException): error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") - return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, - error_message=error_desc + - " If you believe we have made a mistake, please " - "<a href='https://github.com" - "/discord-python/site/issues'>open an issue on our GitHub</a>."), error.code + return self.render( + "errors/error.html", code=error.code, req=request, error_title=error_desc, + error_message=error_desc + + " If you believe we have made a mistake, please " + "<a href='https://github.com/discord-python/site/issues'>open an issue on our GitHub</a>." + ), error.code diff --git a/pysite/views/error_handlers/http_5xx.py b/pysite/views/error_handlers/http_5xx.py index 6bbc8275..60d3b1bb 100644 --- a/pysite/views/error_handlers/http_5xx.py +++ b/pysite/views/error_handlers/http_5xx.py @@ -1,5 +1,5 @@ # coding=utf-8 -from flask import render_template, request +from flask import request from werkzeug.exceptions import HTTPException from pysite.base_route import ErrorView @@ -13,28 +13,21 @@ class Error500View(ErrorView): def get(self, error: HTTPException): error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") - return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, - error_message="An error occurred while " - "processing this " - "request, please try " - "again later. " - "If you believe we have made a mistake, " - "please " - "<a href='https://github.com" - "/discord-python/site/issues'>file an issue on our GitHub" - "</a>."), error.code + return self.render( + "errors/error.html", code=error.code, req=request, error_title=error_desc, + error_message="An error occurred while processing this request, please try " + "again later. If you believe we have made a mistake, please " + "<a href='https://github.com/discord-python/site/issues'>file an issue on our" + " GitHub</a>." + ), error.code def post(self, error: HTTPException): - error_desc = ERROR_DESCRIPTIONS.get(error.code, - "We're not really sure what happened there, please try again.") + error_desc = ERROR_DESCRIPTIONS.get(error.code, "We're not really sure what happened there, please try again.") - return render_template("errors/error.html", code=error.code, req=request, error_title=error_desc, - error_message="An error occurred while " - "processing this " - "request, please try " - "again later. " - "If you believe we have made a mistake, " - "please " - "<a href='https://github.com" - "/discord-python/site/issues'>file an issue on our GitHub" - "</a>."), error.code + return self.render( + "errors/error.html", code=error.code, req=request, error_title=error_desc, + error_message="An error occurred while processing this request, please try " + "again later. If you believe we have made a mistake, please " + "<a href='https://github.com/discord-python/site/issues'>file an issue on our" + " GitHub</a>." + ), error.code diff --git a/pysite/views/main/info/index.py b/pysite/views/main/info/index.py new file mode 100644 index 00000000..371a5353 --- /dev/null +++ b/pysite/views/main/info/index.py @@ -0,0 +1,12 @@ +# coding=utf-8 +from flask import redirect + +from pysite.base_route import RouteView + + +class IndexView(RouteView): + path = "/info/" + name = "info" + + def get(self): + return redirect("/info/resources") diff --git a/pysite/views/main/info/resources.py b/pysite/views/main/info/resources.py new file mode 100644 index 00000000..bce162f4 --- /dev/null +++ b/pysite/views/main/info/resources.py @@ -0,0 +1,21 @@ +# coding=utf-8 +import json +from logging import getLogger + +from pysite.base_route import RouteView + + +try: + with open("static/resources.json") as fh: + categories = json.load(fh) +except Exception: + getLogger("Resources").exception("Failed to load resources.json") + categories = None + + +class ResourcesView(RouteView): + path = "/info/resources" + name = "info/resources" + + def get(self): + return self.render("main/info/resources.html", categories=categories) diff --git a/pysite/views/main/info/rules.py b/pysite/views/main/info/rules.py new file mode 100644 index 00000000..75faded1 --- /dev/null +++ b/pysite/views/main/info/rules.py @@ -0,0 +1,10 @@ +# coding=utf-8 +from pysite.base_route import RouteView + + +class RulesView(RouteView): + path = "/info/rules" + name = "info/rules" + + def get(self): + return self.render("main/info/rules.html") |