Ejemplo n.º 1
0
def select_product():
    """
    binds the frozen context the selected features

    should be called only once - calls after the first call have
    no effect
    """
    global _product_selected
    if _product_selected:
        # tss already bound ... ignore
        return

    _product_selected = True
    from django_productline import context, template

    featuremonkey.add_import_guard('django.conf')
    featuremonkey.add_import_guard('django.db')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'django_productline.settings'
    contextfile = os.environ['PRODUCT_CONTEXT_FILENAME']
    equationfile = os.environ['PRODUCT_EQUATION_FILENAME']

    #bind context and compose features
    context.bind_context(contextfile)
    get_composer().select_equation(equationfile)

    # after composition we are now able to bind composed template settings
    template.bind_settings()

    featuremonkey.remove_import_guard('django.conf')
    featuremonkey.remove_import_guard('django.db')

    import django
    if compare_version(django.get_version(), '1.7') >= 0:
        django.setup()
    # force import of settings and urls
    # better fail during initialization than on the first request
    from django.conf import settings
    from django.core.urlresolvers import get_resolver
    # eager creation of URLResolver
    get_resolver(None)

    # make sure overextends tag is registered
    from django.template.loader import get_template
    from overextends import models
Ejemplo n.º 2
0
def select_product():
    """
    binds the frozen context the selected features

    should be called only once - calls after the first call have
    no effect
    """
    global _product_selected
    if _product_selected:
        # tss already bound ... ignore
        return

    _product_selected = True
    from django_productline import context

    featuremonkey.add_import_guard("django.conf")
    featuremonkey.add_import_guard("django.db")
    os.environ["DJANGO_SETTINGS_MODULE"] = "django_productline.settings"
    contextfile = os.environ["PRODUCT_CONTEXT_FILENAME"]
    equationfile = os.environ["PRODUCT_EQUATION_FILENAME"]
    # bind context and compose features
    context.bind_context(contextfile)
    get_composer().select_equation(equationfile)
    featuremonkey.remove_import_guard("django.conf")
    featuremonkey.remove_import_guard("django.db")

    import django

    if compare_version(django.get_version(), "1.7") >= 0:
        django.setup()
    # force import of settings and urls
    # better fail during initialization than on the first request
    from django.conf import settings
    from django.core.urlresolvers import get_resolver

    # eager creation of URLResolver
    get_resolver(None)

    # make sure overextends tag is registered
    from django.template.loader import get_template
    from overextends import models
Ejemplo n.º 3
0
def bind_settings():
    """
    Put DJANGO_TEMPLATE_* under the right settings.* name according to django-version
    :return:
    """
    from django_productline import settings

    if settings.TEMPLATE_LOADER_CACHED_ENABLED:
        loaders = [[
            'django.template.loaders.cached.Loader',
            settings.DJANGO_TEMPLATE_LOADERS
        ]]
    else:
        loaders = settings.DJANGO_TEMPLATE_LOADERS

    if compare_version(django.get_version(), '1.9') >= 0:

        TEMPLATES = [
            {
                'BACKEND': settings.DJANGO_TEMPLATE_BACKEND,
                'DIRS': settings.DJANGO_TEMPLATE_DIRS,
                'OPTIONS': {
                    'builtins': settings.DJANGO_TEMPLATE_BUILTINS,
                    'context_processors':
                    settings.DJANGO_TEMPLATE_CONTEXT_PROCESSORS,
                    'loaders': loaders,
                    'debug': settings.DJANGO_TEMPLATE_DEBUG
                },
            },
        ]

        setattr(settings, 'TEMPLATES', TEMPLATES)

    else:
        setattr(settings, 'TEMPLATE_DEBUG', settings.DJANGO_TEMPLATE_DEBUG)
        setattr(settings, 'TEMPLATE_DIRS', settings.DJANGO_TEMPLATE_DIRS)
        setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS',
                settings.DJANGO_TEMPLATE_CONTEXT_PROCESSORS)
        setattr(settings, 'TEMPLATE_LOADERS', loaders)
