示例#1
0
 def dehydrate(self, bundle):
     """
     populates the bundle.data with the application model associated
     """
     if apphook_pool.get_apphooks():
         # There are apphooks in the pool. Let's see if there is one for the
         # current page
         # since we always have a page at this point, applications_page_check is
         # pointless
         # page = applications_page_check(request, page, slug)
         # Check for apphooks! This time for real!
         apphook_name = bundle.obj.get_application()
         if apphook_name:
             apphook = apphook_pool.get_apphook(apphook_name)
             mod = __import__(apphook.module, fromlist=[apphook.klass])
             klass = getattr(mod, apphook.klass)
             if klass:
                 resource = klass()
                 try:
                     obj = resource.obj_get(page__id=bundle.obj.id)
                     appbundle = resource.build_bundle(obj=obj,
                                                       request=bundle.request)
                     appbundle = resource.full_dehydrate(appbundle)
                     bundle.data['application'] = appbundle
                 except resource._meta.object_class.DoesNotExist:
                     pass
     return bundle
示例#2
0
 def dehydrate(self, bundle):
     """
     populates the bundle.data with the application model associated
     """
     if apphook_pool.get_apphooks():
         # There are apphooks in the pool. Let's see if there is one for the
         # current page
         # since we always have a page at this point, applications_page_check is
         # pointless
         # page = applications_page_check(request, page, slug)
         # Check for apphooks! This time for real!
         apphook_name = bundle.obj.get_application()
         if apphook_name:
             apphook = apphook_pool.get_apphook(apphook_name)
             mod = __import__(apphook.module, fromlist=[apphook.klass])
             klass = getattr(mod, apphook.klass)
             if klass:
                 resource = klass()
                 try:
                     obj = resource.obj_get(page__id=bundle.obj.id)
                     appbundle = resource.build_bundle(
                         obj=obj, request=bundle.request)
                     appbundle = resource.full_dehydrate(appbundle)
                     bundle.data['application'] = appbundle
                 except resource._meta.object_class.DoesNotExist:
                     pass
     return bundle
示例#3
0
    def test_apphook_by_class(self):
        if APP_MODULE in sys.modules:
            del sys.modules[APP_MODULE]
        apphooks = (
            '%s.%s' % (APP_MODULE, APP_NAME),
        )

        with SettingsOverride(POSER_APPHOOKS=apphooks):
            apphook_pool.clear()
            apphook = apphook_pool.get_apphook(APP_NAME)
            page = create_page(apphook=apphook,
                               **self._get_default_create_page_arguments())
            self.assertEqual(page.get_application_urls(), APP_NAME)
示例#4
0
def get_patterns_for_page(path, page):
    """
    Resolve the urlconf module for a path+title combination
    Returns a list of url objects.
    """
    app = apphook_pool.get_apphook(page.application)
    patterns_page = []
    for pattern_list in get_app_urls(app.urls):
        if path and not path.endswith('/'):
            path += '/'
        page_id = page.id
        patterns_page += recurse_patterns(path, pattern_list, page_id)
    patterns_page = _flatten_patterns(patterns_page)
    return patterns_page
示例#5
0
def get_patterns_for_page(path, page):
    """
    Resolve the urlconf module for a path+title combination
    Returns a list of url objects.
    """
    app = apphook_pool.get_apphook(page.application)
    patterns_page = []
    for pattern_list in get_app_urls(app.urls):
        if path and not path.endswith('/'):
            path += '/'
        page_id = page.id
        patterns_page += recurse_patterns(path, pattern_list, page_id)
    patterns_page = _flatten_patterns(patterns_page)
    return patterns_page
示例#6
0
def details(request, slug):
    """
    Takes a request and a slug, renders the page's template.
    """
    # Get a Page model object from the request
    page = get_page_from_request(request, use_path=slug)
    if not page:
        return _handle_no_page(request, slug)

    # Check if the page has a redirect url defined
    redirect_url = page.get_redirect()
    if redirect_url:
        # prevent redirect to self
        own_urls = [
            'http%s://%s%s' % ('s' if request.is_secure() else '', request.get_host(), request.path),
            '/%s' % (request.path),
            request.path,
        ]
        if redirect_url not in own_urls:
            return HttpResponseRedirect(redirect_url)

    if not page.has_view_permission(request):
        return _handle_no_page(request, slug)

    if apphook_pool.get_apphooks():
        # There are apphooks in the pool. Let's see if there is one for the
        # current page
        # since we always have a page at this point, applications_page_check() is
        # pointless
        app_name = page.get_application()
        if app_name:
            app = apphook_pool.get_apphook(app_name)
            pattern_list = []
            for urlpatterns in get_app_urls(app.urls):
                pattern_list += urlpatterns
            urlpatterns = patterns('', *pattern_list)
            try:
                view, args, kwargs = resolve('/', tuple(urlpatterns))
                return view(request, *args, **kwargs)
            except Resolver404:
                pass
        else:
            return _handle_no_page(request, slug)