def handle(self, *apps, **options):
        using = options.get('database', DEFAULT_DB_ALIAS)

        tree_modules = import_project_sitetree_modules()

        if not tree_modules:
            self.stdout.write('No sitetrees found in project apps (searched in %%app%%/%s.py).\n' % APP_MODULE_NAME)

        for module in tree_modules:
            sitetrees = getattr(module, 'sitetrees', None)
            app = module.__dict__['__package__']
            if not apps or (apps and app in apps):
                if sitetrees is not None:
                    self.stdout.write('Sitetrees found in `%s` app ...\n' % app)
                    for tree in sitetrees:
                        self.stdout.write('  Processing `%s` tree ...\n' % tree.alias)
                        # Delete trees with the same name beforehand.
                        MODEL_TREE_CLASS.objects.filter(alias=tree.alias).using(using).delete()
                        # Drop id to let the DB handle it.
                        tree.id = None
                        tree.save(using=using)
                        for item in tree.dynamic_items:
                            self.stdout.write('    Adding `%s` tree item ...\n' % item.title)
                            # Drop id to let the DB handle it.
                            item.id = None
                            if item.parent is not None:
                                # Suppose parent tree object is already saved to DB.
                                item.parent_id = item.parent.id
                            item.tree = tree
                            item.save(using=using)
Esempio n. 2
0
def test_import():

    from sitetree.utils import import_project_sitetree_modules

    modules = import_project_sitetree_modules()

    assert len(modules) == 1
    assert modules[0].sitetrees
def test_import():

    from sitetree.utils import import_project_sitetree_modules

    modules = import_project_sitetree_modules()

    assert len(modules) == 1
    assert modules[0].sitetrees
Esempio n. 4
0
    def handle(self, *apps, **options):
        using = options.get('database', DEFAULT_DB_ALIAS)

        tree_modules = import_project_sitetree_modules()

        if not tree_modules:
            self.stdout.write(
                f'No sitetrees found in project apps (searched in %app%/{APP_MODULE_NAME}.py).\n'
            )

        for module in tree_modules:
            sitetrees = getattr(module, 'sitetrees', None)
            app = module.__dict__['__package__']
            if not apps or app in apps:
                if sitetrees is not None:
                    self.stdout.write(f'Sitetrees found in `{app}` app ...\n')
                    for tree in sitetrees:
                        self.stdout.write(
                            f'  Processing `{tree.alias}` tree ...\n')
                        # Delete trees with the same name beforehand.
                        MODEL_TREE_CLASS.objects.filter(
                            alias=tree.alias).using(using).delete()
                        # Drop id to let the DB handle it.
                        tree.id = None
                        tree.save(using=using)
                        for item in tree.dynamic_items:
                            self.stdout.write(
                                f'    Adding `{item.title}` tree item ...\n')
                            # Drop id to let the DB handle it.
                            item.id = None
                            if item.parent is not None:
                                # Suppose parent tree object is already saved to DB.
                                item.parent_id = item.parent.id
                            item.tree = tree
                            item.save(using=using)
                            # Copy permissions to M2M field once `item`
                            # has been saved
                            if hasattr(item.access_permissions, 'set'):
                                item.access_permissions.set(item.permissions)

                            else:
                                item.access_permissions = item.permissions

        Cache.reset()
    def handle(self, *args, **options):
        if len(args) < 1:
            raise CommandError('The tree_name argument is required!')
        tree_name = args[0]
        # Delete trees with the same name beforehand.
        using = options.get('database', DEFAULT_DB_ALIAS)
        MODEL_TREE_CLASS.objects.filter(alias=tree_name).using(using).delete()
        maintree = MODEL_TREE_CLASS.objects.using(using).create(alias=tree_name)

        tree_modules = import_project_sitetree_modules()

        if not tree_modules:
            self.stdout.write('No sitetrees found in project apps (searched in %%app%%/%s.py).\n' % APP_MODULE_NAME)

        for module in tree_modules:
            sitetrees = getattr(module, 'sitetrees', None)
            app = module.__dict__['__package__']
            if sitetrees is not None:
                self.stdout.write('Sitetrees found in `%s` app ...\n' % app)
                for tree in sitetrees:
                    self.stdout.write('  Processing `%s` tree ...\n' % tree.alias)

                    # Drop id to let the DB handle it.
                    # tree.id = None
                    # tree.save(using=using)
                    for item in tree.dynamic_items:
                        self.stdout.write('    Adding `%s` tree item ...\n' % item.title)
                        # Drop id to let the DB handle it.
                        item.id = None
                        if item.parent is not None:
                            # Suppose parent tree object is already saved to DB.
                            item.parent_id = item.parent.id
                        item.tree = maintree
                        item.save(using=using)
                        if item.access_restricted:
                            item.access_permissions = item.pending_permissions
                            item.save()
Esempio n. 6
0
    def handle(self, *apps, **options):
        using = options.get('database', DEFAULT_DB_ALIAS)

        tree_modules = import_project_sitetree_modules()

        if not tree_modules:
            self.stdout.write(
                'No sitetrees found in project apps (searched in %%app%%/%s.py).\n'
                % APP_MODULE_NAME)

        for module in tree_modules:
            sitetrees = getattr(module, 'sitetrees', None)
            app = module.__dict__['__package__']
            if not apps or (apps and app in apps):
                if sitetrees is not None:
                    self.stdout.write('Sitetrees found in `%s` app ...\n' %
                                      app)
                    for tree in sitetrees:
                        self.stdout.write('  Processing `%s` tree ...\n' %
                                          tree.alias)
                        # Delete trees with the same name beforehand.
                        MODEL_TREE_CLASS.objects.filter(
                            alias=tree.alias).using(using).delete()
                        # Drop id to let the DB handle it.
                        tree.id = None
                        tree.save(using=using)
                        for item in tree.dynamic_items:
                            self.stdout.write(
                                '    Adding `%s` tree item ...\n' % item.title)
                            # Drop id to let the DB handle it.
                            item.id = None
                            if item.parent is not None:
                                # Suppose parent tree object is already saved to DB.
                                item.parent_id = item.parent.id
                            item.tree = tree
                            item.save(using=using)
Esempio n. 7
0
 def test_get_model_class(self):
     import_project_sitetree_modules()
Esempio n. 8
0
 def test_get_model_class(self):
     import_project_sitetree_modules()