예제 #1
0
 def test_reload(self):
     BlokManager.load()
     BlokManager.set('invalid blok', None)
     BlokManager.get('invalid blok')
     BlokManager.reload()
     with pytest.raises(BlokManagerException):
         BlokManager.get('invalid blok')
예제 #2
0
 def test_get_invalid_blok(self):
     try:
         BlokManager.load()
         BlokManager.get('invalid blok')
         self.fail('No exception when get invalid blok')
     except BlokManagerException:
         pass
예제 #3
0
 def test_get_invalid_blok(self):
     try:
         BlokManager.load()
         BlokManager.get('invalid blok')
         self.fail('No exception when get invalid blok')
     except BlokManagerException:
         pass
예제 #4
0
    def test_load_anyblok(self):
        BlokManager.load()
        if not BlokManager.list():
            self.fail('No blok load')
        if not BlokManager.has('anyblok-core'):
            self.fail("The blok 'anyblok-core' is missing")

        BlokManager.get('anyblok-core')
예제 #5
0
    def test_load_anyblok(self):
        BlokManager.load()
        if not BlokManager.list():
            self.fail('No blok load')
        if not BlokManager.has('anyblok-core'):
            self.fail("The blok 'anyblok-core' is missing")

        BlokManager.get('anyblok-core')
예제 #6
0
 def test_reload(self):
     BlokManager.load()
     BlokManager.set('invalid blok', None)
     BlokManager.get('invalid blok')
     BlokManager.reload()
     try:
         BlokManager.get('invalid blok')
         self.fail("Reload classmethod doesn't reload the bloks")
     except BlokManagerException:
         pass
예제 #7
0
 def test_reload(self):
     BlokManager.load()
     BlokManager.set('invalid blok', None)
     BlokManager.get('invalid blok')
     BlokManager.reload()
     try:
         BlokManager.get('invalid blok')
         self.fail("Reload classmethod doesn't reload the bloks")
     except BlokManagerException:
         pass
예제 #8
0
 def test_update_loadwithoutmigration(self, registry_blok16_installed):
     registry = registry_blok16_installed
     registry.loadwithoutmigration = True
     registry.System.Parameter.set("with-demo", True)
     registry.upgrade(update=('test-blok16', ))
     blok = BlokManager.get('test-blok16')
     assert blok.called_methods == []
예제 #9
0
 def load(self):
     """Load all the actor defined in all the installed bloks"""
     Blok = self.registry.System.Blok
     for blok in Blok.list_by_state('installed'):
         b = BlokManager.get(blok)
         if hasattr(b, 'declare_actors'):
             b.declare_actors(self.registry)
예제 #10
0
    def export_i18n(cls, blok_name):
        b = BlokManager.get(blok_name)
        bpath = BlokManager.getPath(blok_name)
        po = polib.POFile()
        po.metadata = {
            'Project-Id-Version': b.version,
            'POT-Creation-Date': datetime.now().isoformat(),
            'MIME-Version': '1.0',
            'Content-Type': 'text/plain; charset=utf-8',
            'Content-Transfer-Encoding': '8bit',
        }
        if hasattr(b, 'furetui'):
            templates = Template()
            for template in b.furetui.get('templates', []):
                with open(join(bpath, template), 'r') as fp:
                    templates.load_file(fp, ignore_missing_extend=True)

            templates.export_i18n(po)

        Mapping = cls.anyblok.IO.Mapping
        for mapping in Mapping.query().filter_by(blokname=blok_name):
            obj = Mapping.get(mapping.model, mapping.key)
            if not obj:
                continue

            for context, text in obj.get_i18n_to_export(mapping.key):
                entry = Translation.define(context, text)
                po.append(entry)

        cls.export_i18n_bases(blok_name, po)

        Path(path.join(bpath, 'locale')).mkdir(exist_ok=True)
        po.save(path.join(bpath, 'locale', f'{blok_name}.pot'))
예제 #11
0
파일: imp.py 프로젝트: AnyBlok/AnyBlok
    def imports(self):
        """ Imports modules and / or packages listed in the blok path"""
        from anyblok.blok import BlokManager
        from anyblok.registry import RegistryManager

        RegistryManager.init_blok(self.blok)
        b = BlokManager.get(self.blok)
        b.import_declaration_module()
