django-cms / djangocms-frontend

django CMS frontend is a plugin bundle for django CMS providing several components for the frontend, currently implemented with the popular Bootstrap 5 framework.
Other
55 stars 21 forks source link

feat: Support `LinkFormField` of djangocms-link 5+ #241

Closed fsbraun closed 2 days ago

fsbraun commented 3 weeks ago

This PR replaces the built-in link functionality with the new re-usable LinkFormField by djangocms-link.

Summary by Sourcery

Replace the built-in link functionality with the reusable LinkFormField from djangocms-link, simplifying link management and updating configurations. Refactor the codebase to remove redundant link fields and update the build and CI configurations to align with the new setup.

New Features:

Enhancements:

Build:

CI:

Tests:

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 88.10811% with 22 lines in your changes missing coverage. Please review.

Project coverage is 88.49%. Comparing base (f11feee) to head (a6a2025). Report is 45 commits behind head on master.

Files with missing lines Patch % Lines
djangocms_frontend/helpers.py 16.66% 8 Missing and 2 partials :warning:
djangocms_frontend/ui_plugin_base.py 85.29% 3 Missing and 2 partials :warning:
djangocms_frontend/component_pool.py 75.00% 2 Missing and 2 partials :warning:
djangocms_frontend/common/bootstrap5/responsive.py 0.00% 0 Missing and 1 partial :warning:
djangocms_frontend/contrib/link/cms_plugins.py 85.71% 0 Missing and 1 partial :warning:
djangocms_frontend/plugin_tag.py 97.91% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #241 +/- ## ========================================== + Coverage 86.93% 88.49% +1.56% ========================================== Files 120 123 +3 Lines 3107 3217 +110 Branches 330 259 -71 ========================================== + Hits 2701 2847 +146 + Misses 304 260 -44 - Partials 102 110 +8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features:

fsbraun commented 4 days ago

@sourcery-ai review

sourcery-ai[bot] commented 4 days ago

Reviewer's Guide by Sourcery

This PR replaces the built-in link functionality with djangocms-link's reusable LinkFormField. The implementation involves removing the custom link handling code and integrating with djangocms-link's field and helpers. The changes include data migration to convert existing link data to the new format.

ER diagram for link data migration

erDiagram
    FrontendUIItem {
        JSON config
    }
    FrontendUIItem ||--o{ Link : contains
    Link {
        String external_link
        String internal_link
        String file_link
        String phone
        String mailto
        String anchor
    }
    Link ||--o{ LinkFormField : converted_to
    LinkFormField {
        String link
    }

Class diagram for LinkFormField integration

classDiagram
    class LinkFormMixin {
        +LinkFormField link
        +ChoiceField target
        +Boolean link_is_optional
    }
    class AbstractLinkForm {
    }
    class EntangledModelFormMixin {
    }
    LinkFormMixin --|> EntangledModelFormMixin
    AbstractLinkForm --|> LinkFormMixin

    class GetLinkMixin {
        +String get_link()
    }
    GetLinkMixin --|> LinkFormMixin

    class LinkFormField {
    }
    LinkFormMixin o-- LinkFormField

    class Site {
    }
    GetLinkMixin o-- Site

File-Level Changes

Change Details Files
Replace custom link form fields with djangocms-link's LinkFormField
  • Remove custom link form fields (external_link, internal_link, file_link, etc.)
  • Add LinkFormField from djangocms-link package
  • Update form validation to use djangocms-link's validation
  • Remove custom link widgets and field classes
djangocms_frontend/contrib/link/forms.py
Add data migration for converting existing link data
  • Create migration to convert old link format to new djangocms-link format
  • Add forward and backward migration functions
  • Handle various link types (external, internal, file, phone, mailto)
djangocms_frontend/migrations/0002_migrate_links.py
Refactor link handling helpers
  • Remove custom link choice and queryset functions
  • Update get_link method to use djangocms-link helpers
  • Simplify link URL generation code
djangocms_frontend/contrib/link/helpers.py
Update dependencies and configuration
  • Add djangocms-link>=5.0.0 as a dependency
  • Remove obsolete link-related settings
  • Add migration warning for deprecated settings
setup.py
djangocms_frontend/apps.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).