本文整理汇总了Python中django.contrib.syndication.views.Feed方法的典型用法代码示例。如果您正苦于以下问题:Python views.Feed方法的具体用法?Python views.Feed怎么用?Python views.Feed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.syndication.views
的用法示例。
在下文中一共展示了views.Feed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_dynamic_attr
# 需要导入模块: from django.contrib.syndication import views [as 别名]
# 或者: from django.contrib.syndication.views import Feed [as 别名]
def _get_dynamic_attr(self, attname, obj, default=None):
"""
Copied from django.contrib.syndication.views.Feed (v1.7.1)
"""
try:
attr = getattr(self, attname)
except AttributeError:
return default
if callable(attr):
num_args = len(signature(attr).parameters)
if num_args == 0:
return attr()
if num_args == 1:
return attr(obj)
raise TypeError(
"Number of arguments to _get_dynamic_attr needs to be 0 or 1"
)
return attr
# NOTE: Not used by icalendar but required
# by the Django syndication framework.
示例2: __call__
# 需要导入模块: from django.contrib.syndication import views [as 别名]
# 或者: from django.contrib.syndication.views import Feed [as 别名]
def __call__(self, request, *args, **kwargs):
"""
Copied from django.contrib.syndication.views.Feed
Supports file_name as a dynamic attr.
"""
try:
obj = self.get_object(request, *args, **kwargs)
except ObjectDoesNotExist:
raise Http404("Feed object does not exist.")
feedgen = self.get_feed(obj, request)
response = HttpResponse(
content_type="text/calendar, text/x-vcalendar, application/hbs-vcs"
)
if hasattr(self, "item_pubdate") or hasattr(self, "item_updateddate"):
# if item_pubdate or item_updateddate is defined for the feed, set
# header so as ConditionalGetMiddleware is able to send 304 NOT MODIFIED
response["Last-Modified"] = http_date(
timegm(feedgen.latest_post_date().utctimetuple())
)
feedgen.write(response, "utf-8")
filename = self._get_dynamic_attr("file_name", obj)
if filename:
response["Content-Disposition"] = 'attachment; filename="%s"' % filename
return response
示例3: title
# 需要导入模块: from django.contrib.syndication import views [as 别名]
# 或者: from django.contrib.syndication.views import Feed [as 别名]
def title(self, obj):
return '%s - %s Jobs Feed' % (obj.site.name, obj.name)