예제 #12
0
파일: test_blok.py 프로젝트: Gnonpi/AnyBlok
 def test_auto_migration_is_between_pre_and_post_migration_1(self):
     registry = self.init_registry(None)
     registry.upgrade(install=('test-blok14', ))
     blok = BlokManager.get('test-blok14')
     self.assertFalse(blok.table_exist_before_automigration)
     self.assertTrue(blok.table_exist_after_automigration)
     registry.Test.insert()
     self.assertEqual(registry.Test.query().count(), 1)
예제 #13
0
파일: imp.py 프로젝트: Gnonpi/AnyBlok
    def imports(self):
        """ Imports modules and / or packages listed in the blok path"""
        from anyblok.blok import BlokManager
        from anyblok.registry import RegistryManager

        RegistryManager.init_blok(self.blok)
        b = BlokManager.get(self.blok)
        b.import_declaration_module()
예제 #14
0
 def test_unistall_without_demo(self, registry_blok16_installed):
     registry = registry_blok16_installed
     registry.System.Parameter.set("with-demo", False)
     registry.upgrade(uninstall=('test-blok16', ))
     blok = BlokManager.get('test-blok16')
     assert blok.called_methods == [
         "uninstall",
     ]
예제 #15
0
 def test_auto_migration_is_between_pre_and_post_migration_1(
         self, registry_testblok):
     registry = registry_testblok
     registry.upgrade(install=('test-blok14', ))
     blok = BlokManager.get('test-blok14')
     assert blok.table_exist_before_automigration is False
     assert blok.table_exist_after_automigration is True
     registry.Test.insert()
     assert registry.Test.query().count() == 1
예제 #16
0
    def test_reload(self):
        import sys
        module_type = sys.__class__  # is there a simpler way ?

        def fake_reload(module):
            self.assertIsInstance(module, module_type)

        blok = BlokManager.get('wms-quantity')
        blok.reload_declaration_module(fake_reload)
예제 #17
0
파일: database.py 프로젝트: ERPBlok/ERPBlok
def get_addons(request):
    res = []
    for blok_name in BlokManager.ordered_bloks:
        blok = BlokManager.get(blok_name)
        if hasattr(blok, 'setting_blok_description'):
            addons = blok.setting_blok_description
            addons['id'] = blok_name
            res.append(addons)

    return res
예제 #18
0
파일: blok.py 프로젝트: AnyBlok/AnyBlok
    def get_short_description(self):
        """ fget of the ``short_description`` Column.Selection

        :rtype: the docstring of the blok
        """
        blok = BlokManager.get(self.name)
        if hasattr(blok, '__doc__'):
            return blok.__doc__ or ''

        return ''
예제 #19
0
 def test_update_without_demo(self, registry_blok16_installed):
     registry = registry_blok16_installed
     registry.System.Parameter.set("with-demo", False)
     registry.upgrade(update=('test-blok16', ))
     blok = BlokManager.get('test-blok16')
     assert blok.called_methods == [
         "pre_migration",
         "post_migration",
         "update",
     ]
예제 #20
0
    def get_short_description(self):
        """ fget of the ``short_description`` Column.Selection

        :rtype: the docstring of the blok
        """
        blok = BlokManager.get(self.name)
        if hasattr(blok, '__doc__'):
            return blok.__doc__ or ''

        return ''
예제 #21
0
 def test_install_with_demo(self, registry_testblok_func):
     registry = registry_testblok_func
     registry.System.Parameter.set("with-demo", True)
     registry.upgrade(install=('test-blok16', ))
     blok = BlokManager.get('test-blok16')
     assert blok.called_methods == [
         "pre_migration",
         "post_migration",
         "update",
         "update_demo",
     ]
예제 #22
0
    def get_logo(self):
        """fget of ``logo`` return the path in the blok of the logo

        :rtype: absolute path or None if unexiste logo
        """
        blok = BlokManager.get(self.name)
        blok_path = BlokManager.getPath(blok.name)
        file_path = join(blok_path, blok.logo)
        if isfile(file_path):
            return file_path

        return None
