Skip to content

Commit

Permalink
Merge pull request #55 from DemocracyClub/party-lists
Browse files Browse the repository at this point in the history
Support party lists
  • Loading branch information
symroe authored Mar 28, 2024
2 parents e5d8fe8 + f2c8f04 commit 4ea0da9
Show file tree
Hide file tree
Showing 7 changed files with 958 additions and 986 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ jobs:
command: |
sudo `pipenv --venv`/bin/playwright install-deps
- run: pipenv run playwright install
- run: pipenv run black-check
- run: pipenv run ruff
- run: pipenv run ruff-format
- run: pipenv run pytest --cov-report= --cov=postcode_lookup --junitxml=test-reports/junit.xml
- codecov/upload:
file: /home/circleci/repo/test-reports/junit.xml
Expand Down
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: debug-statements
- id: trailing-whitespace
- id: check-merge-conflict
- id: check-json
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.245'
rev: 'v0.3.4'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --extend-exclude, TCH]
- id: ruff-format
- repo: https://github.com/awslabs/cfn-python-lint
rev: v0.83.3 # The version of cfn-lint to use
rev: v0.86.1 # The version of cfn-lint to use
hooks:
- id: cfn-python-lint
files: template.yaml$
11 changes: 5 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ dc-response-builder = {file = "https://github.com/DemocracyClub/dc_response_buil
dateparser = "==1.1.7"
sentry-sdk = {extras = ["starlette"], version = "*"}
urllib3 = "<2"
ruff = "*"

[dev-packages]
uvicorn = "*"
black = "*"
pytest = "*"
respx = "*"
aws-sam-cli = "*"
ipdb = "*"
beautifulsoup4 = "*"
pydantic = {extras = ["email"], version = "*"}
pydantic = {extras = ["email"], version = "==2.6.4"}
pydantic-factories = "*"
ruff = "*"
ruff = "0.3.4"
pytest-cov = "*"
coverage = {extras = ["toml"], version = "*"}
pytest-asyncio = "*"
Expand All @@ -35,8 +35,7 @@ pre-commit = "*"
python_version = "3.10"

[scripts]
black = "black ."
black-check = "black --check ."
pytest = "pytest"
ruff = "ruff --diff postcode_lookup lib/template_generator"
ruff = "ruff check"
ruff-format = "ruff format ."
build_templates = "python lib/template_generator/generate_base_template.py"
1,860 changes: 915 additions & 945 deletions Pipfile.lock

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions postcode_lookup/dc_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
from response_builder.v1.sandbox import SANDBOX_BASE_URL, SANDBOX_POSTCODES


class InvalidPostcodeException(Exception):
...
class InvalidPostcodeException(Exception): ...


class InvalidUPRNException(Exception):
...
class InvalidUPRNException(Exception): ...


def valid_postcode(postcode: str):
Expand Down Expand Up @@ -70,12 +68,10 @@ def _get(self, endpoint, params=None):
return req

@abstractmethod
def get_postcode(self, postcode: str) -> dict:
...
def get_postcode(self, postcode: str) -> dict: ...

@abstractmethod
def get_uprn(self, uprn: str) -> dict:
...
def get_uprn(self, uprn: str) -> dict: ...


class LiveAPIBackend(BaseAPIClient):
Expand Down
41 changes: 27 additions & 14 deletions postcode_lookup/templates/includes/ballot_model.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,38 @@
{% endif %}
{% endif %}
{% else %}
<p>This election takes place on <time datetime=&quot;{{ ballot.poll_open_date }}&quot;>{{ ballot.poll_open_date.strftime('%-d %B %Y') }}</time>. <a href=&quot;/i-am-a/voter/types-elections&quot;>Find out more about voting in this election</a></p>
<p>This election takes place on <time datetime=&quot;{{ ballot.poll_open_date }}&quot;>{{ ballot.poll_open_date.strftime('%-d %B %Y') }}</time>.
<a href=&quot;/i-am-a/voter/types-elections&quot;>Find out more about voting in this election</a>.</p>
{% endif %}


{% if ballot.candidates_verified %}
{% if not ballot.cancelled or ballot.metadata.cancelled_election.title == "Uncontested election" %}
<ul class=&quot;u-list-reset ballot&quot;>
{% for candidate in ballot.candidates %}
<li class=&quot;ballot__candidate&quot;>
{{ candidate.person.name }}
{% if ballot.metadata.cancelled_election.title == "Uncontested election" %}
(elected unopposed)
{% endif %}
<br>
{{ candidate.party.party_name }}
</li>
{% endfor %}
</ul>
<p>Visit <a href=&quot;https://whocanivotefor.co.uk/elections/{{ postcode }}&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; class=&quot;o-external-link&quot;>Who Can I Vote For <span class=&quot;visually-hidden&quot;>(Opens in new window)</span></a> to find out more about your candidates</p>
{% if ballot.voting_system.uses_party_lists %}
<ul class=&quot;u-list-reset ballot&quot;>
{% for party_name, candidates in ballot.candidates|groupby('party.party_name')|sort %}
<li>{{ party_name }} ({{ candidates|length }} candidates)</li>
{% endfor %}
</ul>
{% else %}
<ul class=&quot;u-list-reset ballot&quot;>
{% for candidate in ballot.candidates %}
<li class=&quot;ballot__candidate&quot;>
{{ candidate.person.name }}
{% if ballot.metadata.cancelled_election.title == "Uncontested election" %}
(elected unopposed)
{% endif %}
<br>
{{ candidate.party.party_name }}
</li>
{% endfor %}
</ul>
{% endif %}

<p>Visit <a href=&quot;https://whocanivotefor.co.uk/elections/{{ postcode }}&quot; target=&quot;_blank&quot;
rel=&quot;noopener&quot; class=&quot;o-external-link&quot;>Who Can I Vote For <span
class=&quot;visually-hidden&quot;>(Opens in new window)</span></a> to find out more about your
candidates</p>
{% endif %}


Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
[tool.black]
line-length = 80

[tool.ruff]
line-length = 80
ignore = ["E501"]
extend-select = [
lint.ignore = ["E501"]
lint.extend-select = [
"I",
"C4",
"SIM",
Expand Down

0 comments on commit 4ea0da9

Please sign in to comment.