Пример #1
0
def setup_from_none():
    lang = os.environ['LANG'][:2] if 'LANG' in os.environ else 'fr'
    if six.PY3:
        clear_modules()
    from lucterios.framework.settings import fill_appli_settings
    import types
    import gc
    gc.collect()
    lct_modules = []
    glob = LucteriosGlobal()
    _, mod_applis, mod_modules = glob.installed()
    for mod_item in mod_applis:
        lct_modules.append(mod_item[0])
    for mod_item in mod_modules:
        lct_modules.append(mod_item[0])
    try:
        module = types.ModuleType("default_setting")
    except TypeError:
        module = types.ModuleType(six.binary_type("default_setting"))
    setattr(module, '__file__', ".")
    setattr(module, 'SECRET_KEY', "default_setting")
    setattr(module, 'LANGUAGE_CODE', lang)
    setattr(module, 'DATABASES',
            {'default': {
                'ENGINE': 'django.db.backends.dummy'
            }})
    fill_appli_settings("lucterios.standard", lct_modules, module)
    sys.modules["default_setting"] = module
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "default_setting")
    import django
    from django import db
    django.setup()
    set_locale_lang(lang)
    db.close_old_connections()
Пример #2
0
    def test_formating_en(self):
        set_locale_lang('en')
        activate('en')
        self.assertEqual(
            format_to_string(1234.56, "N3", "{[i]}{0}{[/i]};{[b]}{0}{[/b]}"),
            "{[i]}1,234.560{[/i]}", "check num positive formated")
        self.assertEqual(
            format_to_string(-1234.56, "N3", "{[i]}{0}{[/i]};{[b]}{0}{[/b]}"),
            "{[b]}1,234.560{[/b]}", "check num negative formated")
        self.assertEqual(format_to_string(1234.56, "N0", "{0}"), "1,235",
                         "check int no-formated")

        self.assertEqual(format_to_string(1234.56, "N3", "{0}"), "1,234.560",
                         "check num positive no-formated")
        self.assertEqual(format_to_string(-1234.56, "N3", "{0}"), "-1,234.560",
                         "check num negative no-formated")
        self.assertEqual(format_to_string(1234.56, "C2USD", "{0}"),
                         "1,234.56 $US", "check currency positive no-formated")
        self.assertEqual(format_to_string(-1234.56, "C2USD",
                                          "{0}"), "-1,234.56 $US",
                         "check currency negative no-formated")

        self.assertEqual(format_to_string("2017-04-23", "D", "{0}"),
                         "April 23, 2017", "check date")
        self.assertEqual(format_to_string("12:54:25.014", "T", "{0}"), "12:54",
                         "check time")
        self.assertEqual(
            format_to_string("2017-04-23T12:54:25.014", "H", "{0}"),
            "Sunday, April 23, 2017 at 12:54", "check date time")

        self.assertEqual(format_to_string(True, "B", "{0}"), "Yes",
                         "check bool true")
        self.assertEqual(format_to_string(False, "B", "{0}"), "No",
                         "check bool false")
Пример #3
0
def initial_values(*args):
    set_locale_lang(settings.LANGUAGE_CODE)
    PrintModel().load_model("diacamma.member", "Adherent_0001", is_default=True)
    PrintModel().load_model("diacamma.member", "Adherent_0002", is_default=False)
    PrintModel().load_model("diacamma.member", "Adherent_0003", is_default=False)
    PrintModel().load_model("diacamma.member", "Adherent_0004", is_default=True)
    PrintModel().load_model("diacamma.member", "Adherent_0005", is_default=False)
Пример #4
0
def check_values(*args):
    set_locale_lang(settings.LANGUAGE_CODE)
    jnl2 = Journal.objects.get(id=2)
    jnl2.name = _('spending')
    jnl2.save()
    jnl3 = Journal.objects.get(id=3)
    jnl3.name = _('revenue')
    jnl3.save()
Пример #5
0
 def read(self, virtual_setup=False):
     clear_modules()
     import django.conf
     from lucterios.framework.tools import set_locale_lang
     if virtual_setup:
         setup_from_none()
     if self.name == '':
         raise AdminException("Instance not precise!")
     if not isfile(self.setting_path) or not isfile(self.instance_conf):
         raise AdminException("Instance not exists !")
     os.environ[django.conf.ENVIRONMENT_VARIABLE] = self.setting_module_name
     if self.setting_module_name in sys.modules.keys():
         mod_set = sys.modules[self.setting_module_name]
         del mod_set
         del sys.modules[self.setting_module_name]
     if not virtual_setup:
         import_module("django.conf")
         django.setup()
         setting_module = django.conf.settings
     else:
         setting_module = import_module(self.setting_module_name)
         set_locale_lang(setting_module.LANGUAGE_CODE)
     self.secret_key = setting_module.SECRET_KEY
     self.extra = setting_module.EXTRA
     self.databases = setting_module.DATABASES
     self.database = setting_module.DATABASES['default']['ENGINE']
     if "sqlite3" in self.database:
         self.database = ('sqlite', {})
     if "mysql" in self.database:
         self.database = ('mysql', self._get_db_info_())
     if "postgresql" in self.database:
         self.database = ('postgresql', self._get_db_info_())
     self.appli_name = setting_module.APPLIS_MODULE.__name__
     self.modules = ()
     for appname in setting_module.INSTALLED_APPS:
         if ("django" not in appname) and (
                 appname != 'lucterios.framework') and (
                     appname != 'lucterios.CORE') and (self.appli_name !=
                                                       appname):
             self.modules = self.modules + (six.text_type(appname), )
     try:
         from lucterios.CORE.parameters import Params
         self.extra[''] = {
             'mode': (Params.getvalue("CORE-connectmode"),
                      Params.gettext("CORE-connectmode"))
         }
     except Exception:
         self.extra[''] = {'mode': None}
     self.print_info_("""Instance %s:
 path\t%s
 appli\t%s
 database\t%s
 modules\t%s
 extra\t%s
 """ % (self.name, self.instance_dir, self.get_appli_txt(),
        self.get_database_txt(), self.get_module_txt(),
        self.get_extra_txt()))
     return
Пример #6
0
def post_after_migrate(sender, **kwargs):
    if ('exception' not in kwargs) and ('app_config' in kwargs) and (
            kwargs['app_config'].name == 'lucterios.CORE'):
        from django.conf import settings
        set_locale_lang(settings.LANGUAGE_CODE)
        six.print_('check parameters')
        Signal.call_signal("checkparam")
        six.print_('convert data')
        Signal.call_signal("convertdata")
Пример #7
0
def initial_values(apps, schema_editor):
    set_locale_lang(settings.LANGUAGE_CODE)
    legalentity = apps.get_model("contacts", "LegalEntity")
    current_entity = legalentity.objects.create(id=1, name="---", address='---',
                                                postal_code='00000', city='---', country='---')
    current_entity.save()

    PrintModel().load_model('lucterios.contacts', "LegalEntity_0001", is_default=True)
    PrintModel().load_model('lucterios.contacts', "LegalEntity_0002", is_default=True)
    PrintModel().load_model('lucterios.contacts', "Individual_0001", is_default=True)
    PrintModel().load_model('lucterios.contacts', "Individual_0002", is_default=True)
Пример #8
0
def initial_values(*args):
    set_locale_lang(settings.LANGUAGE_CODE)
    Function.objects.create(name=_('president of council'))
    Function.objects.create(name=_('auditor'))
    Function.objects.create(name=_('secretary of council'))
    Function.objects.create(name=_('member of council'))
    StructureType.objects.create(name=_('enterprise'))
    StructureType.objects.create(name=_('association'))

    if Journal.objects.all().count() != 0:
        jnl2 = Journal.objects.get(id=2)
        jnl2.name = _('spending')
        jnl2.save()
        jnl3 = Journal.objects.get(id=3)
        jnl3.name = _('revenue')
        jnl3.save()
Пример #9
0
def initial_values(*_args):
    from diacamma.condominium.models import OwnerLink
    set_locale_lang(settings.LANGUAGE_CODE)
    link1, created = OwnerLink.objects.get_or_create(id=1)
    if created:
        link1.name = _('lodger')
        link1.save()
    link2, created = OwnerLink.objects.get_or_create(id=2)
    if created:
        link2.name = _('rental agency')
        link2.save()
    link3, created = OwnerLink.objects.get_or_create(id=3)
    if created:
        link3.name = _('emergency')
        link3.save()
    link4, created = OwnerLink.objects.get_or_create(id=4)
    if created:
        link4.name = _('security agency')
        link4.save()