예제 #23
0
파일: blok.py 프로젝트: AnyBlok/AnyBlok
    def get_logo(self):
        """fget of ``logo`` return the path in the blok of the logo

        :rtype: absolute path or None if unexiste logo
        """
        blok = BlokManager.get(self.name)
        blok_path = BlokManager.getPath(blok.name)
        file_path = join(blok_path, blok.logo)
        if isfile(file_path):
            return file_path

        return None
예제 #24
0
파일: common.py 프로젝트: jssuzanne/ERPBlok
def get_templates_from(attr):
    tmpl = Template(forclient=True)
    for blok_name in BlokManager.ordered_bloks:
        blok = BlokManager.get(blok_name)
        if hasattr(blok, attr):
            bpath = BlokManager.getPath(blok_name)
            for template in getattr(blok, attr):
                with open(join(bpath, template), 'r') as fp:
                    tmpl.load_file(fp)

    tmpl.compile()
    return tmpl.get_all_template()
예제 #25
0
파일: blok.py 프로젝트: petrus-v/AnyBlok
    def load(self):
        """ Method to load the blok when the registry is completly loaded
        """
        name = self.name
        blok_cls = BlokManager.get(name)
        if blok_cls is None:
            logger.warning("load(): class of Blok %r not found, "
                           "Blok can't be loaded", name)
            return

        logger.info("Loading Blok %r", name)
        blok_cls(self.registry).load()
        logger.debug("Succesfully loaded Blok %r", name)
예제 #26
0
    def load(self):
        from os.path import join
        tmpl = Template()
        Blok = self.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, 'views'):
                bpath = BlokManager.getPath(blok)
                for template in b.views:
                    with open(join(bpath, template), 'r') as fp:
                        tmpl.load_file(fp)

        tmpl.compile()
        self.registry.furetui_views = tmpl
예제 #27
0
파일: __init__.py 프로젝트: ERPBlok/ERPBlok
    def load(self):
        from os.path import join
        tmpl = Template()
        Blok = self.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, 'views'):
                bpath = BlokManager.getPath(blok)
                for template in b.views:
                    with open(join(bpath, template), 'r') as fp:
                        tmpl.load_file(fp)

        tmpl.compile()
        self.registry.erpblok_views = tmpl
예제 #28
0
def get_static(static_type):
    """ Get in the Blok definition the static data from the client

    :param static: entry to read: css, js, ...
    :rtype: list of str
    """
    res = []
    for blok_name in BlokManager.ordered_bloks:
        blok = BlokManager.get(blok_name)
        if hasattr(blok, static_type):
            for static_url in getattr(blok, static_type):
                res.append(format_static(blok_name, static_url))

    return res
예제 #29
0
파일: common.py 프로젝트: jssuzanne/ERPBlok
def get_static(static_type):
    """ Get in the Blok definition the static data from the client

    :param static: entry to read: css, js, ...
    :rtype: list of str
    """
    res = []
    for blok_name in BlokManager.ordered_bloks:
        blok = BlokManager.get(blok_name)
        if hasattr(blok, static_type):
            for static_url in getattr(blok, static_type):
                res.append(format_static(blok_name, static_url))

    return res
예제 #30
0
    def get_static(cls, static_type):
        """ return the list of all static file path

        :param static_type: entry in the blok
        :rtype: list of the path
        """
        res = []
        Blok = cls.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, static_type):
                for static_url in getattr(b, static_type):
                    res.append(cls.format_static(blok, static_url))

        return res
예제 #31
0
파일: __init__.py 프로젝트: ERPBlok/ERPBlok
    def get_templates(cls):
        """ Return the list of the web client template to load """
        from os.path import join
        tmpl = Template(forclient=True)
        Blok = cls.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, 'client_templates'):
                bpath = BlokManager.getPath(blok)
                for template in b.client_templates:
                    with open(join(bpath, template), 'r') as fp:
                        tmpl.load_file(fp)

        tmpl.compile()
        return tmpl.get_all_template()
