Example #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
Example #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
Example #3
0
 def test_explicit_apphooks(self):
     """
     Test explicit apphook loading with the POSER_APPHOOKS setting.
     """
     apphooks = ("%s.%s" % (APP_MODULE, APP_NAME),)
     with SettingsOverride(POSER_APPHOOKS=apphooks):
         apphook_pool.clear()
         hooks = apphook_pool.get_apphooks()
         app_names = [hook[0] for hook in hooks]
         self.assertEqual(len(hooks), 1)
         self.assertEqual(app_names, [APP_NAME])
         apphook_pool.clear()
Example #4
0
 def test_implicit_apphooks(self):
     """
     Test implicit apphook loading with INSTALLED_APPS + poser_app.py
     """
         
     apps = ['poser.test_utils.project.sampleapp']
     with SettingsOverride(INSTALLED_APPS=apps, ROOT_URLCONF='poser.test_utils.project.urls_for_apphook_tests'):
         apphook_pool.clear()
         hooks = apphook_pool.get_apphooks()
         app_names = [hook[0] for hook in hooks]
         self.assertEqual(len(hooks), 1)
         self.assertEqual(app_names, [APP_NAME])
         apphook_pool.clear()
Example #5
0
    def test_implicit_apphooks(self):
        """
        Test implicit apphook loading with INSTALLED_APPS + poser_app.py
        """

        apps = ["poser.test_utils.project.sampleapp"]
        with SettingsOverride(INSTALLED_APPS=apps, ROOT_URLCONF="poser.test_utils.project.urls_for_apphook_tests"):
            apphook_pool.clear()
            hooks = apphook_pool.get_apphooks()
            app_names = [hook[0] for hook in hooks]
            self.assertEqual(len(hooks), 1)
            self.assertEqual(app_names, [APP_NAME])
            apphook_pool.clear()
Example #6
0
 def test_explicit_apphooks(self):
     """
     Test explicit apphook loading with the POSER_APPHOOKS setting.
     """
     apphooks = (
         '%s.%s' % (APP_MODULE, APP_NAME),
     )
     with SettingsOverride(POSER_APPHOOKS=apphooks):
         apphook_pool.clear()
         hooks = apphook_pool.get_apphooks()
         app_names = [hook[0] for hook in hooks]
         self.assertEqual(len(hooks), 1)
         self.assertEqual(app_names, [APP_NAME])
         apphook_pool.clear()
Example #7
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)
# -*- coding: utf-8 -*-
from poser.apphook_pool import apphook_pool
from poser.views import details
from django.conf import settings
from django.conf.urls.defaults import url, patterns

if settings.APPEND_SLASH:
    reg = url(r'^(?P<slug>[0-9A-Za-z-_.//]+)/$',
              details,
              name='pages-details-by-slug')
else:
    reg = url(r'^(?P<slug>[0-9A-Za-z-_.//]+)$',
              details,
              name='pages-details-by-slug')

urlpatterns = [
    # Public pages
    url(r'^$', details, {'slug': ''}, name='pages-root'),
    reg,
]

if apphook_pool.get_apphooks():
    """If there are some application urls, add special resolver, so we will
    have standard reverse support.
    """
    from poser.appresolver import get_app_patterns
    urlpatterns = get_app_patterns() + urlpatterns

urlpatterns = patterns('', *urlpatterns)
# -*- coding: utf-8 -*-
from poser.apphook_pool import apphook_pool
from poser.views import details
from django.conf import settings
from django.conf.urls.defaults import url, patterns

if settings.APPEND_SLASH:
    reg = url(r'^(?P<slug>[0-9A-Za-z-_.//]+)/$', details, name='pages-details-by-slug')
else:
    reg = url(r'^(?P<slug>[0-9A-Za-z-_.//]+)$', details, name='pages-details-by-slug')

urlpatterns = [
    # Public pages
    url(r'^$', details, {'slug':''}, name='pages-root'),
    reg,
]

if apphook_pool.get_apphooks():
    """If there are some application urls, add special resolver, so we will
    have standard reverse support.
    """
    from poser.appresolver import get_app_patterns
    urlpatterns = get_app_patterns() + urlpatterns
    
urlpatterns = patterns('', *urlpatterns)