From 5fa07c3bc9622e65e31f454c69da9e09214c967f Mon Sep 17 00:00:00 2001 From: Mykhailo Poienko <22IMC10258@fh-krems.ac.at> Date: Wed, 23 Oct 2024 14:25:29 +0200 Subject: [PATCH] internalization issues --- README.md | 12 +++++ demoapp/settings.py | 2 +- demoapp/templates/email/default.html | 70 ++++++++++++++++++++++++++++ demoapp/tests/test_01_mail.py | 2 +- demoapp/urls.py | 1 + docs/source/installation.rst | 9 ++++ docs/source/quickstart.rst | 4 +- docs/source/usage.rst | 6 +++ sendmail/admin.py | 2 +- sendmail/models.py | 1 + sendmail/settings.py | 7 ++- sendmail/utils.py | 2 +- sendmail/version.txt | 2 +- setup.py | 2 +- 14 files changed, 113 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dc72db7c..634856cf 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,16 @@ Add `CKEDITOR_UPLOAD_PATH`. This path will be used to store ckeditor uploaded im CKEDITOR_UPLOAD_PATH = 'ckeditor_uploads' ``` +To your main `urls.py` add `ckeditor_uploader` urls: + +```python +urlpatterns = [ + ..., + path('ckeditor/', include('ckeditor_uploader.urls')), + ] +``` + + Add `STATIC_URL` and `STATIC_ROOT` ```python @@ -164,6 +174,8 @@ SENDMAIL = { You can use relative path from your `templates` folder or absolute file path. +- Specify list of translation languages in `settings.LANGUAGES` or disable internalization by setting `settings.USE_I18N` to `False`. + - Open your admin interface and create a new EmailMergeModel instance: - Enter name. This will be used as identifier for your template and click “Save and continue editing”. - Select Base File which you have created. diff --git a/demoapp/settings.py b/demoapp/settings.py index 42420bb9..e408e0e5 100644 --- a/demoapp/settings.py +++ b/demoapp/settings.py @@ -223,7 +223,7 @@ TIME_ZONE = "UTC" -USE_I18N = True +USE_I18N = False USE_L10N = True diff --git a/demoapp/templates/email/default.html b/demoapp/templates/email/default.html index e69de29b..56921b5d 100644 --- a/demoapp/templates/email/default.html +++ b/demoapp/templates/email/default.html @@ -0,0 +1,70 @@ +{% load sendmail %} + + + + + + + + + + + + + +
+ + + + + + + + + + +
 
+ + + + + + +
+ + + {% placeholder 'header' %} +
+ + + + +
+

Dear + {% with gender=recipient.gender %} + {% if gender == 'male' %} + Mr. + {% elif gender == 'female' %} + Ms. + {% else %} + Human + {% endif %} + {% endwith %} + {% placeholder 'name' %} +

+ {% placeholder 'main' %} +
+ + + + +
+ {% placeholder 'footer' %} +
+ + +
 
+
+ + \ No newline at end of file diff --git a/demoapp/tests/test_01_mail.py b/demoapp/tests/test_01_mail.py index 97f497ba..3697edd7 100644 --- a/demoapp/tests/test_01_mail.py +++ b/demoapp/tests/test_01_mail.py @@ -445,7 +445,7 @@ def test_internalization(caplog, template): recipients=[en_recipient, de_recipient, ua_recipient, nullable_recipient], template=template) - assert 'Language "ua" is not found in LANGUAGES configuration.' in caplog.text + assert 'Language "ua" is not found in LANGUAGES configuration' in caplog.text assert len(emails) == 4 assert emails[0].language == 'en' diff --git a/demoapp/urls.py b/demoapp/urls.py index a08e7965..d571271b 100644 --- a/demoapp/urls.py +++ b/demoapp/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ path('admin/', admin.site.urls), + path('ckeditor/', include('ckeditor_uploader.urls')), ] if settings.DEBUG: diff --git a/docs/source/installation.rst b/docs/source/installation.rst index 205f3ec5..57bce60c 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -52,6 +52,15 @@ Add ``CKEDITOR_UPLOAD_PATH``. This path will be used to store ckeditor uploaded CKEDITOR_UPLOAD_PATH = 'ckeditor_uploads' +To your main ``urls.py`` add ``ckeditor_uploader`` urls. + +.. code-block:: + + urlpatterns = [ + ... + path('ckeditor/', include('ckeditor_uploader.urls')), + ] + Add ``STATIC_URL`` and ``STATIC_ROOT`` .. code-block:: diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst index 297455b7..657b6b88 100644 --- a/docs/source/quickstart.rst +++ b/docs/source/quickstart.rst @@ -35,7 +35,7 @@ If you want to use templates: -Register your template in ``settings.py``: +- Register your template in ``settings.py``: .. code-block:: python @@ -48,6 +48,8 @@ Register your template in ``settings.py``: You can use relative path from your ``templates`` folder or absolute file path. +- Specify list of translation languages in ``settings.LANGUAGES`` or disable internalization by setting ``settings.USE_I18N`` to ``False``. + - Open your admin interface and create a new EmailMergeModel instance: - Enter name. This will be used as identifier for your template and click "Save and continue editing". - Select Base File which you have created. diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 7d6efa0e..00efad02 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -396,6 +396,12 @@ Multilingual Templates In sendmail you can create and send templates in multiple languages. For this simply edit your ``settings.py``: +Verify that internalization is enabled: + +.. code-block:: python + + USE_I18N = True + Default templates language can be changed in ``settings.LANGUAGE_CODE`` .. code-block:: python diff --git a/sendmail/admin.py b/sendmail/admin.py index d28cfcd5..aa6118d2 100644 --- a/sendmail/admin.py +++ b/sendmail/admin.py @@ -389,7 +389,7 @@ class EmailTemplateAdmin(admin.ModelAdmin): (None, {'fields': ('name', 'description', 'base_file', 'extra_recipients')}), # (_('Default Content'), {'fields': ('subject', 'content')}), ] - inlines = (EmailTemplateInline, EmailContentInline) if settings.USE_I18N else (EmailContentInline,) + inlines = (EmailTemplateInline, EmailContentInline) formfield_overrides = {models.CharField: {'widget': SubjectField}} filter_horizontal = ('extra_recipients',) diff --git a/sendmail/models.py b/sendmail/models.py index f02ea525..aeb19425 100644 --- a/sendmail/models.py +++ b/sendmail/models.py @@ -411,6 +411,7 @@ def save(self, *args, **kwargs): ) placeholder_names = process_template(self.base_file) + print(placeholder_names) existing_placeholders = set( self.contents.filter(base_file=self.base_file).values_list('placeholder_name', diff --git a/sendmail/settings.py b/sendmail/settings.py index a32e9aa7..cca0a1a7 100644 --- a/sendmail/settings.py +++ b/sendmail/settings.py @@ -82,8 +82,11 @@ def get_config(): def get_languages_list(): - lang_conf = getattr(settings, 'LANGUAGES', []) - return [lang[0] for lang in lang_conf] + if settings.USE_I18N: + lang_conf = getattr(settings, 'LANGUAGES', []) + return [lang[0] for lang in lang_conf] + else: + return [get_default_language(),] def get_default_language(): diff --git a/sendmail/utils.py b/sendmail/utils.py index 920d458c..ff244fe3 100644 --- a/sendmail/utils.py +++ b/sendmail/utils.py @@ -288,7 +288,7 @@ def get_language_from_code(code, log=True) -> str: else: if code not in get_languages_list(): if log: - logger.warning(f'Language "{code}" is not found in LANGUAGES configuration.') + logger.warning(f'Language "{code}" is not found in LANGUAGES configuration or I18N is disabled.') code = get_default_language() return code diff --git a/sendmail/version.txt b/sendmail/version.txt index 13639d96..2c41c156 100644 --- a/sendmail/version.txt +++ b/sendmail/version.txt @@ -1 +1 @@ -4, 0, 2 \ No newline at end of file +4, 0, 3 \ No newline at end of file diff --git a/setup.py b/setup.py index 0d671f5e..022d6812 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ zip_safe=False, include_package_data=True, package_data={'': ['README.md']}, - install_requires=['Django', 'django-ckeditor', 'lxml', 'nh3'], + install_requires=['Django>=4', 'django-ckeditor=>6', 'lxml=>5', 'nh3'], classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment',