Skip to content

Commit

Permalink
Fixes errors for ruff v0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrharpo committed Nov 3, 2023
1 parent 925409c commit 25b8202
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 26 deletions.
14 changes: 8 additions & 6 deletions authors/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from typing import ClassVar, List

from django.db import models
from wagtail.api import APIField
from modelcluster.fields import ParentalKey
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtail.api import APIField
from wagtail.core.fields import RichTextField
from wagtail.core.models import Orderable
from wagtail.images.api.fields import ImageRenditionField
from wagtail.snippets.models import register_snippet
from modelcluster.fields import ParentalKey


class AuthorsOrderable(Orderable):
Expand All @@ -17,7 +19,7 @@ class AuthorsOrderable(Orderable):
on_delete=models.CASCADE,
)

panels = [FieldPanel('author')]
panels: ClassVar[List[FieldPanel]] = [FieldPanel('author')]

@property
def name(self):
Expand All @@ -27,7 +29,7 @@ def name(self):
def image(self):
return self.author.image

api_fields = [
api_fields: ClassVar[List[APIField]] = [
APIField('author_id'),
APIField('name'),
APIField('image', serializer=ImageRenditionField('fill-100x100')),
Expand All @@ -49,11 +51,11 @@ class Author(models.Model):

bio = RichTextField(blank=True, help_text='Brief author bio')

panels = [
panels: ClassVar[List[FieldPanel]] = [
MultiFieldPanel([FieldPanel('name'), FieldPanel('image'), FieldPanel('bio')])
]

api_fields = [
api_fields: ClassVar[List[APIField]] = [
APIField('id'),
APIField('name'),
APIField('image'),
Expand Down
5 changes: 4 additions & 1 deletion authors/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import ClassVar, List

from rest_framework.serializers import ModelSerializer, PrimaryKeyRelatedField
from wagtail.images.api.fields import ImageRenditionField

from authors.models import Author


Expand All @@ -9,7 +12,7 @@ class AuthorSerializer(ModelSerializer):

class Meta:
model = Author
fields = [
fields: ClassVar[List[str]] = [
'author_id',
'name',
'image',
Expand Down
5 changes: 4 additions & 1 deletion authors/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from typing import ClassVar, List

from wagtail.api.v2.views import BaseAPIViewSet

from .models import Author


class AuthorsAPIViewSet(BaseAPIViewSet):
model = Author
listing_default_fields = [
listing_default_fields: ClassVar[List[str]] = [
'id',
'detail_url',
'name',
Expand Down
4 changes: 1 addition & 3 deletions exhibits/management/commands/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def handle(self, old_name, new_name, models, *args, **options):
f"UPDATE django_content_type SET app_label='{new_name}' WHERE app_label='{old_name}'" # noqa E501
)
cursor.execute(
"UPDATE django_migrations SET app='{}' WHERE app='{}'".format(
new_name, old_name
)
f"UPDATE django_migrations SET app='{new_name}' WHERE app='{old_name}'"
)

for model_name in models:
Expand Down
15 changes: 10 additions & 5 deletions exhibits/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar, List

from django.db import models
from modelcluster.fields import ParentalKey
from pydantic import BaseModel
Expand All @@ -21,7 +23,7 @@ class ExhibitsOrderable(Orderable):
on_delete=models.CASCADE,
)

panels = [FieldPanel('exhibit')]
panels: ClassVar[List[FieldPanel]] = [FieldPanel('exhibit')]

@property
def title(self):
Expand All @@ -35,7 +37,7 @@ def cover_image(self):
def authors(self):
return self.exhibit.authors

api_fields = [
api_fields: ClassVar[List[APIField]] = [
APIField('exhibit_id'),
APIField('title'),
APIField(
Expand Down Expand Up @@ -81,9 +83,12 @@ class ExhibitPage(Page):
related_name='+',
)

search_fields = [*Page.search_fields, index.SearchField('body')]
search_fields: ClassVar[List[index.SearchField]] = [
*Page.search_fields,
index.SearchField('body'),
]

content_panels = [
content_panels: ClassVar[List[FieldPanel]] = [
*Page.content_panels,
MultiFieldPanel(
[FieldPanel('cover_image'), FieldPanel('hero_image')], heading='Images'
Expand All @@ -93,7 +98,7 @@ class ExhibitPage(Page):
InlinePanel('other_exhibits', heading='Other Exhibits', max_num=3),
]

api_fields = [
api_fields: ClassVar[List[APIField]] = [
APIField('title'),
APIField('body', serializer=RichTextSerializer()),
APIField(
Expand Down
4 changes: 3 additions & 1 deletion exhibits/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar, List

from wagtail.api.v2.views import BaseAPIViewSet

from .models import ExhibitPage
Expand All @@ -6,7 +8,7 @@
class ExhibitsAPIViewSet(BaseAPIViewSet):
model = ExhibitPage

listing_default_fields = [
listing_default_fields: ClassVar[List[str]] = [
*BaseAPIViewSet.listing_default_fields,
'title',
'body',
Expand Down
9 changes: 7 additions & 2 deletions home/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar, List

from wagtail.admin.edit_handlers import FieldPanel
from wagtail.api import APIField
from wagtail.core.fields import RichTextField
Expand All @@ -7,6 +9,9 @@
class HomePage(Page):
body = RichTextField(blank=True)

content_panels = [*Page.content_panels, FieldPanel('body', classname='full')]
content_panels: ClassVar[List[FieldPanel]] = [
*Page.content_panels,
FieldPanel('body', classname='full'),
]

api_fields = [APIField('body')]
api_fields: ClassVar[List[APIField]] = [APIField('body')]
11 changes: 8 additions & 3 deletions ov_collections/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar, List

from django.db import models
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.api import APIField
Expand Down Expand Up @@ -69,16 +71,19 @@ class Collection(Page):
related_name='+',
)

search_fields = [*Page.search_fields, index.SearchField('introduction')]
search_fields: ClassVar[List[index.SearchField]] = [
*Page.search_fields,
index.SearchField('introduction'),
]

content_panels = [
content_panels: ClassVar[List[FieldPanel]] = [
*Page.content_panels,
FieldPanel('introduction'),
FieldPanel('cover_image'),
FieldPanel('content'),
]

api_fields = [
api_fields: ClassVar[List[APIField]] = [
APIField('title'),
APIField('introduction'),
APIField(
Expand Down
4 changes: 3 additions & 1 deletion ov_collections/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar, List

from wagtail.api.v2.views import BaseAPIViewSet

from .models import Collection
Expand All @@ -6,7 +8,7 @@
class CollectionAPIViewSet(BaseAPIViewSet):
model = Collection

listing_default_fields = [
listing_default_fields: ClassVar[List[str]] = [
*BaseAPIViewSet.listing_default_fields,
'title',
'introduction',
Expand Down
48 changes: 46 additions & 2 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[project]
# PEP 621 project metadata
# See https://www.python.org/dev/peps/pep-0621/
name = "ov-wag"
dependencies = ["Django<4.2,>=4.1.1", "wagtail<4.1,>=4.0.4", "wagtail-factories<3.2,>=3.1.0", "pydantic<2.0,>=1.10.2", "psycopg2<2.10,>=2.9.3"]
requires-python = ">=3.8"

Expand Down Expand Up @@ -37,4 +38,8 @@ select = [
'UP', # pyupgrade
'W', # pycodestyle warnings

]
]
[tool.pdm.dev-dependencies]
dev = [
"ruff>=0.1.3",
]

0 comments on commit 25b8202

Please sign in to comment.