Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #103 from communitiesuk/bau/fix-bad-html
Browse files Browse the repository at this point in the history
General tidy up on Find
  • Loading branch information
samuelhwilliams authored May 2, 2024
2 parents b723e3d + b18a239 commit 67b0391
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 370 deletions.
69 changes: 11 additions & 58 deletions app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from flask import (
flash,
json,
make_response,
redirect,
render_template,
request,
Expand Down Expand Up @@ -33,7 +31,7 @@
get_returns,
process_api_response,
)
from app.main.forms import CookiesForm, DownloadForm
from app.main.forms import DownloadForm


@bp.route("/", methods=["GET"])
Expand All @@ -48,30 +46,10 @@ def index():
@bp.route("/start", methods=["GET", "POST"])
@login_required(return_app=SupportedApp.POST_AWARD_FRONTEND)
def start_page():
form = DownloadForm()

if request.method == "GET":
return render_template("start_page.html", form=form)

if request.method == "POST":
if not form.validate():
current_app.logger.info("Unexpected file format requested from /download")
return abort(400), "Form validation failed"

file_format = form.file_format.data

current_datetime = datetime.now().strftime("%Y-%m-%d-%H%M%S")

query_params = {"file_format": file_format}

content_type, file_content = process_api_response(query_params)

return send_file(
file_content,
download_name=f"download-{current_datetime}.{file_format}",
as_attachment=True,
mimetype=content_type,
)
# We used to have a start page, but seem to have decided since then to just take users straight to the download
# page as it was seemingly an unnecessary step. We have a redirect here only for the principle that it's nice
# to not break URLs entirely (in case, eg, a user has bookmarked it).
return redirect(url_for(".download"))


@bp.route("/download", methods=["GET", "POST"])
Expand Down Expand Up @@ -153,47 +131,22 @@ def download():
@bp.route("/accessibility", methods=["GET"])
@login_required(return_app=SupportedApp.POST_AWARD_FRONTEND)
def accessibility():
return render_template("accessibility.html")
current_app.logger.error("user has tried to view accessibility statement but we haven't written one yet")
abort(404)


@bp.route("/cookies", methods=["GET", "POST"])
@login_required(return_app=SupportedApp.POST_AWARD_FRONTEND)
def cookies():
form = CookiesForm()
# Default cookies policy to reject all categories of cookie
cookies_policy = {"functional": "no", "analytics": "no"}

if form.validate_on_submit():
# Update cookies policy consent from form data
cookies_policy["functional"] = form.functional.data
cookies_policy["analytics"] = form.analytics.data

# Create flash message confirmation before rendering template
flash("You’ve set your cookie preferences.", "success")

# Create the response so we can set the cookie before returning
response = make_response(render_template("cookies.html", form=form))

# Set cookies policy for one year
response.set_cookie("cookies_policy", json.dumps(cookies_policy), max_age=31557600)
return response
if request.method == "GET":
if request.cookies.get("cookies_policy"):
# Set cookie consent radios to current consent
cookies_policy = json.loads(request.cookies.get("cookies_policy"))
form.functional.data = cookies_policy["functional"]
form.analytics.data = cookies_policy["analytics"]
else:
# If conset not previously set, use default "no" policy
form.functional.data = cookies_policy["functional"]
form.analytics.data = cookies_policy["analytics"]
return render_template("cookies.html", form=form)
current_app.logger.error("user has tried to view cookie policy but we haven't written one yet")
abort(404)


@bp.route("/privacy", methods=["GET"])
@login_required(return_app=SupportedApp.POST_AWARD_FRONTEND)
def privacy():
return render_template("privacy.html")
current_app.logger.error("user has tried to view privacy policy but we haven't written one yet")
abort(404)


@bp.route("/help", methods=["GET"])
Expand Down
51 changes: 0 additions & 51 deletions app/static/src/js/cookie-banner.js

This file was deleted.

18 changes: 12 additions & 6 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,28 @@
{% endblock %}

{% block beforeContent %}
{% block phaseBanner %}
{{ govukPhaseBanner({
'tag': {
'text': config['SERVICE_PHASE']
},
'html': 'This is a new service – your <a class="govuk-link" href="mailto:' + config['CONTACT_EMAIL'] +'?subject=Feedback">feedback</a> will help us to improve it.'
}) }}
{% endblock %}

<div class="govuk-width-container global-actions">
{{ govukBackLink({
'text': 'Back',
'href': url_for('main.download')
}) }}
<div class="global-actions">
{% if request.path in [url_for('main.download'), url_for('main.start_page')] %}
<div></div>
{% else %}
{{ govukBackLink({
'text': 'Back',
'href': url_for('main.download')
}) }}
{% endif %}

