예제 #1
0
        '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
0
파일: models.py 프로젝트: skyl/djragon-cms
            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
0
    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)
"""