Пример #10
0
def initial_values(*_args):
    from diacamma.condominium.models import OwnerLink
    set_locale_lang(settings.LANGUAGE_CODE)
    link1, created = OwnerLink.objects.get_or_create(id=OwnerLink.DEFAULT_LODGER)
    if created:
        link1.name = _('lodger')
        link1.save()
    link2, created = OwnerLink.objects.get_or_create(id=OwnerLink.DEFAULT_RENTAL_AGENCY)
    if created:
        link2.name = _('rental agency')
        link2.save()
    link3, created = OwnerLink.objects.get_or_create(id=OwnerLink.DEFAULT_EMERGENCY)
    if created:
        link3.name = _('emergency')
        link3.save()
    link4, created = OwnerLink.objects.get_or_create(id=OwnerLink.DEFAULT_SECURITY_AGENCY)
    if created:
        link4.name = _('security agency')
        link4.save()
Пример #11
0
 def _initialize(self, request, *_, **kwargs):
     from django.conf import settings
     if hasattr(self.__class__, 'is_view_right'):
         self.get_action().raise_bad_permission(request)
     if hasattr(request, 'session'):
         request.session.set_expiry(12 * 60)  # 12 min of idle timeout
     path_list = request.path.split('/')
     self.extension, self.action = path_list[-2:]
     self.request = request
     for key in kwargs.keys():
         self.params[key] = kwargs[key]
     for key in request.GET.keys():
         self.params[key] = request.GET[key]
     for key in request.POST.keys():
         self.params[key] = request.POST[key]
     if 'FORMAT' in self.params.keys():
         self.format = self.params['FORMAT']
         del self.params['FORMAT']
     self.language = settings.LANGUAGE_CODE
     set_locale_lang(self.language)
     self._search_model()
Пример #12
0
 def setUp(self):
     LucteriosTest.setUp(self)
     set_locale_lang('fr')
     activate(settings.LANGUAGE_CODE)
     Example.objects.create(name='abc',
                            value=12,
                            price=1224.06,
                            date='1997-10-07',
                            time='21:43',
                            valid=True,
                            comment="blablabla")
     Example.objects.create(name='zzzz',
                            value=7,
                            price=714.03,
                            date='2008-03-21',
                            time='15:21',
                            valid=False,
                            comment="")
     Example.objects.create(name='uvw',
                            value=9,
                            price=918.05,
                            date='2014-05-11',
                            time='04:57',
                            valid=True,
                            comment="")
     Example.objects.create(name='blabla',
                            value=17,
                            price=1734.08,
                            date='2001-07-17',
                            time='23:14',
                            valid=False,
                            comment="")
     Example.objects.create(name='boom',
                            value=4,
                            price=408.02,
                            date='1984-08-02',
                            time='11:36',
                            valid=True,
                            comment="")
Пример #13
0
 def read(self, virtual_setup=False):
     clear_modules()
     import django.conf
     from lucterios.framework.tools import set_locale_lang
     if virtual_setup:
         setup_from_none()
     if self.name == '':
         raise AdminException("Instance not precise!")
     if not isfile(self.setting_path) or not isfile(self.instance_conf):
         raise AdminException("Instance not exists !")
     os.environ[django.conf.ENVIRONMENT_VARIABLE] = self.setting_module_name
     if self.setting_module_name in sys.modules.keys():
         mod_set = sys.modules[self.setting_module_name]
         del mod_set
         del sys.modules[self.setting_module_name]
     if not virtual_setup:
         import_module("django.conf")
         django.setup()
         setting_module = django.conf.settings
     else:
         setting_module = import_module(self.setting_module_name)
         set_locale_lang(setting_module.LANGUAGE_CODE)
     self.secret_key = setting_module.SECRET_KEY
     self.appli_name = setting_module.APPLIS_MODULE.__name__
     self._read_databases(setting_module.DATABASES)
     self._read_modules(setting_module.INSTALLED_APPS)
     self._read_extra(setting_module.EXTRA)
     self.print_info_("""Instance %s:
 path\t%s
 appli\t%s
 database\t%s
 modules\t%s
 extra\t%s
 """ % (self.name, self.instance_dir, self.get_appli_txt(),
        self.get_database_txt(), self.get_module_txt(),
        self.get_extra_txt()))
     return
