diff --git a/djangocms_link/apps.py b/djangocms_link/apps.py index c0eac622..db057710 100644 --- a/djangocms_link/apps.py +++ b/djangocms_link/apps.py @@ -8,7 +8,6 @@ class DjangoCmsLinkConfig(AppConfig): def ready(self): # Only scan admins after all apps are loaded - from django.contrib import admin from djangocms_link import admin as link_admin diff --git a/djangocms_link/fields.py b/djangocms_link/fields.py index 2a591e9a..50208fca 100644 --- a/djangocms_link/fields.py +++ b/djangocms_link/fields.py @@ -113,6 +113,7 @@ class SiteAutocompleteSelect(AutocompleteSelect): no_sites = None def __init__(self, attrs=None): + # Hack: Pretend that the user is selecting a site for a Page object try: from cms.models.pagemodel import TreeNode @@ -151,6 +152,7 @@ class LinkWidget(MultiWidget): template_name = "djangocms_link/admin/link_widget.html" data_pos = {} number_sites = None + default_site_selector = getattr(settings, "DJANGOCMS_LINK_SITE_SELECTOR", False) class Media: js = ("djangocms_link/link-widget.js",) @@ -159,7 +161,7 @@ class Media: def __init__(self, site_selector=None): if site_selector is None: - site_selector = getattr(settings, "DJANGOCMS_LINK_SITE_SELECTOR", False) + site_selector = LinkWidget.default_site_selector widgets = [ Select( @@ -254,7 +256,8 @@ def __init__(self, *args, **kwargs): def prepare_value(self, value): if isinstance(value, list): return value - + if value is None: + value = {} multi_value = len(self.widget.widgets) * [None] if "external_link" in value: pos = self._get_pos("external_link") @@ -309,7 +312,7 @@ class LinkField(JSONField): def __init__(self, *args, **kwargs): kwargs.setdefault("default", dict) kwargs.setdefault("blank", True) - kwargs.setdefault("help_text", "-") + kwargs.setdefault("help_text", "-") # Help text is set by the widget super().__init__(*args, **kwargs) def formfield(self, **kwargs): diff --git a/djangocms_link/locale/af/LC_MESSAGES/django.mo b/djangocms_link/locale/af/LC_MESSAGES/django.mo new file mode 100644 index 00000000..419543d1 Binary files /dev/null and b/djangocms_link/locale/af/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ar/LC_MESSAGES/django.mo b/djangocms_link/locale/ar/LC_MESSAGES/django.mo new file mode 100644 index 00000000..13fdb9b8 Binary files /dev/null and b/djangocms_link/locale/ar/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/be/LC_MESSAGES/django.mo b/djangocms_link/locale/be/LC_MESSAGES/django.mo new file mode 100644 index 00000000..1e7e8ff5 Binary files /dev/null and b/djangocms_link/locale/be/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/bg/LC_MESSAGES/django.mo b/djangocms_link/locale/bg/LC_MESSAGES/django.mo new file mode 100644 index 00000000..1377b3cc Binary files /dev/null and b/djangocms_link/locale/bg/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/bn/LC_MESSAGES/django.mo b/djangocms_link/locale/bn/LC_MESSAGES/django.mo new file mode 100644 index 00000000..e9a579bd Binary files /dev/null and b/djangocms_link/locale/bn/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ca/LC_MESSAGES/django.mo b/djangocms_link/locale/ca/LC_MESSAGES/django.mo new file mode 100644 index 00000000..034b2c0f Binary files /dev/null and b/djangocms_link/locale/ca/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/cmn/LC_MESSAGES/django.mo b/djangocms_link/locale/cmn/LC_MESSAGES/django.mo new file mode 100644 index 00000000..e40fe7b4 Binary files /dev/null and b/djangocms_link/locale/cmn/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/cs/LC_MESSAGES/django.mo b/djangocms_link/locale/cs/LC_MESSAGES/django.mo new file mode 100644 index 00000000..3dec9746 Binary files /dev/null and b/djangocms_link/locale/cs/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/cy/LC_MESSAGES/django.mo b/djangocms_link/locale/cy/LC_MESSAGES/django.mo new file mode 100644 index 00000000..56abdc7e Binary files /dev/null and b/djangocms_link/locale/cy/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/da/LC_MESSAGES/django.mo b/djangocms_link/locale/da/LC_MESSAGES/django.mo new file mode 100644 index 00000000..14ccf09a Binary files /dev/null and b/djangocms_link/locale/da/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/de/LC_MESSAGES/django.mo b/djangocms_link/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 00000000..a4939469 Binary files /dev/null and b/djangocms_link/locale/de/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/el/LC_MESSAGES/django.mo b/djangocms_link/locale/el/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8d934fb8 Binary files /dev/null and b/djangocms_link/locale/el/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/en/LC_MESSAGES/django.mo b/djangocms_link/locale/en/LC_MESSAGES/django.mo new file mode 100644 index 00000000..a036668d Binary files /dev/null and b/djangocms_link/locale/en/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/en/LC_MESSAGES/django.po b/djangocms_link/locale/en/LC_MESSAGES/django.po index aebde87f..a4603d79 100644 --- a/djangocms_link/locale/en/LC_MESSAGES/django.po +++ b/djangocms_link/locale/en/LC_MESSAGES/django.po @@ -23,15 +23,15 @@ msgstr "" #: djangocms_link/cms_plugins.py:15 djangocms_link/models.py:73 msgid "Link" -msgstr "" +msgstr "Link" #: djangocms_link/cms_plugins.py:27 msgid "Advanced settings" -msgstr "" +msgstr "Advanced settings" #: djangocms_link/fields.py:26 djangocms_link/forms.py:15 msgid "Internal link" -msgstr "" +msgstr "Internal link" #: djangocms_link/fields.py:27 msgid "External link/anchor" @@ -47,7 +47,7 @@ msgstr "" #: djangocms_link/fields.py:175 msgid "https://example.com or #anchor" -msgstr "" +msgstr "https://example.com or #anchor" #: djangocms_link/fields.py:177 msgid "" @@ -80,7 +80,7 @@ msgstr "" #: djangocms_link/fields.py:215 msgid "Select site" -msgstr "" +msgstr "Select site" #: djangocms_link/fields.py:249 msgid "Select a link type and provide a link." @@ -128,12 +128,12 @@ msgstr "" #: djangocms_link/models.py:118 msgid "Link is required." -msgstr "" +msgstr "Link is required." #: djangocms_link/validators.py:50 msgid "Enter a valid anchor" -msgstr "" +msgstr "Enter a valid anchor" #: djangocms_link/validators.py:84 msgid "Enter a valid phone number" -msgstr "" +msgstr "Enter a valid phone number" diff --git a/djangocms_link/locale/en_GB/LC_MESSAGES/django.mo b/djangocms_link/locale/en_GB/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8bcafdcf Binary files /dev/null and b/djangocms_link/locale/en_GB/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/en_US/LC_MESSAGES/django.mo b/djangocms_link/locale/en_US/LC_MESSAGES/django.mo new file mode 100644 index 00000000..d6531063 Binary files /dev/null and b/djangocms_link/locale/en_US/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/eo/LC_MESSAGES/django.mo b/djangocms_link/locale/eo/LC_MESSAGES/django.mo new file mode 100644 index 00000000..744f213f Binary files /dev/null and b/djangocms_link/locale/eo/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/es/LC_MESSAGES/django.mo b/djangocms_link/locale/es/LC_MESSAGES/django.mo new file mode 100644 index 00000000..dee95407 Binary files /dev/null and b/djangocms_link/locale/es/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/et/LC_MESSAGES/django.mo b/djangocms_link/locale/et/LC_MESSAGES/django.mo new file mode 100644 index 00000000..c24cbb1e Binary files /dev/null and b/djangocms_link/locale/et/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/eu/LC_MESSAGES/django.mo b/djangocms_link/locale/eu/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8b8f0a89 Binary files /dev/null and b/djangocms_link/locale/eu/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/fa/LC_MESSAGES/django.mo b/djangocms_link/locale/fa/LC_MESSAGES/django.mo new file mode 100644 index 00000000..0bfa16e5 Binary files /dev/null and b/djangocms_link/locale/fa/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/fi/LC_MESSAGES/django.mo b/djangocms_link/locale/fi/LC_MESSAGES/django.mo new file mode 100644 index 00000000..5883e379 Binary files /dev/null and b/djangocms_link/locale/fi/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/fr/LC_MESSAGES/django.mo b/djangocms_link/locale/fr/LC_MESSAGES/django.mo new file mode 100644 index 00000000..f8a972ba Binary files /dev/null and b/djangocms_link/locale/fr/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ga/LC_MESSAGES/django.mo b/djangocms_link/locale/ga/LC_MESSAGES/django.mo new file mode 100644 index 00000000..41898af1 Binary files /dev/null and b/djangocms_link/locale/ga/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/gl/LC_MESSAGES/django.mo b/djangocms_link/locale/gl/LC_MESSAGES/django.mo new file mode 100644 index 00000000..3e910eaa Binary files /dev/null and b/djangocms_link/locale/gl/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/gu/LC_MESSAGES/django.mo b/djangocms_link/locale/gu/LC_MESSAGES/django.mo new file mode 100644 index 00000000..fbd9472c Binary files /dev/null and b/djangocms_link/locale/gu/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/he/LC_MESSAGES/django.mo b/djangocms_link/locale/he/LC_MESSAGES/django.mo new file mode 100644 index 00000000..6d5c6856 Binary files /dev/null and b/djangocms_link/locale/he/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/hi/LC_MESSAGES/django.mo b/djangocms_link/locale/hi/LC_MESSAGES/django.mo new file mode 100644 index 00000000..9649925e Binary files /dev/null and b/djangocms_link/locale/hi/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/hr/LC_MESSAGES/django.mo b/djangocms_link/locale/hr/LC_MESSAGES/django.mo new file mode 100644 index 00000000..42d3290b Binary files /dev/null and b/djangocms_link/locale/hr/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/hu/LC_MESSAGES/django.mo b/djangocms_link/locale/hu/LC_MESSAGES/django.mo new file mode 100644 index 00000000..adfe7fd4 Binary files /dev/null and b/djangocms_link/locale/hu/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/id/LC_MESSAGES/django.mo b/djangocms_link/locale/id/LC_MESSAGES/django.mo new file mode 100644 index 00000000..c80fe01f Binary files /dev/null and b/djangocms_link/locale/id/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/is/LC_MESSAGES/django.mo b/djangocms_link/locale/is/LC_MESSAGES/django.mo new file mode 100644 index 00000000..504f0fcd Binary files /dev/null and b/djangocms_link/locale/is/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/it/LC_MESSAGES/django.mo b/djangocms_link/locale/it/LC_MESSAGES/django.mo new file mode 100644 index 00000000..c01f9528 Binary files /dev/null and b/djangocms_link/locale/it/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ja/LC_MESSAGES/django.mo b/djangocms_link/locale/ja/LC_MESSAGES/django.mo new file mode 100644 index 00000000..dffce96f Binary files /dev/null and b/djangocms_link/locale/ja/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ka/LC_MESSAGES/django.mo b/djangocms_link/locale/ka/LC_MESSAGES/django.mo new file mode 100644 index 00000000..13807bf7 Binary files /dev/null and b/djangocms_link/locale/ka/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/kk/LC_MESSAGES/django.mo b/djangocms_link/locale/kk/LC_MESSAGES/django.mo new file mode 100644 index 00000000..455aea14 Binary files /dev/null and b/djangocms_link/locale/kk/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/km/LC_MESSAGES/django.mo b/djangocms_link/locale/km/LC_MESSAGES/django.mo new file mode 100644 index 00000000..c327d55c Binary files /dev/null and b/djangocms_link/locale/km/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ko/LC_MESSAGES/django.mo b/djangocms_link/locale/ko/LC_MESSAGES/django.mo new file mode 100644 index 00000000..3cb7f944 Binary files /dev/null and b/djangocms_link/locale/ko/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/lt/LC_MESSAGES/django.mo b/djangocms_link/locale/lt/LC_MESSAGES/django.mo new file mode 100644 index 00000000..e641f117 Binary files /dev/null and b/djangocms_link/locale/lt/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/lv/LC_MESSAGES/django.mo b/djangocms_link/locale/lv/LC_MESSAGES/django.mo new file mode 100644 index 00000000..ddad4d68 Binary files /dev/null and b/djangocms_link/locale/lv/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/mn/LC_MESSAGES/django.mo b/djangocms_link/locale/mn/LC_MESSAGES/django.mo new file mode 100644 index 00000000..9e8a3a51 Binary files /dev/null and b/djangocms_link/locale/mn/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ms/LC_MESSAGES/django.mo b/djangocms_link/locale/ms/LC_MESSAGES/django.mo new file mode 100644 index 00000000..11584e94 Binary files /dev/null and b/djangocms_link/locale/ms/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/mt/LC_MESSAGES/django.mo b/djangocms_link/locale/mt/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8fefb5d1 Binary files /dev/null and b/djangocms_link/locale/mt/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/nb/LC_MESSAGES/django.mo b/djangocms_link/locale/nb/LC_MESSAGES/django.mo new file mode 100644 index 00000000..847e2f3f Binary files /dev/null and b/djangocms_link/locale/nb/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/nl/LC_MESSAGES/django.mo b/djangocms_link/locale/nl/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8b272cd3 Binary files /dev/null and b/djangocms_link/locale/nl/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/no/LC_MESSAGES/django.mo b/djangocms_link/locale/no/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8e946b16 Binary files /dev/null and b/djangocms_link/locale/no/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/pl/LC_MESSAGES/django.mo b/djangocms_link/locale/pl/LC_MESSAGES/django.mo new file mode 100644 index 00000000..a90c2564 Binary files /dev/null and b/djangocms_link/locale/pl/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/pt/LC_MESSAGES/django.mo b/djangocms_link/locale/pt/LC_MESSAGES/django.mo new file mode 100644 index 00000000..a3641606 Binary files /dev/null and b/djangocms_link/locale/pt/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ro/LC_MESSAGES/django.mo b/djangocms_link/locale/ro/LC_MESSAGES/django.mo new file mode 100644 index 00000000..078e6e3a Binary files /dev/null and b/djangocms_link/locale/ro/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ru/LC_MESSAGES/django.mo b/djangocms_link/locale/ru/LC_MESSAGES/django.mo new file mode 100644 index 00000000..5e43e807 Binary files /dev/null and b/djangocms_link/locale/ru/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/sk/LC_MESSAGES/django.mo b/djangocms_link/locale/sk/LC_MESSAGES/django.mo new file mode 100644 index 00000000..a890c0a0 Binary files /dev/null and b/djangocms_link/locale/sk/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/sl/LC_MESSAGES/django.mo b/djangocms_link/locale/sl/LC_MESSAGES/django.mo new file mode 100644 index 00000000..05e3aaeb Binary files /dev/null and b/djangocms_link/locale/sl/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/sq/LC_MESSAGES/django.mo b/djangocms_link/locale/sq/LC_MESSAGES/django.mo new file mode 100644 index 00000000..29af7511 Binary files /dev/null and b/djangocms_link/locale/sq/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/sr/LC_MESSAGES/django.mo b/djangocms_link/locale/sr/LC_MESSAGES/django.mo new file mode 100644 index 00000000..0503856a Binary files /dev/null and b/djangocms_link/locale/sr/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/sv/LC_MESSAGES/django.mo b/djangocms_link/locale/sv/LC_MESSAGES/django.mo new file mode 100644 index 00000000..eae17268 Binary files /dev/null and b/djangocms_link/locale/sv/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ta/LC_MESSAGES/django.mo b/djangocms_link/locale/ta/LC_MESSAGES/django.mo new file mode 100644 index 00000000..06ce80fa Binary files /dev/null and b/djangocms_link/locale/ta/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/th/LC_MESSAGES/django.mo b/djangocms_link/locale/th/LC_MESSAGES/django.mo new file mode 100644 index 00000000..927e5d88 Binary files /dev/null and b/djangocms_link/locale/th/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/tr/LC_MESSAGES/django.mo b/djangocms_link/locale/tr/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8e35fe6e Binary files /dev/null and b/djangocms_link/locale/tr/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ug/LC_MESSAGES/django.mo b/djangocms_link/locale/ug/LC_MESSAGES/django.mo new file mode 100644 index 00000000..d8e56508 Binary files /dev/null and b/djangocms_link/locale/ug/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/uk/LC_MESSAGES/django.mo b/djangocms_link/locale/uk/LC_MESSAGES/django.mo new file mode 100644 index 00000000..07019e3a Binary files /dev/null and b/djangocms_link/locale/uk/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/ur/LC_MESSAGES/django.mo b/djangocms_link/locale/ur/LC_MESSAGES/django.mo new file mode 100644 index 00000000..49e0e851 Binary files /dev/null and b/djangocms_link/locale/ur/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/vi/LC_MESSAGES/django.mo b/djangocms_link/locale/vi/LC_MESSAGES/django.mo new file mode 100644 index 00000000..6becf383 Binary files /dev/null and b/djangocms_link/locale/vi/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/zh-Hans/LC_MESSAGES/django.mo b/djangocms_link/locale/zh-Hans/LC_MESSAGES/django.mo new file mode 100644 index 00000000..8893fb66 Binary files /dev/null and b/djangocms_link/locale/zh-Hans/LC_MESSAGES/django.mo differ diff --git a/djangocms_link/locale/zh/LC_MESSAGES/django.mo b/djangocms_link/locale/zh/LC_MESSAGES/django.mo new file mode 100644 index 00000000..099e54a9 Binary files /dev/null and b/djangocms_link/locale/zh/LC_MESSAGES/django.mo differ diff --git a/tests/test_fields.py b/tests/test_fields.py index 00cb333b..c68791a1 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -1,5 +1,119 @@ +from django import forms from django.test import TestCase +from cms.api import create_page + +from djangocms_link.fields import LinkFormField, LinkWidget +from tests.helpers import get_filer_file + class LinkFieldTestCase(TestCase): - pass + def setUp(self): + self.page = create_page( + title='django CMS is fun', + template='page.html', + language='en', + ) + self.file = get_filer_file() + + def test_form_field_rendering(self): + class LinkForm(forms.Form): + link_field = LinkFormField(required=True) + + form = LinkForm() + form_html = str(form) + + # Render widget + self.assertIn( + '