Ejemplo n.º 4
0
def bind_settings():
    """
    Put DJANGO_TEMPLATE_* under the right settings.* name according to django-version
    :return:
    """
    from django_productline import settings

    if settings.TEMPLATE_LOADER_CACHED_ENABLED:
        loaders = [
            ['django.template.loaders.cached.Loader', settings.DJANGO_TEMPLATE_LOADERS]
        ]
    else:
        loaders = settings.DJANGO_TEMPLATE_LOADERS

    if compare_version(django.get_version(), '1.9') >= 0:

        TEMPLATES = [
            {
                'BACKEND': settings.DJANGO_TEMPLATE_BACKEND,
                'DIRS': settings.DJANGO_TEMPLATE_DIRS,
                'OPTIONS': {
                    'builtins': settings.DJANGO_TEMPLATE_BUILTINS,
                    'context_processors': settings.DJANGO_TEMPLATE_CONTEXT_PROCESSORS,
                    'loaders': loaders,
                    'debug': settings.DJANGO_TEMPLATE_DEBUG
                },
            },
        ]

        setattr(settings, 'TEMPLATES', TEMPLATES)

    else:
        setattr(settings, 'TEMPLATE_DEBUG', settings.DJANGO_TEMPLATE_DEBUG)
        setattr(settings, 'TEMPLATE_DIRS', settings.DJANGO_TEMPLATE_DIRS)
        setattr(settings, 'TEMPLATE_CONTEXT_PROCESSORS', settings.DJANGO_TEMPLATE_CONTEXT_PROCESSORS)
        setattr(settings, 'TEMPLATE_LOADERS', loaders)
Ejemplo n.º 5
0
    "django.template.context_processors.debug",
    "django.template.context_processors.i18n",
    "django.template.context_processors.media",
    "django.template.context_processors.static",
    "django.template.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    "django.template.context_processors.request",
]

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = [
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
]

if compare_version(django.get_version(), '1.9') >= 0:
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'OPTIONS': {
                'builtins': ['overextends.templatetags.overextends_tags'],
                'context_processors':
                TEMPLATE_CONTEXT_PROCESSORS,
                'loaders': [
                    'django.template.loaders.filesystem.Loader',
                    'django.template.loaders.app_directories.Loader',
                ]
            },
        },
    ]
Ejemplo n.º 6
0
# refinement for django_productline.settings
import django
from django_productline import compare_version


def refine_INSTALLED_APPS(original):
    return ['django_productline.features.djpladmin', 'django.contrib.admin', ] + list(original)


introduce_ADMIN_URL = 'admin/'

if (compare_version(django.get_version(), '1.9') >= 0):
    # WE use the TEMPLATES variable not prior to 1.9
    def refine_TEMPLATES(original):
        OPTIONS = original[0]['OPTIONS']
        OPTIONS['context_processors'] += [
            'django_productline.features.djpladmin.context_processors.django_admin'
        ]
        return original
else:

    def refine_TEMPLATE_CONTEXT_PROCESSORS(original):
        return list(original) + ['django_productline.features.djpladmin.context_processors.django_admin']

introduce_AUTH_GROUPS = {
    # {
    #    'name': 'Operator',
    #    'permissions': [
    #        ('add_mymodel', 'myapp'),
    #        ('change_my_model', 'myapp')
    #    ]
Ejemplo n.º 7
0
#refinement for django_productline.settings
import django
from django_productline import compare_version


def refine_INSTALLED_APPS(original):
    return ['django_productline.features.djpladmin', 'django.contrib.admin', ] + list(original)


introduce_ADMIN_URL = 'admin/'




if (compare_version(django.get_version(), '1.9') >= 0):
    # WE use the TEMPLATES variable not prior to 1.9
    def refine_TEMPLATES(original):
        OPTIONS = original[0]['OPTIONS']
        OPTIONS['context_processors'] += [
            'django_productline.features.djpladmin.context_processors.django_admin'
        ]
        return original
else:

    def refine_TEMPLATE_CONTEXT_PROCESSORS(original):
        return list(original) + ['django_productline.features.djpladmin.context_processors.django_admin']




Ejemplo n.º 8
0
    "django.template.context_processors.static",
    "django.template.context_processors.tz",
    "django.contrib.messages.context_processors.messages",
    "django.template.context_processors.request",
]

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = [
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
]




if compare_version(django.get_version(), '1.9') >= 0:
    TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',

            'OPTIONS': {
                'builtins': ['overextends.templatetags.overextends_tags'],
                'context_processors': TEMPLATE_CONTEXT_PROCESSORS,
                'loaders': [
                    'django.template.loaders.filesystem.Loader',
                    'django.template.loaders.app_directories.Loader',
                ]
            },
        },
    ]