Skip to content

Commit 2cf268f

Browse files
authored
ruff (#2882)
1 parent 50518fd commit 2cf268f

File tree

518 files changed

+12808
-9513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

518 files changed

+12808
-9513
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.15.0
4+
hooks:
5+
- id: ruff
6+
args: [--fix]
7+
- id: ruff-format
8+
29
- repo: https://github.com/adamchainz/django-upgrade
310
rev: 1.29.1
411
hooks:
512
- id: django-upgrade
6-
args: [--target-version=4.2]
13+
args: [--target-version=5.2]
714

815
- repo: https://github.com/pre-commit/pre-commit-hooks
916
rev: v6.0.0

banners/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Banner management for displaying site-wide announcements."""

banners/admin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
"""Admin configuration for the banners app."""
2+
13
from django.contrib import admin
24

35
from banners.models import Banner
46

57

68
@admin.register(Banner)
79
class BannerAdmin(admin.ModelAdmin):
10+
"""Admin interface for managing site-wide banners."""
11+
812
list_display = ("title", "active", "psf_pages_only")

banners/apps.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
"""Django app configuration for the banners app."""
2+
13
from django.apps import AppConfig
24

35

46
class BannersAppConfig(AppConfig):
7+
"""App configuration for the banners app."""
58

6-
name = 'banners'
9+
name = "banners"

banners/migrations/0001_initial.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class Migration(migrations.Migration):
7-
87
initial = True
98

109
dependencies = []
@@ -31,27 +30,19 @@ class Migration(migrations.Migration):
3130
),
3231
(
3332
"message",
34-
models.CharField(
35-
help_text="Message to display in the banner", max_length=2048
36-
),
33+
models.CharField(help_text="Message to display in the banner", max_length=2048),
3734
),
3835
(
3936
"link",
40-
models.CharField(
41-
help_text="Link the button will go to", max_length=1024
42-
),
37+
models.CharField(help_text="Link the button will go to", max_length=1024),
4338
),
4439
(
4540
"active",
46-
models.BooleanField(
47-
default=False, help_text="Make the banner active on the site"
48-
),
41+
models.BooleanField(default=False, help_text="Make the banner active on the site"),
4942
),
5043
(
5144
"psf_pages_only",
52-
models.BooleanField(
53-
default=True, help_text="Display the banner on /psf pages only"
54-
),
45+
models.BooleanField(default=True, help_text="Display the banner on /psf pages only"),
5546
),
5647
],
5748
)

banners/models.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1+
"""Models for site-wide announcement banners."""
2+
13
from django.db import models
24

35

46
class Banner(models.Model):
7+
"""A dismissible announcement banner displayed across the site."""
58

6-
title = models.CharField(
7-
max_length=1024, help_text="Text to display in the banner's button"
8-
)
9-
message = models.CharField(
10-
max_length=2048, help_text="Message to display in the banner"
11-
)
9+
title = models.CharField(max_length=1024, help_text="Text to display in the banner's button")
10+
message = models.CharField(max_length=2048, help_text="Message to display in the banner")
1211
link = models.CharField(max_length=1024, help_text="Link the button will go to")
13-
active = models.BooleanField(
14-
null=False, default=False, help_text="Make the banner active on the site"
15-
)
16-
psf_pages_only = models.BooleanField(
17-
null=False, default=True, help_text="Display the banner on /psf pages only"
18-
)
12+
active = models.BooleanField(null=False, default=False, help_text="Make the banner active on the site")
13+
psf_pages_only = models.BooleanField(null=False, default=True, help_text="Display the banner on /psf pages only")
14+
15+
def __str__(self):
16+
"""Return the banner title."""
17+
return self.title

banners/templatetags/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Template tags for the banners app."""

banners/templatetags/banners.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Template tags for rendering active banners on the site."""
2+
13
from django import template
24
from django.template.loader import render_to_string
35

@@ -18,11 +20,13 @@ def _render_banner(banner=None):
1820

1921
@register.simple_tag
2022
def render_active_banner():
23+
"""Render the active site-wide banner, excluding PSF-only banners."""
2124
banner = Banner.objects.filter(active=True, psf_pages_only=False).first()
2225
return _render_banner(banner=banner)
2326

2427

2528
@register.simple_tag
2629
def render_active_psf_banner():
30+
"""Render the active banner for PSF pages."""
2731
banner = Banner.objects.filter(active=True).first()
2832
return _render_banner(banner=banner)

blogs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Blog aggregation and display for python.org."""

blogs/admin.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
1+
"""Admin configuration for the blogs app."""
2+
13
from django.contrib import admin
24
from django.core.management import call_command
35

4-
from .models import BlogEntry, Feed, FeedAggregate
6+
from blogs.models import BlogEntry, Feed, FeedAggregate
57

68

79
@admin.register(BlogEntry)
810
class BlogEntryAdmin(admin.ModelAdmin):
9-
list_display = ['title', 'pub_date']
10-
date_hierarchy = 'pub_date'
11-
actions = ['sync_new_entries']
11+
"""Admin interface for blog entries imported from RSS feeds."""
12+
13+
list_display = ["title", "pub_date"]
14+
date_hierarchy = "pub_date"
15+
actions = ["sync_new_entries"]
1216

13-
@admin.action(
14-
description="Sync new blog entries"
15-
)
17+
@admin.action(description="Sync new blog entries")
1618
def sync_new_entries(self, request, queryset):
17-
call_command('update_blogs')
19+
"""Trigger the update_blogs management command to sync new entries."""
20+
call_command("update_blogs")
1821
self.message_user(request, "Blog entries updated.")
1922

2023

21-
2224
@admin.register(FeedAggregate)
2325
class FeedAggregateAdmin(admin.ModelAdmin):
24-
list_display = ['name', 'slug', 'description']
25-
prepopulated_fields = {'slug': ('name',)}
26+
"""Admin interface for managing feed aggregates."""
27+
28+
list_display = ["name", "slug", "description"]
29+
prepopulated_fields = {"slug": ("name",)}
30+
2631

2732
admin.site.register(Feed)

0 commit comments

Comments
 (0)