Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Information page test rebase 6 #32

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3136b69
Standard_pages app creation
nehakerung Nov 1, 2024
90fc0b3
Django models for information page updated and the template for the i…
sanjeevz3009 Nov 7, 2024
3351dd5
Zombie code removed
sanjeevz3009 Nov 7, 2024
7b3813e
Unnused files deleted
sanjeevz3009 Nov 7, 2024
63487c5
Mirgation file formatted
sanjeevz3009 Nov 7, 2024
219e70f
django-manager-missing ignore added
sanjeevz3009 Nov 7, 2024
a722f31
TODO comment removed and docstrings added
sanjeevz3009 Nov 7, 2024
e88f50e
Replace `pytest` with Django's built-in runner (#18)
RealOrangeOne Nov 5, 2024
46b8b6f
Information code formatted
sanjeevz3009 Nov 7, 2024
4fa2ef3
Docstring rewritten to make it more concise
sanjeevz3009 Nov 7, 2024
2175e90
Updated body to content
sanjeevz3009 Nov 7, 2024
64f13c0
Conditional for last_updated added, InformationPage class docstring s…
sanjeevz3009 Nov 8, 2024
6ddabe0
summary TextField null=true removed and the migration file regenerate…
sanjeevz3009 Nov 8, 2024
d80edaf
Removing the conditional as per requirement the summary field is requ…
sanjeevz3009 Nov 8, 2024
08e938c
InformationPage restrictions added
sanjeevz3009 Nov 8, 2024
7329601
Release calendar pages (#16)
zerolab Nov 8, 2024
c0b9726
Code formatted
sanjeevz3009 Nov 8, 2024
035550d
Comments added
sanjeevz3009 Nov 11, 2024
85d44ca
Comment out the scheduler image (#22)
zerolab Nov 11, 2024
ca03791
Custom CSS added to make video embeds responsive
sanjeevz3009 Nov 11, 2024
f43c7f2
Formatting fixed
sanjeevz3009 Nov 11, 2024
1eaadc7
Ignore Unexpected property "left" property-disallowed-list rule
sanjeevz3009 Nov 12, 2024
ab1cccf
cms/release_calendar/models.py formating fixed
sanjeevz3009 Nov 12, 2024
81f4290
Replace Docker Desktop setup with Colima (#24)
MebinAbraham Nov 12, 2024
31fa095
Add Cookie banner and Google Tag Manager snippet (#19)
kacperpONS Nov 12, 2024
d1fc5e2
Analysis page and series (#20)
zerolab Nov 14, 2024
66a8ed4
Addition of equation partials
nehakerung Nov 14, 2024
fc4ae81
Deleted media files and made lint, format test pass
nehakerung Nov 14, 2024
af9f89a
Repeated code remove, /media added to .gitignore, media file removed
nehakerung Nov 15, 2024
0998a17
Check tests pass
nehakerung Nov 15, 2024
68c8e24
Custom sign commit
nehakerung Nov 15, 2024
7bb1076
Fix `KeyError 'changes_to_release_date'` (#26)
zerolab Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .docker/Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
web: python manage.py runserver 0.0.0.0:8000
scheduler: python manage.py scheduler
frontend: npm run start:reload
1 change: 1 addition & 0 deletions .docker/bashrc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ alias dj="django-admin"
if [ -n "$DEVCONTAINER" ]
then
alias djrun="django-admin runserver 0.0.0.0:8000"
alias djtest="python manage.py test --settings=cms.settings.test"
alias djrunplus="python manage.py runserver_plus 0.0.0.0:8000"
alias honcho="honcho -f .docker/Procfile"
fi
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ trim_trailing_whitespace = true
# Possible values - true, false
insert_final_newline = true

[*.{js,html,json,yaml,yml}]
[*.{js,json,yaml,yml}]
indent_size = 2

[*.{json,yaml,yml}]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,6 @@ static/

# mkdocs
/site

# Media files
/media
10 changes: 8 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ignore=CVS
# ignore-list. The regex matches against paths and can be in Posix or Windows
# format. Because '\\' represents the directory delimiter on Windows systems,
# it can't be used as an escape character.
ignore-paths=.*/migrations,.venv,venv,.mypy_cache,node_modules
ignore-paths=.*/migrations,.venv,venv,.mypy_cache,node_modules,cms/settings/formats

# Files or directories matching the regular expression patterns are skipped.
# The regex matches against base names, not paths. The default value ignores
Expand Down Expand Up @@ -434,12 +434,18 @@ disable=raw-checker-failed,
duplicate-code,
wrong-import-order,
missing-module-docstring,
too-many-ancestors
too-many-ancestors,
too-few-public-methods,
missing-class-docstring,
fixme

# note:
# - wrong-import-order: covered by ruff
# - missing-module-docstring: because they should be self-explanatory
# - too-many-ancestors: because of our and Wagtail's use of mixins
# - too-few-public-methods: because of Django Meta classes
# - missing-class-docstring: mostly because of Django classes.
# - fixme: because we want to leave TODO notes for future features.

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ all: ## Show the available make targets.

.PHONY: clean
clean: ## Clean the temporary files.
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf .coverage
rm -rf .ruff_cache
Expand Down Expand Up @@ -39,6 +38,7 @@ lint: lint-py lint-html lint-frontend ## Run all linters (python, html, front-en
.PHONY: lint-py
lint-py: ## Run all Python linters (ruff/pylint/mypy).
poetry run ruff check .
poetry run ruff format --check .
find . -type f -name "*.py" | xargs poetry run pylint --reports=n --output-format=colorized --rcfile=.pylintrc --django-settings-module=cms.settings.production -j 0
make mypy

Expand All @@ -52,7 +52,10 @@ lint-frontend: ## Run front-end linters

.PHONY: test
test: ## Run the tests and check coverage.
poetry run pytest -n auto --ds=cms.settings.test --cov=cms --cov-report term-missing
poetry run coverage erase
poetry run coverage run ./manage.py test --parallel --settings=cms.settings.test
poetry run coverage combine
poetry run coverage report --fail-under=90

.PHONY: mypy
mypy: ## Run mypy.
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Ensure you have the following installed:
managing Python versions.
2. **[Poetry](https://python-poetry.org/)**: This is used to manage package dependencies and virtual
environments.
3. **[Docker](https://docs.docker.com/engine/install/)** and **[Docker Compose](https://docs.docker.com/compose/)**.
3. **[Colima](https://github.com/ONSdigital/dp-compose/blob/main/setting-up-colima-locally.md)** for running the project in Docker containers.
4. **[PostgreSQL](https://www.postgresql.org/)** for the database. Provided as container via `docker-compose.yml` when using the Docker setup.
5. **[Node](https://nodejs.org/en)** and **[`nvm` (Node Version Manager)](https://github.com/nvm-sh/nvm)** for front-end tooling.
6. **Operation System**: Ubuntu/MacOS
Expand Down Expand Up @@ -168,13 +168,14 @@ poetry add wagtailmedia

### Run Tests with Coverage

The unit tests are written using the [pytest](https://docs.pytest.org/en/stable/) framework. To run the tests and check
coverage, run:
To run the tests and check coverage, run:

```bash
make test
```

During tests, the `cms.settings.test` settings module is used. When running test without using `make test`, ensure this settings module is used.

### Linting and Formatting

Various tools are used to lint and format the code in this project.
Expand Down Expand Up @@ -260,11 +261,11 @@ make megalint
Wagtail is built on [Django](https://djangoproject.com/) and changes to its models may require generating and
running schema migrations. For full details see the [Django documentation on migrations](https://docs.djangoproject.com/en/5.1/topics/migrations/)

Below are the commands you will most commonly use:
Below are the commands you will most commonly use, note that these have to be run inside the container.

```bash
# Check if you need to generate any new migrations after changes to the model
poetru run django-admin makemigrations --check
poetry run django-admin makemigrations --check

# Generate migrations
poetry run django-admin makemigrations
Expand Down
Empty file added cms/analysis/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions cms/analysis/blocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from typing import TYPE_CHECKING, ClassVar

from django.utils.text import slugify
from wagtail.blocks import RichTextBlock, StreamBlock, StructBlock
from wagtail.embeds.blocks import EmbedBlock
from wagtail.images.blocks import ImageChooserBlock
from wagtailmath.blocks import MathBlock

from cms.core.blocks import (
DocumentsBlock,
HeadingBlock,
ONSEmbedBlock,
PanelBlock,
RelatedContentBlock,
RelatedLinksBlock,
)

if TYPE_CHECKING:
from wagtail.blocks import StructValue


class SectionContentBlock(StreamBlock):
"""The analysis section content StreamField block definition."""

rich_text = RichTextBlock()
panel = PanelBlock()
image = ImageChooserBlock(group="Media")
documents = DocumentsBlock(group="Media")
embed = EmbedBlock(group="Media")
equation = MathBlock(group="DataVis", icon="decimal")
ons_embed = ONSEmbedBlock(group="DataVis", label="ONS General Embed")
related_links = RelatedLinksBlock(RelatedContentBlock(), icon="link")

class Meta:
template = "templates/components/streamfield/stream_block.html"
block_counts: ClassVar[dict[str, dict]] = {"related_links": {"max_num": 1}}


class SectionBlock(StructBlock):
"""The analysis section block definition."""

title = HeadingBlock()
content = SectionContentBlock()

def to_table_of_contents_items(self, value: "StructValue") -> list[dict[str, str]]:
"""Convert the value to the table of contents component macro format."""
return [{"url": "#" + slugify(value["title"]), "text": value["title"]}]

class Meta:
template = "templates/components/streamfield/analysis_section_block.html"


class AnalysisStoryBlock(StreamBlock):
"""The analysis StreamField block definition."""

section = SectionBlock()

class Meta:
template = "templates/components/streamfield/stream_block.html"
104 changes: 104 additions & 0 deletions cms/analysis/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Generated by Django 5.1.2 on 2024-11-04 17:20

import django.db.models.deletion
import wagtail.contrib.routable_page.models
import wagtail.fields
from django.db import migrations, models

import cms.core.fields


class Migration(migrations.Migration):
initial = True

dependencies = [
("core", "0002_contactdetails"),
("images", "0002_customimage_description"),
("wagtailcore", "0094_alter_page_locale"),
]

operations = [
migrations.CreateModel(
name="AnalysisSeries",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
],
options={
"abstract": False,
},
bases=(wagtail.contrib.routable_page.models.RoutablePageMixin, "wagtailcore.page"),
),
migrations.CreateModel(
name="AnalysisPage",
fields=[
(
"page_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="wagtailcore.page",
),
),
("listing_title", models.CharField(blank=True, max_length=255)),
("listing_summary", models.CharField(blank=True, max_length=255)),
("social_text", models.CharField(blank=True, max_length=255)),
("news_headline", models.CharField(blank=True, max_length=255)),
("summary", wagtail.fields.RichTextField()),
("main_points_summary", wagtail.fields.RichTextField()),
("release_date", models.DateField()),
("next_release_date", models.DateField(blank=True, null=True)),
("is_accredited", models.BooleanField(default=False)),
("is_census", models.BooleanField(default=False)),
("headline_figures", cms.core.fields.StreamField(blank=True, block_lookup={})),
("content", cms.core.fields.StreamField(block_lookup={})),
("show_cite_this_page", models.BooleanField(default=True)),
(
"contact_details",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="core.contactdetails",
),
),
(
"listing_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
(
"social_image",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="images.customimage",
),
),
],
options={
"abstract": False,
},
bases=("wagtailcore.page", models.Model),
),
]
Empty file.
Loading
Loading