<div class="govuk-!-margin-top-2">
<a href="{{ url_for('main.help') }}" class="govuk-body govuk-link govuk-link--no-underline govuk-link--no-visited-state">Get help</a>
<a href="{{ config['AUTHENTICATOR_HOST'] + '/sso/logout' }}"class="govuk-body govuk-link govuk-link--no-underline govuk-link--no-visited-state govuk-!-margin-left-4">Log out</a>
<a href="{{ config['AUTHENTICATOR_HOST'] + '/sso/logout' }}" class="govuk-body govuk-link govuk-link--no-underline govuk-link--no-visited-state govuk-!-margin-left-4">Log out</a>
</div>
</div>
{% endblock %}
Expand Down
8 changes: 0 additions & 8 deletions app/templates/main/accessibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

{% block pageTitle %}Accessibility statement – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% block beforeContent %}
{{ super() }}
{{ govukBackLink({
'text': "Back",
'href': url_for('main.download')
}) }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
8 changes: 0 additions & 8 deletions app/templates/main/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@

{% block pageTitle %}{%- if form.errors %}Error: {% endif -%}Cookies – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% block beforeContent %}
{{ super() }}
{{ govukBackLink({
'text': "Back",
'href': url_for('main.download')
}) }}
{% endblock %}

{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand Down
5 changes: 0 additions & 5 deletions app/templates/main/data-glossary.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
{%- from "govuk_frontend_jinja/components/accordion/macro.html" import govukAccordion -%}
{%- from 'govuk_frontend_jinja/components/back-link/macro.html' import govukBackLink -%}


{% block beforeContent %}
{{ super() }}
{% endblock %}

{% block content %}
<h1 class="govuk-heading-xl">Data extract glossary</h1>
<p class="govuk-body">
Expand Down
153 changes: 70 additions & 83 deletions app/templates/main/download.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,87 +14,74 @@
{% endblock %}

{% block content %}

<main id="main-content" role="main">
<section class="govuk-main-wrapper">
<div class="govuk-width-container">
<div class="download-data-container">
<h1 class="govuk-heading-xl">Download monitoring and evaluation data</h1>

<p class="govuk-body">Use the following filters to select the projects you need.</p>

<p class="govuk-body">The filters you select will be applied at project level. You will be able to download this as a file to your desktop.</p>

<p class="govuk-inset-text">
If you don't select any filters you will get all the data from all of the projects that are in the system.
</p>

</div>

<form method="post" action="{{ url_for('main.download') }}">
{{ form.csrf_token }}

{{ govukAccordion({
"id": "download",
"headingLevel": 2,
"showAllSectionsText": "",
"items": [
{
"heading": {
"text": "Filter by fund"
},
"content": {
"html": checkboxItems(funds["name"], funds["items"])
},
},
{
"heading": {
"text": "Filter by area"
},
"content": {
"html": checkboxItems(areas["name"], areas["items"])
}
},
{
"heading": {
"text": "Filter by funded organisation"
},
"content": {
"html": checkboxItems(orgs["name"], orgs["items"])
}
},
{
"heading": {
"text": "Filter by outcomes"
},
"content": {
"html": checkboxItems(outcomes["name"], outcomes["items"])
}
},
{
"heading": {
"text": "Filter by returns period"
},
"content": {
"html": selectItems(returnsParams)
}
}
]
})
}}


</section>

{{ form.file_format}}
{{ form.download }}

</form>

<p class="govuk-body">
<a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.data_glossary') }}">Access the funding glossary</a>
</p>

</main>

<h1 class="govuk-heading-xl">Download monitoring and evaluation data</h1>

<p class="govuk-body">Use the following filters to select the projects you need.</p>

<p class="govuk-body">The filters you select will be applied at project level. You will be able to download this as a file to your desktop.</p>

<p class="govuk-inset-text">
If you don't select any filters you will get all the data from all of the projects that are in the system.
</p>

<form method="post" action="{{ url_for('main.download') }}">
{{ form.csrf_token }}

{{ govukAccordion({
"id": "accordion-download",
"headingLevel": 2,
"showAllSectionsText": "",
"items": [
{
"heading": {
"text": "Filter by fund"
},
"content": {
"html": checkboxItems(funds["name"], funds["items"])
},
},
{
"heading": {
"text": "Filter by area"
},
"content": {
"html": checkboxItems(areas["name"], areas["items"])
}
},
{
"heading": {
"text": "Filter by funded organisation"
},
"content": {
"html": checkboxItems(orgs["name"], orgs["items"])
}
},
{
"heading": {
"text": "Filter by outcomes"
},
"content": {
"html": checkboxItems(outcomes["name"], outcomes["items"])
}
},
{
"heading": {
"text": "Filter by returns period"
},
"content": {
"html": selectItems(returnsParams)
}
}
]
})
}}

{{ form.file_format }}
{{ form.download }}

</form>

<p class="govuk-body">
<a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.data_glossary') }}">Access the funding glossary</a>
</p>
{% endblock %}
Loading

0 comments on commit 67b0391

Please sign in to comment.