Skip to content
Open

ruff #2882

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/adamchainz/django-upgrade
rev: 1.29.1
hooks:
- id: django-upgrade
args: [--target-version=4.2]
args: [--target-version=5.2]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand Down
1 change: 1 addition & 0 deletions banners/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Banner management for displaying site-wide announcements."""
4 changes: 4 additions & 0 deletions banners/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
"""Admin configuration for the banners app."""

from django.contrib import admin

from banners.models import Banner


@admin.register(Banner)
class BannerAdmin(admin.ModelAdmin):
"""Admin interface for managing site-wide banners."""

list_display = ("title", "active", "psf_pages_only")
5 changes: 4 additions & 1 deletion banners/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Django app configuration for the banners app."""

from django.apps import AppConfig


class BannersAppConfig(AppConfig):
"""App configuration for the banners app."""

name = 'banners'
name = "banners"
17 changes: 4 additions & 13 deletions banners/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = []
Expand All @@ -31,27 +30,19 @@ class Migration(migrations.Migration):
),
(
"message",
models.CharField(
help_text="Message to display in the banner", max_length=2048
),
models.CharField(help_text="Message to display in the banner", max_length=2048),
),
(
"link",
models.CharField(
help_text="Link the button will go to", max_length=1024
),
models.CharField(help_text="Link the button will go to", max_length=1024),
),
(
"active",
models.BooleanField(
default=False, help_text="Make the banner active on the site"
),
models.BooleanField(default=False, help_text="Make the banner active on the site"),
),
(
"psf_pages_only",
models.BooleanField(
default=True, help_text="Display the banner on /psf pages only"
),
models.BooleanField(default=True, help_text="Display the banner on /psf pages only"),
),
],
)
Expand Down
23 changes: 11 additions & 12 deletions banners/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Models for site-wide announcement banners."""

from django.db import models


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

title = models.CharField(
max_length=1024, help_text="Text to display in the banner's button"
)
message = models.CharField(
max_length=2048, help_text="Message to display in the banner"
)
title = models.CharField(max_length=1024, help_text="Text to display in the banner's button")
message = models.CharField(max_length=2048, help_text="Message to display in the banner")
link = models.CharField(max_length=1024, help_text="Link the button will go to")
active = models.BooleanField(
null=False, default=False, help_text="Make the banner active on the site"
)
psf_pages_only = models.BooleanField(
null=False, default=True, help_text="Display the banner on /psf pages only"
)
active = models.BooleanField(null=False, default=False, help_text="Make the banner active on the site")
psf_pages_only = models.BooleanField(null=False, default=True, help_text="Display the banner on /psf pages only")

def __str__(self):
"""Return the banner title."""
return self.title
1 change: 1 addition & 0 deletions banners/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Template tags for the banners app."""
4 changes: 4 additions & 0 deletions banners/templatetags/banners.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Template tags for rendering active banners on the site."""

from django import template
from django.template.loader import render_to_string

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

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


@register.simple_tag
def render_active_psf_banner():
"""Render the active banner for PSF pages."""
banner = Banner.objects.filter(active=True).first()
return _render_banner(banner=banner)
1 change: 1 addition & 0 deletions blogs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Blog aggregation and display for python.org."""
27 changes: 16 additions & 11 deletions blogs/admin.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
"""Admin configuration for the blogs app."""

from django.contrib import admin
from django.core.management import call_command

from .models import BlogEntry, Feed, FeedAggregate
from blogs.models import BlogEntry, Feed, FeedAggregate


@admin.register(BlogEntry)
class BlogEntryAdmin(admin.ModelAdmin):
list_display = ['title', 'pub_date']
date_hierarchy = 'pub_date'
actions = ['sync_new_entries']
"""Admin interface for blog entries imported from RSS feeds."""

list_display = ["title", "pub_date"]
date_hierarchy = "pub_date"
actions = ["sync_new_entries"]

@admin.action(
description="Sync new blog entries"
)
@admin.action(description="Sync new blog entries")
def sync_new_entries(self, request, queryset):
call_command('update_blogs')
"""Trigger the update_blogs management command to sync new entries."""
call_command("update_blogs")
self.message_user(request, "Blog entries updated.")



@admin.register(FeedAggregate)
class FeedAggregateAdmin(admin.ModelAdmin):
list_display = ['name', 'slug', 'description']
prepopulated_fields = {'slug': ('name',)}
"""Admin interface for managing feed aggregates."""

list_display = ["name", "slug", "description"]
prepopulated_fields = {"slug": ("name",)}


admin.site.register(Feed)
5 changes: 4 additions & 1 deletion blogs/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Django app configuration for the blogs app."""

from django.apps import AppConfig


class BlogsAppConfig(AppConfig):
"""App configuration for the blogs app."""

name = 'blogs'
name = "blogs"
15 changes: 9 additions & 6 deletions blogs/factories.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
"""Factory functions for creating blog test and seed data."""

from django.conf import settings

from .models import Feed
from blogs.models import Feed


def initial_data():
"""Create and return the default Python Insider blog feed."""
feed, _ = Feed.objects.get_or_create(
id=1,
defaults={
'name': 'Python Insider',
'website_url': settings.PYTHON_BLOG_URL,
'feed_url': settings.PYTHON_BLOG_FEED_URL,
}
"name": "Python Insider",
"website_url": settings.PYTHON_BLOG_URL,
"feed_url": settings.PYTHON_BLOG_FEED_URL,
},
)
return {
'feeds': [feed],
"feeds": [feed],
}
1 change: 1 addition & 0 deletions blogs/management/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Management commands for the blogs app."""
12 changes: 7 additions & 5 deletions blogs/management/commands/update_blogs.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
from django.core.management.base import BaseCommand
from django.utils.timezone import now

from ...models import BlogEntry, RelatedBlog, Feed
from ...parser import get_all_entries, update_blog_supernav
from blogs.models import BlogEntry, Feed, RelatedBlog
from blogs.parser import get_all_entries, update_blog_supernav


class Command(BaseCommand):
""" Update blog entries and related blog feed data """
"""Update blog entries and related blog feed data"""

def handle(self, **options):
for feed in Feed.objects.all():
entries = get_all_entries(feed.feed_url)

for entry in entries:
url = entry.pop('url')
url = entry.pop("url")
BlogEntry.objects.update_or_create(
feed=feed, url=url, defaults=entry,
feed=feed,
url=url,
defaults=entry,
)

feed.last_import = now()
Expand Down
Loading