Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions .github/workflows/ci-pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Run pre-commit
on:
push:
branches:
- main
pull_request:
branches:
- '*'

jobs:
check:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Run pre-commit
uses: pre-commit/action@v3.0.1
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
default_language_version:
node: system
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-toml
- id: check-merge-conflict
- id: check-byte-order-marker
- id: check-case-conflict
- id: debug-statements
- id: detect-private-key
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ The testsuite uses [pytest](https://docs.pytest.org/) and [pytest-django](https:
pytest
```

### Linting

To ensure a uniform code style, this project uses [black](https://black.readthedocs.io/en/stable/) and [ruff](https://docs.astral.sh/ruff/). You can install the [pre-commit](https://pre-commit.com) hook to run them automatically when making a git commit:

```bash
pre-commit install
```

## Frontend Development

This project uses Bootstrap. The exact version is specified in the `package.json` file.
Expand Down
4 changes: 2 additions & 2 deletions docker/init-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

set -x

python /app/manage.py makemigrations --dry-run --no-input
python /app/manage.py makemigrations --check --no-input
python /app/manage.py migrate --no-input
python /app/manage.py createcachetable
python /app/manage.py collectstatic --no-input
pytest --cov --cov-report=xml
if [ -d /coverage ]; then cp .coverage coverage.xml /coverage/; fi
python /app/manage.py makemigrations --dry-run --no-input
python /app/manage.py makemigrations --check --no-input
1 change: 0 additions & 1 deletion ietf/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import absolute_import
1 change: 1 addition & 0 deletions ietf/announcements/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import wagtail_factories

from ietf.utils.factories import StandardBlockFactory

from .models import IABAnnouncementIndexPage, IABAnnouncementPage


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,78 @@
# Generated by Django 4.2.7 on 2024-04-03 13:40

from django.db import migrations
import wagtail.blocks
import wagtail.contrib.table_block.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
import wagtailmarkdown.blocks
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('announcements', '0003_alter_iabannouncementpage_body'),
("announcements", "0003_alter_iabannouncementpage_body"),
]

operations = [
migrations.AlterField(
model_name='iabannouncementpage',
name='body',
field=wagtail.fields.StreamField([('heading', wagtail.blocks.CharBlock(icon='title')), ('paragraph', wagtail.blocks.RichTextBlock(icon='pilcrow')), ('image', wagtail.images.blocks.ImageChooserBlock(icon='image', template='includes/imageblock.html')), ('markdown', wagtailmarkdown.blocks.MarkdownBlock(icon='code')), ('embed', wagtail.embeds.blocks.EmbedBlock(icon='code')), ('raw_html', wagtail.blocks.RawHTMLBlock(icon='placeholder')), ('table', wagtail.contrib.table_block.blocks.TableBlock(table_options={'renderer': 'html'}, template='includes/tableblock.html')), ('typed_table', wagtail.contrib.typed_table_block.blocks.TypedTableBlock([('text', wagtail.blocks.CharBlock(required=False)), ('numeric', wagtail.blocks.FloatBlock(required=False, template='blocks/float_block.html')), ('rich_text', wagtail.blocks.RichTextBlock(required=False)), ('image', wagtail.images.blocks.ImageChooserBlock(required=False))])), ('note_well', wagtail.blocks.StructBlock([], icon='placeholder', label='Note Well Text'))], use_json_field=True),
model_name="iabannouncementpage",
name="body",
field=wagtail.fields.StreamField(
[
("heading", wagtail.blocks.CharBlock(icon="title")),
("paragraph", wagtail.blocks.RichTextBlock(icon="pilcrow")),
(
"image",
wagtail.images.blocks.ImageChooserBlock(
icon="image", template="includes/imageblock.html"
),
),
("markdown", wagtailmarkdown.blocks.MarkdownBlock(icon="code")),
("embed", wagtail.embeds.blocks.EmbedBlock(icon="code")),
("raw_html", wagtail.blocks.RawHTMLBlock(icon="placeholder")),
(
"table",
wagtail.contrib.table_block.blocks.TableBlock(
table_options={"renderer": "html"},
template="includes/tableblock.html",
),
),
(
"typed_table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
("text", wagtail.blocks.CharBlock(required=False)),
(
"numeric",
wagtail.blocks.FloatBlock(
required=False,
template="blocks/float_block.html",
),
),
(
"rich_text",
wagtail.blocks.RichTextBlock(required=False),
),
(
"image",
wagtail.images.blocks.ImageChooserBlock(
required=False
),
),
]
),
),
(
"note_well",
wagtail.blocks.StructBlock(
[], icon="placeholder", label="Note Well Text"
),
),
],
use_json_field=True,
),
),
]
6 changes: 5 additions & 1 deletion ietf/announcements/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class Meta:
@property
def children(self):
announcements = self.get_children().live().specific()
return sorted(announcements, key=lambda announcement: announcement.specific.date, reverse=True)
return sorted(
announcements,
key=lambda announcement: announcement.specific.date,
reverse=True,
)


IABAnnouncementIndexPage.content_panels = Page.content_panels + [
Expand Down
7 changes: 4 additions & 3 deletions ietf/announcements/tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import timedelta

import pytest
from bs4 import BeautifulSoup
from django.test import Client
from django.utils import timezone

import pytest

from ietf.home.models import IABHomePage

from .factories import IABAnnouncementIndexPageFactory, IABAnnouncementPageFactory
from .models import IABAnnouncementIndexPage, IABAnnouncementPage

Expand Down Expand Up @@ -55,7 +56,7 @@ def test_announcement_page(self):
assert self.announcement_3.introduction in html

def test_homepage(self):
""" The two most recent announcements are shown on the homepage """
"""The two most recent announcements are shown on the homepage"""
response = self.client.get(self.home.url)
assert response.status_code == 200
html = response.content.decode()
Expand Down
1 change: 0 additions & 1 deletion ietf/bibliography/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
# X model mixin with pre-parser method
# item rendering template tag
# itemS rendering template tag

2 changes: 1 addition & 1 deletion ietf/bibliography/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class BibliographyAppConfig(AppConfig):
name = 'ietf.bibliography'
name = "ietf.bibliography"
verbose_name = "Bibliography items"
4 changes: 2 additions & 2 deletions ietf/bibliography/management/commands/fix_BMI_page_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def change_links(page):
group_pattern1 = re.compile("\((\w+)\)\\xa0[Ww]orking [Gg]roup$")
group_pattern2 = re.compile(" *(\w+) +[Ww]orking [Gg]roup$")

for fieldname in page.CONTENT_FIELD_MAP.keys():
for fieldname in page.CONTENT_FIELD_MAP:
field = getattr(page, fieldname)
for item in field.stream_data:
if not item["type"] in ("paragraph", "raw_html"):
if item["type"] not in ("paragraph", "raw_html"):
continue
soup = BeautifulSoup(item["value"], "html.parser")
for tag in soup.find_all("a", string=rfc_pattern):
Expand Down
75 changes: 60 additions & 15 deletions ietf/bibliography/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2020-04-10 18:46
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('wagtailcore', '0040_page_draft_title'),
('contenttypes', '0002_remove_content_type_name'),
("wagtailcore", "0040_page_draft_title"),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name='BibliographyItem',
name="BibliographyItem",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ordering', models.PositiveIntegerField(help_text='The bibliography items on each referring page are sorted and numbered with this ordering number.')),
('content_key', models.CharField(help_text='The "key" with which this item was created, eg. "rfc" in [[rfc:3514]].', max_length=127)),
('content_identifier', models.CharField(help_text='The "value" with which this item was created, eg. "3514" in [[rfc:3514]].', max_length=127)),
('content_long_title', models.CharField(blank=True, max_length=127)),
('content_title', models.CharField(help_text='The link title for this item, eg. "RFC 7168" for [[rfc:7168]].', max_length=127)),
('object_id', models.PositiveIntegerField(blank=True, null=True)),
('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
('page', models.ForeignKey(help_text='The page that this item links to.', on_delete=django.db.models.deletion.CASCADE, related_name='bibliography_items', to='wagtailcore.Page')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"ordering",
models.PositiveIntegerField(
help_text="The bibliography items on each referring page are sorted and numbered with this ordering number."
),
),
(
"content_key",
models.CharField(
help_text='The "key" with which this item was created, eg. "rfc" in [[rfc:3514]].',
max_length=127,
),
),
(
"content_identifier",
models.CharField(
help_text='The "value" with which this item was created, eg. "3514" in [[rfc:3514]].',
max_length=127,
),
),
("content_long_title", models.CharField(blank=True, max_length=127)),
(
"content_title",
models.CharField(
help_text='The link title for this item, eg. "RFC 7168" for [[rfc:7168]].',
max_length=127,
),
),
("object_id", models.PositiveIntegerField(blank=True, null=True)),
(
"content_type",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="contenttypes.ContentType",
),
),
(
"page",
models.ForeignKey(
help_text="The page that this item links to.",
on_delete=django.db.models.deletion.CASCADE,
related_name="bibliography_items",
to="wagtailcore.Page",
),
),
],
),
]
18 changes: 9 additions & 9 deletions ietf/bibliography/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def render(self, request=None):
template = BibliographyItem.TEMPLATE_CACHE[self.content_key]
else:
try:
template = get_template(
"bibliography/item_{}.html".format(self.content_key)
)
template = get_template(f"bibliography/item_{self.content_key}.html")
except TemplateDoesNotExist:
template = None
BibliographyItem.TEMPLATE_CACHE[self.content_key] = template
Expand All @@ -100,7 +98,7 @@ def render(self, request=None):
return str(object)

def __str__(self): # pragma: no cover
return "Bibliography Item #{}: {}".format(self.ordering, self.content_object)
return f"Bibliography Item #{self.ordering}: {self.content_object}"


class BibliographyMixin(models.Model):
Expand All @@ -127,7 +125,7 @@ def save(self, *args, **kwargs):
]
prepared_fields_being_updated = [
prepared_field in update_fields
for prepared_field in self.CONTENT_FIELD_MAP.keys()
for prepared_field in self.CONTENT_FIELD_MAP
]

if any(source_fields_being_updated) or any(prepared_fields_being_updated):
Expand All @@ -147,7 +145,7 @@ def save(self, *args, **kwargs):
all_content = "".join(
[
str(getattr(self, content_field)) or ""
for content_field in self.CONTENT_FIELD_MAP.keys()
for content_field in self.CONTENT_FIELD_MAP
]
)
all_soup = BeautifulSoup(all_content, "html.parser")
Expand All @@ -161,7 +159,9 @@ def save(self, *args, **kwargs):
# Look for <a> nodes that are tagged with bibliographic markup,
# create BibliographyItem records, and turn the <a> nodes into
# footnote links.
for index, tag in enumerate(all_soup.find_all("a", attrs={"data-app": True})):
for index, tag in enumerate(
all_soup.find_all("a", attrs={"data-app": True})
):
app = tag["data-app"]
model = tag["data-linktype"]
obj_id = tag["data-id"]
Expand Down Expand Up @@ -190,7 +190,7 @@ def save(self, *args, **kwargs):
ordering=index + 1,
content_key=model,
content_identifier=obj_id,
**object_details
**object_details,
)
for soup in subsoups.values():
for t in soup.find_all(
Expand All @@ -206,7 +206,7 @@ def save(self, *args, **kwargs):
for prepared_content_field, prepared_soup in subsoups.items():
setattr(self, prepared_content_field, prepared_soup.__unicode__())

return super(BibliographyMixin, self).save(*args, **kwargs)
return super().save(*args, **kwargs)

class Meta:
abstract = True
Loading
Loading