Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in dijango-cms 4.1 and fronted #221

Closed
olariuromeo opened this issue Aug 11, 2023 · 4 comments · Fixed by #226
Closed

in dijango-cms 4.1 and fronted #221

olariuromeo opened this issue Aug 11, 2023 · 4 comments · Fixed by #226

Comments

@olariuromeo
Copy link

python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "django/core/management/init.py", line 442, in execute_from_command_line
utility.execute()
File "/python3.11/site-packages/django/core/management/init.py", line 416, in execute
django.setup()
File "dev/lib/python3.11/site-packages/django/init.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "dev/lib/python3.11/site-packages/django/apps/registry.py", line 124, in populate
app_config.ready()
File "dev/lib/python3.11/site-packages/django/contrib/admin/apps.py", line 27, in ready
self.module.autodiscover()
File "dev/lib/python3.11/site-packages/django/contrib/admin/init.py", line 50, in autodiscover
autodiscover_modules("admin", register_to=site)
File "dev/lib/python3.11/site-packages/django/utils/module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "/usr/local/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "dev/lib/python3.11/site-packages/cms/admin/init.py", line 11, in
plugin_pool.plugin_pool.discover_plugins()
File "dev/lib/python3.11/site-packages/cms/plugin_pool.py", line 42, in discover_plugins
autodiscover_modules('cms_plugins')
File "dev/lib/python3.11/site-packages/django/utils/module_loading.py", line 58, in autodiscover_modules
import_module("%s.%s" % (app_config.name, module_to_search))
File "/usr/local/lib/python3.11/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1204, in _gcd_import
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "", line 940, in exec_module
File "", line 241, in _call_with_frames_removed
File "dev/lib/python3.11/site-packages/djangocms_link/cms_plugins.py", line 7, in
from .forms import LinkForm
File "dev/lib/python3.11/site-packages/djangocms_link/forms.py", line 10, in
class LinkForm(ModelForm):
File "dev/lib/python3.11/site-packages/djangocms_link/forms.py", line 11, in LinkForm
internal_link = PageSearchField(
^^^^^^^^^^^^^^^^
File "dev/lib/python3.11/site-packages/djangocms_link/fields_select2.py", line 45, in init
kwargs['queryset'] = self.widget.get_queryset()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "dev/lib/python3.11/site-packages/djangocms_link/fields_select2.py", line 32, in get_queryset
return Page.objects.drafts()
^^^^^^^^^^^^^^^^^^^
AttributeError: 'PageManager' object has no attribute 'drafts'

@filipweidemann
Copy link
Contributor

filipweidemann commented Jul 19, 2024

@fsbraun Hey Fabian, would you kindly look at master...filipweidemann:djangocms-link:master?

I didn't want to open a PR just yet because the whole test suite also needs to be updated (djangocms-text-ckeditor as a reference is nice).

My patch is kind of simple, just remove the call to draft() on all pages and instead return the whole queryset. If I understand this whole versioning transition correctly, this would yield the expected result since there is only one Page but many PageContents corresponding to their own draft. So, in other words, all we need to care about for linking is the Page while the versioning handles the rest, aka finding the currently published draft.

Can you confirm this? If so, I'd push through and do the refactoring of the whole test suite like it was done in djangocms-text-ckeditor.

@fsbraun
Copy link
Member

fsbraun commented Jul 20, 2024

@filipweidemann That's the right direction. I'd go for a solution that works both with CMS 3 and CMS 4.

For example:

def get_queryset(self):
    if hasattr(Page.objects, "drafts"):
        # django CMS 3.x
        if self.site:
            return Page.objects.drafts().on_site(self.site)
        return Page.objects.drafts()
    # django CMS 4
    if self.site:
        return Page.objects.on_site(self.site)
    return Page.objects.all()

@filipweidemann
Copy link
Contributor

Very clean. I'll start working on a PR next week :)

@filipweidemann
Copy link
Contributor

@fsbraun here you go: #226
Would be nice if you can find some time to either comment on any needed changes or, if everything looks fine, to actually merge this into master so I can start using it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants