本文整理汇总了Python中feincms.module.page.models.Page.register_request_processors方法的典型用法代码示例。如果您正苦于以下问题:Python Page.register_request_processors方法的具体用法?Python Page.register_request_processors怎么用?Python Page.register_request_processors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feincms.module.page.models.Page
的用法示例。
在下文中一共展示了Page.register_request_processors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ApplicationContentHandler
# 需要导入模块: from feincms.module.page.models import Page [as 别名]
# 或者: from feincms.module.page.models.Page import register_request_processors [as 别名]
'extra_path': '/',
})
if request.path != page.get_absolute_url():
# The best_match logic kicked in. See if we have at least one
# application content for this page, and raise a 404 otherwise.
if not page.content.all_of_type(ApplicationContent):
if not settings.FEINCMS_ALLOW_EXTRA_PATH:
raise Http404
else:
request._feincms_extra_context['in_appcontent_subpage'] = True
request._feincms_extra_context['extra_path'] = re.sub(
'^' + re.escape(page.get_absolute_url()[:-1]), '', request.path)
Page.register_request_processors(applicationcontent_request_processor)
class ApplicationContentHandler(Handler):
"""
This handler is almost the same as the default handler. The only difference
is that it uses ``best_match_for_path``, not ``page_for_path``. Because of
this fact it handles URLs which do not exactly match up with any page in
the database.
"""
def __call__(self, request, path=None):
return self.build_response(request,
Page.objects.best_match_for_path(path or request.path, raise404=True))
handler = ApplicationContentHandler()
示例2: authenticated_request_processor
# 需要导入模块: from feincms.module.page.models import Page [as 别名]
# 或者: from feincms.module.page.models.Page import register_request_processors [as 别名]
label=_('Exclusive Subpages'),
required=False,
initial=form.instance.parameters.get('exclusive_subpages', False),
help_text=_('Exclude everything other than the application\'s content when rendering subpages.'),
),
}
Page.create_content_type(ApplicationContent, APPLICATIONS=(
('content.news_urls', 'News Articles', {'admin_fields': get_admin_fields}),
('content.blog_urls', 'Blogs and Opinions', {'admin_fields': get_admin_fields}),
))
Page.create_content_type(CommentsContent)
''' # Using page request processors
def authenticated_request_processor(page, request):
if not request.user.is_authenticated():
return HttpResponseForbidden()
Page.register_request_processors(authenticated_request_processor)
'''
''' # using page response processors
def set_random_header_response_processor(page, request, response):
response['X-Random-Number'] = 42
Page.register_response_processors(set_random_header_response_processor)
'''
'''
示例3: get_government_name
# 需要导入模块: from feincms.module.page.models import Page [as 别名]
# 或者: from feincms.module.page.models.Page import register_request_processors [as 别名]
def get_government_name(self):
return str(self.cleaned_data()['PrimeMinister']) + " " + self.cleaned_data()['TermStart'].strftime('%d%m%y') + self.cleaned_data()['TermStart'].strftime('%d%m%y')
def render(self,**kwargs):
url = 'http://www.legislation.gov.uk/search?type=%s&start-year=%s&end-year=%i&start-number=%i&end-number=%i&version=%i' % (str(self.type),datetime.date(self.TermStart).year,datetime.date(self.TermEnd).year)
# http://www.legislation.gov.uk/search?type={type}&start-year={year}&end-year={year}&start-number={number}&end-number={number}&version={version}
return feedparser.parse(url)
Page.create_content_type(RichTextContent)
Page.create_content_type(PoliticalTerm)
Page.create_content_type(MediaFileContent, TYPE_CHOICES=(
# ('default', _('default')),
('lightbox', _('lightbox')),
))
"""
# Very stupid etag function, a page is supposed the unchanged as long
# as its id and slug do not change. You definitely want something more
# involved, like including last change dates or whatever.
def my_etag(page, request):
return 'PAGE-%d-%s' % ( page.id, page.slug )
Page.etag = my_etag
Page.register_request_processors(Page.etag_request_processor)
Page.register_response_processors(Page.etag_response_processor)
"""