Пример #1
0
def get_or_create_common_template(template_name,
                                  extension='.html',
                                  app_first=False,
                                  force=True,
                                  delete=False,
                                  prefix='',
                                  notfix=None):

    site = Site.objects.get_current()

    if not extension.startswith("."):
        extension = ".%s" % extension

    if app_first:
        tpl_dirs = merge(app_template_dirs, DIRS)
    else:
        tpl_dirs = merge(DIRS, app_template_dirs)
    templatedirs = [d for d in tpl_dirs if os.path.isdir(d)]

    template = None
    for templatedir in templatedirs:
        for dirpath, subdirs, filenames in os.walk(templatedir):
            for f in [
                    f for f in filenames
                    if f.endswith(extension) and not f.startswith(".")
            ]:
                path = os.path.join(dirpath, f)
                name = path.split(templatedir)[1]
                if name.startswith('/'):
                    name = name[1:]
                if template_name in name and prefix in path:
                    if notfix and notfix in path:
                        continue
                    try:
                        t = Template.on_site.get(name__exact=name)
                    except Template.DoesNotExist:
                        t = Template(name=name,
                                     content=codecs.open(path, "r").read())
                        t.save(sync_themes=False)
                        t.sites.add(site)

                    else:
                        if force:
                            t.content = codecs.open(path, 'r').read()
                            t.save(sync_themes=False)
                            t.sites.add(site)
                    template = t
    return template
    def handle(self, **options):
        self.set_options(**options)
        force = options.get('force', False)

        # base
        page_themes = 0

        tpl_dirs = merge(DIRS, app_template_dirs)
        templatedirs = [d for d in tpl_dirs if os.path.isdir(d)]

        for templatedir in templatedirs:
            for dirpath, subdirs, filenames in os.walk(templatedir):
                if 'base/page' in dirpath:
                    for f in filenames:
                        # ignore private and hidden members
                        if not f.startswith("_") and not f.startswith("."):
                            page_template = get_or_create_template(
                                f, force=force, prefix="base/page")
                            if not page_template:
                                self.stdout.write("Missing template %s" % f)
                                continue
                            # create themes with bases
                            try:
                                page_theme = PageTheme.objects.get(
                                    name=f.split(".")[0])
                            except PageTheme.DoesNotExist:
                                page_theme = PageTheme()
                                page_theme.label = '{} layout'.format(
                                    f.split(".")[0].title())
                                page_theme.name = f.split(".")[0]
                                page_theme.template = page_template
                                page_theme.save()
                                page_themes += 1

        if page_themes > 0:
            self.stdout.write(
                'Successfully created {} page themes'.format(page_themes))

        cmd = CollectStatic()
        cmd.stdout = self.stdout
        collect_static = cmd.handle(
            **{
                'interactive': False,
                'link': False,
                'clear': False,
                'dry_run': False,
                'ignore_patterns': [],
                'use_default_ignore_patterns': True,
                'post_process': True,
                'verbosity': 0
            })

        collected = self.collect()

        self.stdout.write("Page themes synced {}".format(
            self.page_themes_updated))
        self.stdout.write("Page Skins synced {}".format(self.skins_updated))
    def handle(self, **options):
        self.set_options(**options)
        force = options.get('force', False)

        # base
        page_themes = 0

        tpl_dirs = merge(DIRS, app_template_dirs)
        templatedirs = [d for d in tpl_dirs if os.path.isdir(d)]

        for templatedir in templatedirs:
            for dirpath, subdirs, filenames in os.walk(templatedir):
                if 'base/page' in dirpath:
                    for f in filenames:
                        # ignore private and hidden members
                        if not f.startswith("_") and not f.startswith("."):
                            page_template = get_or_create_template(
                                f, force=force, prefix="base/page")
                            if not page_template:
                                self.stdout.write("Missing template %s" % f)
                                continue
                            # create themes with bases
                            try:
                                page_theme = PageTheme.objects.get(
                                    name=f.split(".")[0])
                            except PageTheme.DoesNotExist:
                                page_theme = PageTheme()
                                page_theme.label = '{} layout'.format(
                                    f.split(".")[0].title())
                                page_theme.name = f.split(".")[0]
                                page_theme.template = page_template
                                page_theme.save()
                                page_themes += 1

        if page_themes > 0:
            self.stdout.write(
                'Successfully created {} page themes'.format(page_themes))

        cmd = CollectStatic()
        cmd.stdout = self.stdout
        collect_static = cmd.handle(
            **{'interactive': False,
                'link': False,
                'clear': False,
                'dry_run': False,
                'ignore_patterns': [],
                'use_default_ignore_patterns': True,
                'post_process': True,
                'verbosity': 0})

        collected = self.collect()

        self.stdout.write(
            "Page themes synced {}".format(self.page_themes_updated))
        self.stdout.write("Page Skins synced {}".format(self.skins_updated))
