本文整理匯總了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)