예제 #32
0
파일: __init__.py 프로젝트: ERPBlok/ERPBlok
    def get_static(cls, static_type):
        """ return the list of all static file path

        :param static_type: entry in the blok
        :rtype: list of the path
        """
        res = []
        Blok = cls.registry.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            if hasattr(b, static_type):
                for static_url in getattr(b, static_type):
                    res.append(cls.format_static(blok, static_url))

        return res
예제 #33
0
    def load_config_bloks(self):
        """ loop on each blok, keep the order of the blok to load the
        pyramid config. The blok must declare the meth
        ``pyramid_load_config``::

            def pyramid_load_config(config):
                config.add_route('hello', '/hello/{name}/')
                ...

        """
        self.commit()
        for blok_name in BlokManager.ordered_bloks:
            blok = BlokManager.get(blok_name)
            if hasattr(blok, 'pyramid_load_config'):
                logger.debug('Load configuration from: %r' % blok_name)
                blok.pyramid_load_config(self)
                self.commit()
예제 #34
0
    def load_config_bloks(self):
        """ loop on each blok, keep the order of the blok to load the
        pyramid config. The blok must declare the meth
        ``pyramid_load_config``::

            def pyramid_load_config(config):
                config.add_route('hello', '/hello/{name}/')
                ...

        """
        self.commit()
        for blok_name in BlokManager.ordered_bloks:
            blok = BlokManager.get(blok_name)
            if hasattr(blok, 'pyramid_load_config'):
                logger.debug('Load configuration from: %r' % blok_name)
                blok.pyramid_load_config(self)
                self.commit()
예제 #35
0
파일: blok.py 프로젝트: AnyBlok/AnyBlok
    def get_long_description(self):
        """ fget of the ``long_description`` Column.Selection

        :rtype: the readme file of the blok
        """
        blok = BlokManager.get(self.name)
        path = BlokManager.getPath(self.name)
        readme = getattr(blok, 'readme', 'README.rst')
        if readme == '__doc__':
            return blok.__doc__

        file_path = join(path, readme)
        description = ''
        if isfile(file_path):
            with open(file_path, 'r') as fp:
                description = fp.read()

        return description
예제 #36
0
    def get_long_description(self):
        """ fget of the ``long_description`` Column.Selection

        :rtype: the readme file of the blok
        """
        blok = BlokManager.get(self.name)
        path = BlokManager.getPath(self.name)
        readme = getattr(blok, 'readme', 'README.rst')
        if readme == '__doc__':
            return blok.__doc__

        file_path = join(path, readme)
        description = ''
        if isfile(file_path):
            with open(file_path, 'r') as fp:
                description = fp.read()

        return description
예제 #37
0
파일: imp.py 프로젝트: AnyBlok/AnyBlok
    def reload(self):
        """ Reload all the imports for this module

        :exception: ImportManagerException
        """
        from anyblok.blok import BlokManager
        from anyblok.registry import RegistryManager
        from anyblok.environment import EnvironmentManager

        b = BlokManager.get(self.blok)
        if not hasattr(b, 'reload_declaration_module'):
            return

        try:
            EnvironmentManager.set('reload', True)
            RegistryManager.init_blok(self.blok)
            b.reload_declaration_module(reload_module)
        finally:
            EnvironmentManager.set('reload', False)
예제 #38
0
파일: imp.py 프로젝트: Gnonpi/AnyBlok
    def reload(self):
        """ Reload all the imports for this module

        :exception: ImportManagerException
        """
        from anyblok.blok import BlokManager
        from anyblok.registry import RegistryManager
        from anyblok.environment import EnvironmentManager

        b = BlokManager.get(self.blok)
        if not hasattr(b, 'reload_declaration_module'):
            return

        try:
            EnvironmentManager.set('reload', True)
            RegistryManager.init_blok(self.blok)
            b.reload_declaration_module(reload_wraper)
        finally:
            EnvironmentManager.set('reload', False)
예제 #39
0
    def pre_load(cls, lang='en'):
        logger.info('Preload furet UI component')
        templates = Template()
        i18n = {}
        Blok = cls.anyblok.System.Blok
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            bpath = BlokManager.getPath(blok)
            if hasattr(b, 'furetui'):
                for template in b.furetui.get('templates', []):
                    with open(join(bpath, template), 'r') as fp:
                        templates.load_file(fp)

                for local, translations in b.furetui.get('i18n', {}).items():
                    node = i18n.setdefault(local, {})
                    update_translation(node, translations)

        cls.import_i18n(lang)
        templates.compile(lang=lang)
        cls.anyblok.furetui_templates = templates
        cls.anyblok.furetui_i18n = i18n
