Fix typing issues
This commit is contained in:
parent
34dcf63a93
commit
981d0ada4d
2 changed files with 9 additions and 4 deletions
|
@ -1,4 +1,8 @@
|
|||
from typing import Any
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.utils.feedgenerator import DefaultFeed
|
||||
from django.utils.xmlutils import SimplerXMLGenerator
|
||||
|
||||
|
||||
class CustomFeed(DefaultFeed):
|
||||
|
@ -6,11 +10,11 @@ class CustomFeed(DefaultFeed):
|
|||
A custom feed generator with additional features.
|
||||
"""
|
||||
|
||||
def __init__(self, request, **kwargs):
|
||||
def __init__(self, request: HttpRequest, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
self.request = request
|
||||
|
||||
def add_root_elements(self, handler) -> None:
|
||||
def add_root_elements(self, handler: SimplerXMLGenerator) -> None:
|
||||
super().add_root_elements(handler)
|
||||
handler.startElement("image", {})
|
||||
handler.addQuickElement("url", self.request.build_absolute_uri("favicon.ico"))
|
||||
|
|
|
@ -89,7 +89,7 @@ class AllPagesFeed(Feed):
|
|||
|
||||
return response
|
||||
|
||||
def feed_extra_kwargs(self, obj):
|
||||
def feed_extra_kwargs(self, obj: None) -> dict:
|
||||
return {**super().feed_extra_kwargs(obj), "request": self.request}
|
||||
|
||||
def title(self) -> str:
|
||||
|
@ -124,9 +124,10 @@ class AllPagesFeed(Feed):
|
|||
def item_description(self, item: BasePage) -> str:
|
||||
return getattr(item, "summary", None) or item.title
|
||||
|
||||
def item_categories(self, item: BasePage):
|
||||
def item_categories(self, item: BasePage) -> Optional[list[str]]:
|
||||
if tags := getattr(item, "tags", None):
|
||||
return tags.order_by("slug").values_list("slug", flat=True)
|
||||
return None
|
||||
|
||||
def item_enclosure_url(self, item: BasePage) -> Optional[str]:
|
||||
if not hasattr(item, "get_meta_image_url"):
|
||||
|
|
Loading…
Reference in a new issue