Пример #4
0
def get_or_create_common_template(template_name, extension='.html', app_first=False,
                           force=True, delete=False, prefix='', notfix=None):

    site = Site.objects.get_current()

    if not extension.startswith("."):
        extension = ".%s" % extension

    if app_first:
        tpl_dirs = merge(app_template_dirs, DIRS)
    else:
        tpl_dirs = merge(DIRS, app_template_dirs)
    templatedirs = [d for d in tpl_dirs if os.path.isdir(d)]

    template = None
    for templatedir in templatedirs:
        for dirpath, subdirs, filenames in os.walk(templatedir):
            for f in [f for f in filenames
                      if f.endswith(extension) and not f.startswith(".")]:
                path = os.path.join(dirpath, f)
                name = path.split(templatedir)[1]
                if name.startswith('/'):
                    name = name[1:]
                if template_name in name and prefix in path:
                    if notfix and notfix in path:
                        continue
                    try:
                        t = Template.on_site.get(name__exact=name)
                    except Template.DoesNotExist:
                        t = Template(name=name,
                                     content=codecs.open(path, "r").read())
                        t.save(sync_themes=False)
                        t.sites.add(site)

                    else:
                        if force:
                            t.content = codecs.open(path, 'r').read()
                            t.save(sync_themes=False)
                            t.sites.add(site)
                    template = t
    return template
Пример #5
0
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
                'horizon.loaders.TemplateLoader',
            ])]
        TEMPLATES[0]['OPTIONS']['debug'] = False
else:
    # Debugging stuff
    TEMPLATE_DEBUG = DEBUG
    TEMPLATES[0]['OPTIONS']['loaders'] = [
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
        'horizon.loaders.TemplateLoader',
    ]
    COMPRESS_ENABLED = False

APPS = merge(APPS, default.core)

if 'media' in APPS:
    FILER_IMAGE_MODEL = 'leonardo.module.media.models.Image'

try:
    from leonardo.conf.horizon import *
    from leonardo.conf.static import *
except Exception as e:
    warnings.warn(
        'Could not import static packages %s' % str(e))

if LEONARDO_SYSTEM_MODULE:
    APPS = merge(APPS, ['leonardo_system'])
    HORIZON_CONFIG['system_module'] = True
else:
Пример #6
0
 def add_modules(self, modules):
     """Merge new modules to loaded modules"""
     merged_modules = merge(modules, self.modules)
     self.set_modules(merged_modules)
Пример #7
0
 def add_modules(self, modules):
     """Merge new modules to loaded modules"""
     merged_modules = merge(modules, self.modules)
     self.set_modules(merged_modules)
Пример #8
0
        TEMPLATES[0]["OPTIONS"]["loaders"] = [
            (
                "django.template.loaders.cached.Loader",
                [
                    "dbtemplates.loader.Loader",
                    "django.template.loaders.filesystem.Loader",
                    "django.template.loaders.app_directories.Loader",
                    "horizon.loaders.TemplateLoader",
                ],
            )
        ]
        TEMPLATES[0]["OPTIONS"]["debug"] = False
else:
    TEMPLATE_DEBUG = DEBUG

APPS = merge(APPS, default.core)

if "media" in APPS:
    FILER_IMAGE_MODEL = "leonardo.module.media.models.Image"

try:
    from leonardo.conf.horizon import *
    from leonardo.conf.static import *
except Exception as e:
    pass

if LEONARDO_SYSTEM_MODULE:
    APPS = merge(APPS, ["leonardo_system"])
    HORIZON_CONFIG["system_module"] = True
else:
    HORIZON_CONFIG["system_module"] = False