예제 #40
0
    def test_upgrade_contents_local_goods_ids(self):
        Props = self.Props
        p1_id = Props.insert(flexible=dict(foo='bar')).id
        p2_id = Props.insert(flexible=dict(
            monty='python',
            contents=[
                dict(type='POT1',
                     forward_properties=['foo'],
                     quantity=3,
                     local_goods_ids=[1, 3, 7]),
                dict(type='POT2', forward_properties=['foo'], quantity=3),
            ])).id
        from anyblok.blok import BlokManager
        wms_core = BlokManager.get('wms-core')(self.registry)

        # make sure we have no side effect of Property instances in the
        # session
        self.registry.session.expire_all()

        wms_core.update_contents_property_local_goods_id()

        # and again
        self.registry.flush()
        self.registry.session.expire_all()

        # time for assertions
        p1 = Props.query().get(p1_id)
        self.assertEqual(p1.flexible, dict(foo='bar'))
        p2 = Props.query().get(p2_id)
        self.assertEqual(
            p2.flexible,
            dict(monty='python',
                 contents=[
                     dict(type='POT1',
                          forward_properties=['foo'],
                          quantity=3,
                          local_physobj_ids=[1, 3, 7]),
                     dict(type='POT2', forward_properties=['foo'], quantity=3)
                 ]))
예제 #41
0
    def pre_load(cls):
        logger.info('Preload furet UI component')
        tmpl_views = Template()
        tmpl_components = Template()
        js = []
        css = []
        i18n = {}
        Blok = cls.registry.System.Blok
        timestamp = datetime.utcnow().timestamp()
        for blok in Blok.list_by_state('installed'):
            b = BlokManager.get(blok)
            bpath = BlokManager.getPath(blok)
            if hasattr(b, 'furetui'):
                for template in b.furetui.get('templates', []):
                    with open(join(bpath, template), 'r') as fp:
                        tmpl_components.load_file(fp)

                js.extend([
                    '%s?%s' %
                    (join('furet-ui', blok, 'js', filename), timestamp)
                    for filename in b.furetui.get('js', [])
                ])
                css.extend([
                    join('furet-ui', blok, 'css', filename)
                    for filename in b.furetui.get('css', [])
                ])

                for local, translations in b.furetui.get('i18n', {}).items():
                    node = i18n.setdefault(local, {})
                    update_translation(node, translations)

        tmpl_views.compile()
        cls.registry.furetui_views = tmpl_views
        tmpl_components.compile()
        cls.registry.furetui_components = tmpl_components
        cls.registry.furetui_js = js
        cls.registry.furetui_css = css
        cls.registry.furetui_i18n = i18n
예제 #42
0
 def clear_called_methods():
     BlokManager.get('test-blok16').called_methods = []
예제 #43
0
 def registry_blok16_installed(self, registry_testblok_func):
     registry_testblok_func.upgrade(install=('test-blok16', ))
     blok = BlokManager.get('test-blok16')
     blok.called_methods = []
     return registry_testblok_func
예제 #44
0
 def test_marked_as_conflicting(self):
     blok1 = BlokManager.get('test-blok1')
     blok13 = BlokManager.get('test-blok13')
     self.assertEqual(blok13.conflicting, ['test-blok1'])
     self.assertEqual(blok1.conflicting_by, ['test-blok13'])
예제 #45
0
 def get_inherit_bloks(blok_name):
     bloks.add(blok_name)
     blok = BlokManager.get(blok_name)
     for subblok in (blok.required_by + blok.conditional_by):
         get_inherit_bloks(subblok)
예제 #46
0
 def test_marked_as_conflicting(self, registry_testblok):
     blok1 = BlokManager.get('test-blok1')
     blok13 = BlokManager.get('test-blok13')
     assert blok13.conflicting == ['test-blok1']
     assert blok1.conflicting_by == ['test-blok13']