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))
def dbtemplate_save(sender, instance, created, **kwargs):
    """create widget/page content/base theme from given db template::
        /widget/icon/my_awesome.html
        /base/widget/my_new_widget_box.html
        /base/page/my_new_page_layout.html
    """

    if created:
        if 'widget' in instance.name:
            name = instance.name.split('/')[-1]
            kwargs = {
                'name': name.split('.')[0],
                'label': name.split('.')[0].capitalize(),
                'template': instance,
            }
            if 'base/widget' in instance.name:
                from leonardo.module.web.models import WidgetBaseTheme
                theme_cls = WidgetBaseTheme
            else:
                from leonardo.module.web.models import WidgetContentTheme
                theme_cls = WidgetContentTheme
                from leonardo.utils.widgets import find_widget_class
                w_cls_name = instance.name.split('/')[-2]
                w_cls = find_widget_class(w_cls_name)
                if w_cls is None:
                    raise Exception('widget class for %s not found' % w_cls_name)
                kwargs['widget_class'] = w_cls.__name__
            theme_cls(**kwargs).save()

        if 'base/page' in instance.name:
            from leonardo.module.web.models import PageTheme
            page_theme = PageTheme()
            page_theme.label = '{} layout'.format(
                instance.name.split("/")[-1].split('.')[0].title())
            page_theme.name = instance.name.split("/")[-1]
            page_theme.template = instance
            page_theme.save()