Пример #14
0
    def test_formating_fr(self):
        set_locale_lang('fr')
        activate('fr')

        self.assertEqual(
            format_to_string(1234.56, "N3", "{[i]}{0}{[/i]};{[b]}{0}{[/b]}"),
            "{[i]}1 234,560{[/i]}", "check num positive formated")
        self.assertEqual(
            format_to_string(-1234.56, "N3", "{[i]}{0}{[/i]};{[b]}{0}{[/b]}"),
            "{[b]}1 234,560{[/b]}", "check num negative formated")
        self.assertEqual(format_to_string(1234.56, "N0", "{0}"), "1 235",
                         "check int no-formated")

        self.assertEqual(format_to_string(1234.56, "N3", "{0}"), "1 234,560",
                         "check num positive no-formated")
        self.assertEqual(format_to_string(-1234.56, "N3", "{0}"), "-1 234,560",
                         "check num negative no-formated")
        self.assertEqual(format_to_string(1234.56, "C2EUR", "{0}"),
                         "1 234,56 €", "check currency positive no-formated")
        self.assertEqual(format_to_string(-1234.56, "C2EUR", "{0}"),
                         "-1 234,56 €", "check currency negative no-formated")

        self.assertEqual(format_to_string(1234.56, 'C2EUR', '{0};'),
                         "1 234,56 €", "currency mode 0 +")
        self.assertEqual(
            format_to_string(1234.56, 'C2EUR', 'Crédit {0};Débit {0}'),
            "Crédit 1 234,56 €", "currency mode 1 +")
        self.assertEqual(
            format_to_string(
                1234.56, 'C2EUR',
                '{[font color="green"]}Crédit {0}{[/font]};{[font color="blue"]}Débit {0}{[/font]}'
            ), "{[font color=\"green\"]}Crédit 1 234,56 €{[/font]}",
            "currency mode 2 +")
        self.assertEqual(format_to_string(1234.56, 'N2', '{0}'), "1 234,56",
                         "currency mode 3 +")
        self.assertEqual(format_to_string(1234.56, 'C2EUR', '{0};{0}'),
                         "1 234,56 €", "currency mode 4 +")
        self.assertEqual(format_to_string(1234.56, 'C2EUR', '{0}'),
                         "1 234,56 €", "currency mode 5 +")
        self.assertEqual(
            format_to_string(
                1234.56, 'C2EUR',
                '{[font color="green"]}{0}{[/font]};{[font color="blue"]}{0}{[/font]}'
            ), "{[font color=\"green\"]}1 234,56 €{[/font]}",
            "currency mode 6 +")

        self.assertEqual(format_to_string(-1234.56, 'C2EUR', '{0};'), "",
                         "currency mode 0 -")
        self.assertEqual(
            format_to_string(-1234.56, 'C2EUR', 'Crédit {0};Débit {0}'),
            "Débit 1 234,56 €", "currency mode 1 -")
        self.assertEqual(
            format_to_string(
                -1234.56, 'C2EUR',
                '{[font color="green"]}Crédit {0}{[/font]};{[font color="blue"]}Débit {0}{[/font]}'
            ), "{[font color=\"blue\"]}Débit 1 234,56 €{[/font]}",
            "currency mode 2 -")
        self.assertEqual(format_to_string(-1234.56, 'N2', '{0}'), "-1 234,56",
                         "currency mode 3 -")
        self.assertEqual(format_to_string(-1234.56, 'C2EUR', '{0};{0}'),
                         "1 234,56 €", "currency mode 4 -")
        self.assertEqual(format_to_string(-1234.56, 'C2EUR', '{0}'),
                         "-1 234,56 €", "currency mode 5 -")
        self.assertEqual(
            format_to_string(
                -1234.56, 'C2EUR',
                '{[font color="green"]}{0}{[/font]};{[font color="blue"]}{0}{[/font]}'
            ), "{[font color=\"blue\"]}1 234,56 €{[/font]}",
            "currency mode 6 -")

        self.assertEqual(format_to_string("2017-04-23", "D", "{0}"),
                         "23 avril 2017", "check date")
        self.assertEqual(format_to_string("12:54:25.014", "T", "{0}"), "12:54",
                         "check time")
        self.assertEqual(
            format_to_string("2017-04-23T12:54:25.014", "H", "{0}"),
            "dimanche 23 avril 2017 à 12:54", "check date time")

        self.assertEqual(format_to_string(True, "B", "{0}"), "Oui",
                         "check bool true")
        self.assertEqual(format_to_string(False, "B", "{0}"), "Non",
                         "check bool false")
