Skip to content

Commit

Permalink
Fix tests and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Oct 25, 2024
1 parent fcfbcdf commit bbc3004
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
36 changes: 17 additions & 19 deletions djangocms_link/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,7 @@ class Media:
js = ("djangocms_link/link-widget.js",)
css = {"all": ("djangocms_link/link-widget.css",)}

def __init__(self):
# Get the number of sites only once
if LinkWidget.number_sites is None:
LinkWidget.number_sites = Site.objects.count()
def __init__(self, sites_selector=True):

widgets = [
Select(
Expand All @@ -169,13 +166,16 @@ def __init__(self):
"data-help": _("No destination selected. Use the dropdown to select a destination.")
},
), # Link type selector
SiteAutocompleteSelect(
URLInput(
attrs={
"class": "js-link-site-widget",
"widget": "site",
"data-placeholder": _("Select site"),
"widget": "external_link",
"placeholder": _("https://example.com or #anchor"),
"data-help": _(
"Provide a link to an external URL, including the schema such as 'https://', 'tel:', "
"or 'mailto:'. Optionally, add an #anchor (including the #) to scroll to."
),
},
), # Site selector
), # External link input
LinkAutoCompleteWidget(
attrs={
"widget": "internal_link",
Expand All @@ -185,16 +185,6 @@ def __init__(self):
"data-placeholder": _("Select internal destination"),
},
), # Internal link selector
URLInput(
attrs={
"widget": "external_link",
"placeholder": _("https://example.com or #anchor"),
"data-help": _(
"Provide a link to an external URL, including the schema such as 'https://', 'tel:', "
"or 'mailto:'. Optionally, add an #anchor (including the #) to scroll to."
),
},
), # External link input
TextInput(
attrs={
"widget": "anchor",
Expand All @@ -214,6 +204,14 @@ def __init__(self):
},
),
)
if sites_selector:
widgets.insert(2, SiteAutocompleteSelect(
attrs={
"class": "js-link-site-widget",
"widget": "site",
"data-placeholder": _("Select site"),
},
)) # Site selector

# Remember which widget expets its content at which position
self.data_pos = {
Expand Down
1 change: 0 additions & 1 deletion tests/requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
django-select2>=5.11,<7 # 7 works in Django 2+
django-filer>=1.5.0
html5lib>=1
django-app-helper
Expand Down
1 change: 0 additions & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
HELPER_SETTINGS = {
'INSTALLED_APPS': [
'filer',
'django_select2',
'tests.utils',
],
'CMS_LANGUAGES': {
Expand Down
5 changes: 4 additions & 1 deletion tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ def test_full_plugin_render(self):
plugin_type=LinkPlugin.__name__,
language=self.language,
)
from djangocms_link.fields import LinkWidget
pos = LinkWidget().data_pos["external_link"]

data = {
"template": "default",
"link_0": "external_link",
"link_2": "https://www.google.com",
f"link_{pos}": "https://www.google.com",
"name": "External link",
}

Expand Down

0 comments on commit bbc3004

Please sign in to comment.