Projet

Général

Profil

0001-commands-set-locales-in-tenant-commands-51734.patch

Thomas Noël, 06 mars 2021 14:44

Télécharger (3,69 ko)

Voir les différences:

Subject: [PATCH] commands: set locales in tenant commands (#51734)

 tests/test_ctl.py                       | 11 +++++++++++
 wcs/ctl/management/commands/__init__.py |  1 +
 wcs/qommon/cron.py                      |  5 +----
 wcs/qommon/publisher.py                 | 11 +++++++----
 4 files changed, 20 insertions(+), 8 deletions(-)
tests/test_ctl.py
427 427
class TestAfterJob(AfterJob):
428 428
    def execute(self):
429 429
        self.foo = WorkflowStatusItem().compute('{{ global_title|default:"FAIL" }}')
430
        self.l10n_month = WorkflowStatusItem().compute('{{ "10/10/2010"|date:"F" }}')
430 431

  
431 432

  
432 433
def test_runjob(pub):
......
448 449
    call_command('runjob', '--domain=example.net', '--job-id=%s' % job.id)
449 450
    assert AfterJob.get(job.id).status == 'completed'
450 451
    assert AfterJob.get(job.id).foo == 'HELLO'
452
    assert AfterJob.get(job.id).l10n_month == 'October'
453

  
454
    pub.cfg['language'] = {'language': 'fr'}
455
    pub.write_cfg()
456
    job = TestAfterJob(label='test2')
457
    job.store()
458
    assert AfterJob.get(job.id).status == 'registered'
459
    call_command('runjob', '--domain=example.net', '--job-id=%s' % job.id)
460
    assert AfterJob.get(job.id).status == 'completed'
461
    assert AfterJob.get(job.id).l10n_month == 'octobre'
451 462

  
452 463

  
453 464
def test_ctl_print_help(capsys):
wcs/ctl/management/commands/__init__.py
28 28
            raise CommandError('unknown tenant')
29 29
        publisher.app_dir = os.path.join(publisher.APP_DIR, domain)
30 30
        publisher.set_config()
31
        publisher.install_lang()
31 32
        publisher.substitutions.feed(publisher)
32 33
        return publisher
wcs/qommon/cron.py
67 67
            if minutes and not now[4] in minutes:
68 68
                continue
69 69

  
70
        class FakeRequest(object):
71
            language = publisher.get_site_language()
72

  
73
        publisher.install_lang(FakeRequest())
70
        publisher.install_lang()
74 71
        publisher.substitutions.reset()
75 72
        publisher.substitutions.feed(publisher)
76 73
        for extra_source in publisher.extra_sources:
wcs/qommon/publisher.py
344 344
            content = template.render(content.templates, content.context)
345 345
        return template.decorate(content, self.get_request().response)
346 346

  
347
    def install_lang(self, request):
348
        lang = request.language
347
    def install_lang(self, request=None):
348
        if request:
349
            lang = request.language
350
        else:
351
            lang = self.get_site_language()
349 352
        if lang is None or not lang in [x[0] for x in settings.LANGUAGES]:
350 353
            lang = 'en'
351 354
        translation.activate(lang)
352
        request.LANGUAGE_CODE = lang
353

  
354 355
        self.gettext = translation.gettext
355 356
        self.ngettext = translation.ngettext
357
        if request:
358
            request.LANGUAGE_CODE = lang
356 359

  
357 360
    def load_site_options(self):
358 361
        self.site_options = configparser.ConfigParser()
359
-