mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[4.1.x] Fixed #22078 -- Fixed crash of Feed with decorated methods.
Backport of 8c0886b068 from main.
This commit is contained in:
committed by
Mariusz Felisiak
parent
9d3b812001
commit
0210dbcbe3
@@ -1,3 +1,5 @@
|
||||
from functools import wraps
|
||||
|
||||
from django.contrib.syndication import views
|
||||
from django.utils import feedgenerator
|
||||
from django.utils.timezone import get_fixed_timezone
|
||||
@@ -5,6 +7,23 @@ from django.utils.timezone import get_fixed_timezone
|
||||
from .models import Article, Entry
|
||||
|
||||
|
||||
def wraps_decorator(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
value = f(*args, **kwargs)
|
||||
return f"{value} -- decorated by @wraps."
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def common_decorator(f):
|
||||
def wrapper(*args, **kwargs):
|
||||
value = f(*args, **kwargs)
|
||||
return f"{value} -- common decorated."
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
class TestRss2Feed(views.Feed):
|
||||
title = "My blog"
|
||||
description = "A more thorough description of my blog."
|
||||
@@ -39,11 +58,45 @@ class TestRss2Feed(views.Feed):
|
||||
item_copyright = "Copyright (c) 2007, Sally Smith"
|
||||
|
||||
|
||||
class TestRss2FeedWithStaticMethod(TestRss2Feed):
|
||||
class TestRss2FeedWithDecoratedMethod(TestRss2Feed):
|
||||
class TimeToLive:
|
||||
@wraps_decorator
|
||||
def __call__(self):
|
||||
return 800
|
||||
|
||||
@staticmethod
|
||||
@wraps_decorator
|
||||
def feed_copyright():
|
||||
return "Copyright (c) 2022, John Doe"
|
||||
|
||||
ttl = TimeToLive()
|
||||
|
||||
@staticmethod
|
||||
def categories():
|
||||
return ("javascript", "vue")
|
||||
|
||||
@wraps_decorator
|
||||
def title(self):
|
||||
return "Overridden title"
|
||||
|
||||
@wraps_decorator
|
||||
def item_title(self, item):
|
||||
return f"Overridden item title: {item.title}"
|
||||
|
||||
@wraps_decorator
|
||||
def description(self, obj):
|
||||
return "Overridden description"
|
||||
|
||||
@wraps_decorator
|
||||
def item_description(self):
|
||||
return "Overridden item description"
|
||||
|
||||
|
||||
class TestRss2FeedWithWrongDecoratedMethod(TestRss2Feed):
|
||||
@common_decorator
|
||||
def item_description(self, item):
|
||||
return f"Overridden item description: {item.title}"
|
||||
|
||||
|
||||
class TestRss2FeedWithGuidIsPermaLinkTrue(TestRss2Feed):
|
||||
def item_guid_is_permalink(self, item):
|
||||
|
||||
Reference in New Issue
Block a user