Exemple #1
0
def _verify_apphook(apphook, namespace):
    """
    Verifies the apphook given is valid and returns the normalized form (name)
    """
    apphook_pool.discover_apps()
    if isinstance(apphook, CMSApp):
        try:
            assert apphook.__class__ in [app.__class__ for app in apphook_pool.apps.values()]
        except AssertionError:
            print(apphook_pool.apps.values())
            raise
        apphook_name = apphook.__class__.__name__
    elif hasattr(apphook, '__module__') and issubclass(apphook, CMSApp):
        return apphook.__name__
    elif isinstance(apphook, six.string_types):
        try:
            assert apphook in apphook_pool.apps
        except AssertionError:
            print(apphook_pool.apps.values())
            raise
        apphook_name = apphook
    else:
        raise TypeError("apphook must be string or CMSApp instance")
    if apphook_pool.apps[apphook_name].app_name and not namespace:
        raise ValidationError('apphook with app_name must define a namespace')
    return apphook_name
Exemple #2
0
def _verify_apphook(apphook, namespace):
    """
    Verifies the apphook given is valid and returns the normalized form (name)
    """
    apphook_pool.discover_apps()
    if isinstance(apphook, CMSApp):
        try:
            assert apphook.__class__ in [app.__class__ for app in apphook_pool.apps.values()]
        except AssertionError:
            print(apphook_pool.apps.values())
            raise
        apphook_name = apphook.__class__.__name__
    elif hasattr(apphook, '__module__') and issubclass(apphook, CMSApp):
        return apphook.__name__
    elif isinstance(apphook, six.string_types):
        try:
            assert apphook in apphook_pool.apps
        except AssertionError:
            print(apphook_pool.apps.values())
            raise
        apphook_name = apphook
    else:
        raise TypeError("apphook must be string or CMSApp instance")
    if apphook_pool.apps[apphook_name].app_name and not namespace:
        raise ValidationError('apphook with app_name must define a namespace')
    return apphook_name
Exemple #3
0
 def clean(self):
     cleaned_data = super(AdvancedSettingsForm, self).clean()
     if 'reverse_id' in self.fields:
         id = cleaned_data['reverse_id']
         site_id = cleaned_data['site']
         if id:
             if Page.objects.filter(reverse_id=id,
                                    site=site_id,
                                    publisher_is_draft=True).exclude(
                                        pk=self.instance.pk).count():
                 self._errors['reverse_id'] = self.error_class(
                     [_('A page with this reverse URL id exists already.')])
     apphook = cleaned_data.get('application_urls', None)
     namespace = cleaned_data.get('application_namespace', None)
     if apphook:
         apphook_pool.discover_apps()
         if apphook_pool.apps[apphook].app_name and not namespace:
             self._errors['application_urls'] = ErrorList([
                 _('You selected an apphook with an "app_name". You must enter a instance name.'
                   )
             ])
     if namespace and not apphook:
         self._errors['application_namespace'] = ErrorList([
             _("If you enter an instance name you need an application url as well."
               )
         ])
     return cleaned_data
Exemple #4
0
def _verify_apphook(apphook):
    """
    Verifies the apphook given is valid and returns the normalized form (name)
    """
    if hasattr(apphook, '__module__') and  issubclass(apphook, CMSApp):
        apphook_pool.discover_apps()
        assert apphook in apphook_pool.apps.values()
        return apphook.__name__
    elif isinstance(apphook, basestring):
        apphook_pool.discover_apps()
        assert apphook in apphook_pool.apps
        return apphook
    else:
        raise TypeError("apphook must be string or CMSApp instance")
Exemple #5
0
def _verify_apphook(apphook):
    """
    Verifies the apphook given is valid and returns the normalized form (name)
    """
    if hasattr(apphook, '__module__') and issubclass(apphook, CMSApp):
        apphook_pool.discover_apps()
        assert apphook in apphook_pool.apps.values()
        return apphook.__name__
    elif isinstance(apphook, basestring):
        apphook_pool.discover_apps()
        assert apphook in apphook_pool.apps
        return apphook
    else:
        raise TypeError("apphook must be string or CMSApp instance")