Пример #15
0
 def setUp(self):
     LucteriosTest.setUp(self)
     set_locale_lang('fr')
     activate(settings.LANGUAGE_CODE)
Пример #16
0
def addons_values(apps, schema_editor):
    set_locale_lang(settings.LANGUAGE_CODE)
    PrintModel().load_model("lucterios.mailing",
                            "Message_0001",
                            is_default=True)
Пример #17
0
def printer_model(*_args):
    set_locale_lang(settings.LANGUAGE_CODE)
    PrintModel().load_model("diacamma.condominium",
                            "Owner_0003",
                            is_default=False)
Пример #18
0
 def tearDown(self):
     set_locale_lang('fr')
     activate(settings.LANGUAGE_CODE)
     LucteriosTest.tearDown(self)
Пример #19
0
    def test_formating_general(self):
        set_locale_lang('fr')
        activate('fr')

        self.assertEqual(format_to_string(None, None, None), "---",
                         "check None")
        self.assertEqual(format_to_string("abc", None, None), "abc",
                         "check string simple")
        self.assertEqual(format_to_string("abc", None, "{0}"), "abc",
                         "check string simple +")
        self.assertEqual(format_to_string(["abc", "uvw", "xyz"], None, None),
                         "abc{[br/]}uvw{[br/]}xyz", "check string multiple")
        self.assertEqual(
            format_to_string("abc", None, "{[i]}{[b]}{0}{[/b]}{[/i]}"),
            "{[i]}{[b]}abc{[/b]}{[/i]}", "check string formated")
        self.assertEqual(
            format_to_string(["abc", "uvw", "xyz"], None, "{0} : {1} --> {2}"),
            "abc : uvw --> xyz", "check string splited")
        self.assertEqual(
            format_to_string([65.4, 456.04, 894730.124], "N2",
                             "{0} : {1} --> {2}"),
            "65,40 : 456,04 --> 894 730,12", "check float splited")
        self.assertEqual(
            format_to_string({
                "value": "abc",
                "format": "{[b]}{0}{[/b]}"
            }, None, "{[i]}{0}{[/i]}"), "{[i]}{[b]}abc{[/b]}{[/i]}",
            "check string riched formated")

        self.assertEqual(
            format_to_string(1234.56, None, "{[i]}{0}{[/i]};{[b]}{0}{[/b]}"),
            "{[i]}1234.56{[/i]}", "check num positive")
        self.assertEqual(
            format_to_string(-1234.56, None, "{[i]}{0}{[/i]};{[b]}{0}{[/b]}"),
            "{[b]}1234.56{[/b]}", "check num negative")

        self.assertEqual(format_to_string(0.000001, 'C2EUR', '{0};A'), "A",
                         "currency mode 0 null")
        self.assertEqual(format_to_string(-0.000001, 'C2EUR', '{0};A'), "A",
                         "currency mode 0 null")
        self.assertEqual(format_to_string(-0.000001, 'C2EUR', '{0};A;B'), "B",
                         "currency mode 0 null")
        self.assertEqual(format_to_string(0.000001, 'C2EUR', '{0};A;B'), "B",
                         "currency mode 0 null")

        self.assertEqual(
            format_to_string(0, {
                '0': 'aaa',
                '1': 'bbb',
                '2': 'ccc'
            }, "{0}"), "aaa", "check select 0")
        self.assertEqual(
            format_to_string(1, {
                '0': 'aaa',
                '1': 'bbb',
                '2': 'ccc'
            }, "{0}"), "bbb", "check select 1")
        self.assertEqual(
            format_to_string(2, {
                '0': 'aaa',
                '1': 'bbb',
                '2': 'ccc'
            }, "{0}"), "ccc", "check select 2")
        self.assertEqual(
            format_to_string(3, {
                '0': 'aaa',
                '1': 'bbb',
                '2': 'ccc'
            }, "{0}"), "3", "check select 3")
Пример #20
0
def initial_values(*args):
    set_locale_lang(settings.LANGUAGE_CODE)
    PrintModel().load_model('diacamma.member',
                            "TaxReceipt_0001",
                            is_default=True)