Skip to content

Commit

Permalink
Merge pull request #60 from LandRegistry/govuk-frontend-45
Browse files Browse the repository at this point in the history
GOV.UK Frontend 4.5.0
  • Loading branch information
matthew-shaw authored Feb 21, 2023
2 parents 5abb3e1 + 99f8c72 commit a183b58
Show file tree
Hide file tree
Showing 24 changed files with 1,100 additions and 117 deletions.
57 changes: 50 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Created by https://www.toptal.com/developers/gitignore/api/git,venv,macos,linux,flask,vscode,python,windows,jetbrains+all
# Edit at https://www.toptal.com/developers/gitignore?templates=git,venv,macos,linux,flask,vscode,python,windows,jetbrains+all
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode,git,venv,macos,linux,windows,python,flask,jetbrains+all
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode,git,venv,macos,linux,windows,python,flask,jetbrains+all

### GOV.UK Frontend ###
app/static/fonts*
app/static/images*
app/static/govuk-frontend*
app/static/images*
app/static/VERSION.txt
govuk_components*

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

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

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
Expand Down Expand Up @@ -312,6 +321,10 @@ Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Python ###
# Byte-compiled / optimized / DLL files

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

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

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm

# Celery stuff

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

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

### venv ###
# Virtualenv
# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
Expand All @@ -400,7 +426,24 @@ Temporary Items
pyvenv.cfg
pip-selfcheck.json

#!! ERROR: vscode is undefined. Use list command to see defined gitignore types !!#
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

### Windows ###
# Windows thumbnail cache files
Expand Down Expand Up @@ -428,4 +471,4 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/git,venv,macos,linux,flask,vscode,python,windows,jetbrains+all
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,git,venv,macos,linux,windows,python,flask,jetbrains+all
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ All notable changes to this project will be documented in this file.

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).

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

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

### Added

### Changed

### Deprecated

### Removed

### Fixed

### Security
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# GOV.UK Frontend Flask

![govuk-frontend 4.5.0](https://img.shields.io/badge/govuk--frontend%20version-4.5.0-005EA5?logo=gov.uk&style=flat)

**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.**

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:

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

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

## Demos

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.

## Testing

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

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).

## Next steps
## Contributors

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

### Add database functionality
## Support

### Add user authentication

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:

```python
@login_required
@limiter.limit("2 per second", key_func=lambda: current_user.id)
```
This software is provided _"as-is"_ without warranty. Support is provided on a _"best endeavours"_ basis by the maintainers and open source community.

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.
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.

### Deploy to Heroku
Otherwise, please see the [contribution guidelines](CONTRIBUTING.md) for how to raise a bug report or feature request.
4 changes: 3 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
assets = Environment()
compress = Compress()
csrf = CSRFProtect()
limiter = Limiter(key_func=get_remote_address, default_limits=["2 per second", "60 per minute"])
limiter = Limiter(get_remote_address, default_limits=["2 per second", "60 per minute"])
talisman = Talisman()


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

# Register blueprints
from app.demos import bp as demo_bp
from app.main import bp as main_bp

app.register_blueprint(demo_bp)
app.register_blueprint(main_bp)

return app
5 changes: 5 additions & 0 deletions app/demos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from flask import Blueprint

bp = Blueprint("demos", __name__, template_folder="../templates/demos")

from app.demos import routes # noqa: E402,F401
18 changes: 18 additions & 0 deletions app/demos/custom_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from wtforms.validators import InputRequired


class RequiredIf(InputRequired):
def __init__(self, other_field_name, other_field_value, *args, **kwargs):
self.other_field_name = other_field_name
self.other_field_value = other_field_value

super(RequiredIf, self).__init__(*args, **kwargs)

def __call__(self, form, field):
other_field = form._fields.get(self.other_field_name)

if other_field is None:
raise Exception('no field named "%s" in form' % self.other_field_name)

if other_field.data == self.other_field_value:
super(RequiredIf, self).__call__(form, field)
Loading

0 comments on commit a183b58

Please sign in to comment.