Exemple #6
0
    def clean(self):
        cleaned_data = super(AdvancedSettingsForm, self).clean()
        if 'reverse_id' in self.fields:
            id = cleaned_data['reverse_id']
            site_id = cleaned_data['site']
            if id:
                if Page.objects.filter(reverse_id=id,
                                       site=site_id,
                                       publisher_is_draft=True).exclude(
                                           pk=self.instance.pk).count():
                    self._errors['reverse_id'] = self.error_class(
                        [_('A page with this reverse URL id exists already.')])
        apphook = cleaned_data.get('application_urls', None)
        # The field 'application_namespace' is a misnomer. It should be
        # 'instance_namespace'.
        instance_namespace = cleaned_data.get('application_namespace', None)
        if apphook:
            apphook_pool.discover_apps()
            # The attribute on the apps 'app_name' is a misnomer, it should be
            # 'application_namespace'.
            application_namespace = apphook_pool.apps[apphook].app_name
            if application_namespace and not instance_namespace:
                if Page.objects.filter(
                        publisher_is_draft=True,
                        application_urls=apphook,
                        application_namespace=application_namespace).exclude(
                            pk=self.instance.pk).count():
                    # Looks like there's already one with the default instance
                    # namespace defined.
                    self._errors['application_urls'] = ErrorList([
                        _('''You selected an apphook with an "app_name".
                            You must enter a unique instance name.''')
                    ])
                else:
                    # OK, there are zero instances of THIS app that use the
                    # default instance namespace, so, since the user didn't
                    # provide one, we'll use the default. NOTE: The following
                    # line is really setting the "instance namespace" of the
                    # new app to the app’s "application namespace", which is
                    # the default instance namespace.
                    self.cleaned_data[
                        'application_namespace'] = application_namespace

        if instance_namespace and not apphook:
            self.cleaned_data['application_namespace'] = None

        return cleaned_data
Exemple #7
0
    def clean(self):
        cleaned_data = super(AdvancedSettingsForm, self).clean()
        if 'reverse_id' in self.fields:
            id = cleaned_data['reverse_id']
            site_id = cleaned_data['site']
            if id:
                if Page.objects.filter(reverse_id=id, site=site_id, publisher_is_draft=True).exclude(
                        pk=self.instance.pk).count():
                    self._errors['reverse_id'] = self.error_class(
                        [_('A page with this reverse URL id exists already.')])
        apphook = cleaned_data.get('application_urls', None)
        # The field 'application_namespace' is a misnomer. It should be
        # 'instance_namespace'.
        instance_namespace = cleaned_data.get('application_namespace', None)
        if apphook:
            apphook_pool.discover_apps()
            # The attribute on the apps 'app_name' is a misnomer, it should be
            # 'application_namespace'.
            application_namespace = apphook_pool.apps[apphook].app_name
            if application_namespace and not instance_namespace:
                if Page.objects.filter(
                    publisher_is_draft=True,
                    application_urls=apphook,
                    application_namespace=application_namespace
                ).exclude(pk=self.instance.pk).count():
                    # Looks like there's already one with the default instance
                    # namespace defined.
                    self._errors['application_urls'] = ErrorList([
                        _('''You selected an apphook with an "app_name".
                            You must enter a unique instance name.''')
                    ])
                else:
                    # OK, there are zero instances of THIS app that use the
                    # default instance namespace, so, since the user didn't
                    # provide one, we'll use the default. NOTE: The following
                    # line is really setting the "instance namespace" of the
                    # new app to the app’s "application namespace", which is
                    # the default instance namespace.
                    self.cleaned_data['application_namespace'] = application_namespace

        if instance_namespace and not apphook:
            self.cleaned_data['application_namespace'] = None

        return cleaned_data
Exemple #8
0
 def clean(self):
     cleaned_data = super(AdvancedSettingsForm, self).clean()
     if 'reverse_id' in self.fields:
         id = cleaned_data['reverse_id']
         site_id = cleaned_data['site']
         if id:
             if Page.objects.filter(reverse_id=id, site=site_id, publisher_is_draft=True).exclude(
                     pk=self.instance.pk).count():
                 self._errors['reverse_id'] = self.error_class(
                     [_('A page with this reverse URL id exists already.')])
     apphook = cleaned_data['application_urls']
     namespace = cleaned_data['application_namespace']
     if apphook:
         apphook_pool.discover_apps()
         if apphook_pool.apps[apphook].app_name and not namespace:
             self._errors['application_urls'] = ErrorList(
                 [_('You selected an apphook with an "app_name". You must enter a namespace.')])
     if namespace and not apphook:
         self._errors['application_namespace'] = ErrorList(
             [_("If you enter a namespace you need an application url as well.")])
     return cleaned_data
Exemple #9
0
# -*- coding: utf-8 -*-
import cms.admin.pageadmin
import cms.admin.useradmin
import cms.admin.permissionadmin
import cms.admin.settingsadmin
import cms.admin.static_placeholder  # nopyflakes
# Piggyback off admin.autodiscover() to discover cms plugins
from cms import plugin_pool
from cms.apphook_pool import apphook_pool
plugin_pool.plugin_pool.discover_plugins()

apphook_pool.discover_apps()