Skip to content

Commit a183b58

Browse files
authored
Merge pull request #60 from LandRegistry/govuk-frontend-45
GOV.UK Frontend 4.5.0
2 parents 5abb3e1 + 99f8c72 commit a183b58

24 files changed

+1100
-117
lines changed

.gitignore

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# Created by https://www.toptal.com/developers/gitignore/api/git,venv,macos,linux,flask,vscode,python,windows,jetbrains+all
2-
# Edit at https://www.toptal.com/developers/gitignore?templates=git,venv,macos,linux,flask,vscode,python,windows,jetbrains+all
1+
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,git,venv,macos,linux,windows,python,flask,jetbrains+all
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,git,venv,macos,linux,windows,python,flask,jetbrains+all
33

44
### GOV.UK Frontend ###
55
app/static/fonts*
6-
app/static/images*
76
app/static/govuk-frontend*
7+
app/static/images*
88
app/static/VERSION.txt
9+
govuk_components*
910

1011
### Flask ###
1112
instance/*
@@ -116,7 +117,15 @@ ipython_config.py
116117
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
117118
#poetry.lock
118119

119-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
120+
# pdm
121+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
122+
#pdm.lock
123+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
124+
# in version control.
125+
# https://pdm.fming.dev/#use-with-ide
126+
.pdm.toml
127+
128+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
120129
__pypackages__/
121130

122131
# Celery stuff
@@ -312,6 +321,10 @@ Network Trash Folder
312321
Temporary Items
313322
.apdisk
314323

324+
### macOS Patch ###
325+
# iCloud generated files
326+
*.icloud
327+
315328
### Python ###
316329
# Byte-compiled / optimized / DLL files
317330

@@ -360,7 +373,13 @@ Temporary Items
360373
# commonly ignored for libraries.
361374
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
362375

363-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
376+
# pdm
377+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
378+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
379+
# in version control.
380+
# https://pdm.fming.dev/#use-with-ide
381+
382+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
364383

365384
# Celery stuff
366385

@@ -388,6 +407,13 @@ Temporary Items
388407
# and can be added to the global gitignore or merged into this file. For a more nuclear
389408
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
390409

410+
### Python Patch ###
411+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
412+
poetry.toml
413+
414+
# ruff
415+
.ruff_cache/
416+
391417
### venv ###
392418
# Virtualenv
393419
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
@@ -400,7 +426,24 @@ Temporary Items
400426
pyvenv.cfg
401427
pip-selfcheck.json
402428

403-
#!! ERROR: vscode is undefined. Use list command to see defined gitignore types !!#
429+
### VisualStudioCode ###
430+
.vscode/*
431+
!.vscode/settings.json
432+
!.vscode/tasks.json
433+
!.vscode/launch.json
434+
!.vscode/extensions.json
435+
!.vscode/*.code-snippets
436+
437+
# Local History for Visual Studio Code
438+
.history/
439+
440+
# Built Visual Studio Code Extensions
441+
*.vsix
442+
443+
### VisualStudioCode Patch ###
444+
# Ignore all local history of files
445+
.history
446+
.ionide
404447

405448
### Windows ###
406449
# Windows thumbnail cache files
@@ -428,4 +471,4 @@ $RECYCLE.BIN/
428471
# Windows shortcuts
429472
*.lnk
430473

431-
# End of https://www.toptal.com/developers/gitignore/api/git,venv,macos,linux,flask,vscode,python,windows,jetbrains+all
474+
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,git,venv,macos,linux,windows,python,flask,jetbrains+all

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased](https://github.com/LandRegistry/govuk-frontend-flask/compare/1.0.0...main)
7+
## [Unreleased](https://github.com/<org-or-user>/<repo-name>/compare/0.1.0...main)
88

9-
## [1.0.0](https://github.com/LandRegistry/govuk-frontend-flask/releases/tag/1.0.0) - xx/xx/2022
9+
## [0.1.0](https://github.com/<org-or-user>/<repo-name>/releases/tag/0.1.0) - dd/mm/yyyy
1010

1111
### Added
12+
13+
### Changed
14+
15+
### Deprecated
16+
17+
### Removed
18+
19+
### Fixed
20+
21+
### Security

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# GOV.UK Frontend Flask
22

3+
![govuk-frontend 4.5.0](https://img.shields.io/badge/govuk--frontend%20version-4.5.0-005EA5?logo=gov.uk&style=flat)
4+
5+
**GOV.UK Frontend Flask is a [community tool](https://design-system.service.gov.uk/community/resources-and-tools/) of the [GOV.UK Design System](https://design-system.service.gov.uk/). The Design System team is not responsible for it and cannot support you with using it. Contact the [maintainers](#contributors) directly if you need [help](#support) or you want to request a feature.**
6+
37
This is a template [Flask](https://flask.palletsprojects.com) app using the [GOV.UK Frontend](https://frontend.design-system.service.gov.uk/) and [GOV.UK Design System](https://design-system.service.gov.uk/) which is designed to get a new project started quicker. It is also a reference implementation of two core packages:
48

59
- [GOV.UK Frontend Jinja](https://github.com/LandRegistry/govuk-frontend-jinja) which provides Jinja macros of GOV.UK components
@@ -59,6 +63,10 @@ flask run
5963

6064
You should now have the app running on <http://localhost:5000/>
6165

66+
## Demos
67+
68+
There are some helpful demos included by default that show all of the components available from GOV.UK Frontend Jinja and a selection of forms and validation patterns from GOV.UK Frontend WTForms. These are located in the `app/demos` and `app/templates/demos` directories, along with the `demos` blueprint. Use them for reference whilst building your service, but make sure to delete them, along with the relevant section in `build.sh`, before deploying the app.
69+
6270
## Testing
6371

6472
To run the tests:
@@ -126,21 +134,14 @@ Uses [Flask Limiter](https://flask-limiter.readthedocs.io/en/stable/) to set req
126134

127135
Rate limit storage can be backed by [Redis](https://redis.io/) using the `RATELIMIT_STORAGE_URL` config value in `config.py`, or fall back to in-memory if not present. Rate limit information will also be added to various [response headers](https://flask-limiter.readthedocs.io/en/stable/#rate-limiting-headers).
128136

129-
## Next steps
137+
## Contributors
130138

131-
### Add your own blueprint
139+
- [Matt Shaw](https://github.com/matthew-shaw) (Primary maintainer)
132140

133-
### Add database functionality
141+
## Support
134142

135-
### Add user authentication
136-
137-
If you're implementing user authentication using [Flask Login](https://flask-login.readthedocs.io/en/latest/) you should also use a `key_func` to identify users on routes that require authentication, for example:
138-
139-
```python
140-
@login_required
141-
@limiter.limit("2 per second", key_func=lambda: current_user.id)
142-
```
143+
This software is provided _"as-is"_ without warranty. Support is provided on a _"best endeavours"_ basis by the maintainers and open source community.
143144

144-
This fixes the issue of rate limiting multiple users behind a single IP NAT or proxy, since the request is identified using a different unique value for each user.
145+
If you are a civil servant you can sign up to the [UK Government Digital Slack](https://ukgovernmentdigital.slack.com/signup) workspace to contact the maintainers listed [above](#contributors) and the community of people using this project in the [#govuk-design-system](https://ukgovernmentdigital.slack.com/archives/C6DMEH5R6) channel.
145146

146-
### Deploy to Heroku
147+
Otherwise, please see the [contribution guidelines](CONTRIBUTING.md) for how to raise a bug report or feature request.

app/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
assets = Environment()
1414
compress = Compress()
1515
csrf = CSRFProtect()
16-
limiter = Limiter(key_func=get_remote_address, default_limits=["2 per second", "60 per minute"])
16+
limiter = Limiter(get_remote_address, default_limits=["2 per second", "60 per minute"])
1717
talisman = Talisman()
1818

1919

@@ -61,8 +61,10 @@ def create_app(config_class=Config):
6161
assets.register("js", js)
6262

6363
# Register blueprints
64+
from app.demos import bp as demo_bp
6465
from app.main import bp as main_bp
6566

67+
app.register_blueprint(demo_bp)
6668
app.register_blueprint(main_bp)
6769

6870
return app

app/demos/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from flask import Blueprint
2+
3+
bp = Blueprint("demos", __name__, template_folder="../templates/demos")
4+
5+
from app.demos import routes # noqa: E402,F401

app/demos/custom_validators.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from wtforms.validators import InputRequired
2+
3+
4+
class RequiredIf(InputRequired):
5+
def __init__(self, other_field_name, other_field_value, *args, **kwargs):
6+
self.other_field_name = other_field_name
7+
self.other_field_value = other_field_value
8+
9+
super(RequiredIf, self).__init__(*args, **kwargs)
10+
11+
def __call__(self, form, field):
12+
other_field = form._fields.get(self.other_field_name)
13+
14+
if other_field is None:
15+
raise Exception('no field named "%s" in form' % self.other_field_name)
16+
17+
if other_field.data == self.other_field_value:
18+
super(RequiredIf, self).__call__(form, field)

0 commit comments

Comments
 (0)