Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented Oct 28, 2025

Description

Avoid admin errors by conditionally including get_author and get_modified_date in the AliasAdmin list display and cleanup legacy versioning list configuration.

Bug Fixes:

  • Prevent missing-method errors by only inserting get_author and get_modified_date when the methods exist

Enhancements:

  • Remove the alias_admin_list_display variable and versioning flag check
  • Simplify AliasAdmin.list_display and override get_list_display to manage optional columns dynamically

Fixes #302

Related resources

Checklist

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 28, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This refactors the AliasAdmin list_display setup by removing the old alias_admin_list_display and versioning flag logic, and instead overriding get_list_display to dynamically inject get_author and get_modified_date when available.

Class diagram for updated AliasAdmin list_display logic

classDiagram
    class AliasAdmin {
        +list_display
        +list_display_links
        +list_filter
        +get_queryset(request)
        +get_list_display(request)
        +used(obj)
    }
    AliasAdmin --|> GrouperModelAdmin
    class GrouperModelAdmin {
    }
    class CategoryAdmin {
    }
    CategoryAdmin --|> TranslatableAdmin
    class TranslatableAdmin {
    }
Loading

File-Level Changes

Change Details Files
Remove the static alias_admin_list_display and versioning flag logic
  • Deleted the alias_admin_list_display variable
  • Removed the djangocms_versioning_enabled flag reference
  • Removed the conditional insertions of get_author and get_modified_date
djangocms_alias/admin.py
Introduce dynamic injection of versioning columns via get_list_display
  • Changed AliasAdmin.list_display to a fixed list without versioning fields
  • Added get_list_display override to check for get_author and insert get_author and get_modified_date before admin_list_actions
djangocms_alias/admin.py

Assessment against linked issues

Issue Objective Addressed Explanation
#302 Prevent errors in admin by ensuring 'get_author' and 'get_modified_date' are only referenced in list_display if they exist in AliasAdmin.

Possibly linked issues


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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard 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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `djangocms_alias/admin.py:82-88` </location>
<code_context>
         # Annotate each Alias with a boolean indicating if related cmsplugins exist
         return qs.annotate(cmsplugins_count=models.Count("cms_plugins"))

+    def get_list_display(self, request):
+        list_display = super().get_list_display(request)
+        if hasattr(self, "get_author"):
+            list_display = list(list_display)
+            list_display.insert(-1, "get_author")
+            list_display.insert(-1, "get_modified_date")
+        return list_display
+
     @admin.display(description=_("Used"), boolean=True, ordering="cmsplugins_count")
</code_context>

<issue_to_address>
**suggestion:** Consider checking for versioning enablement rather than method presence.

Checking for 'get_author' may not accurately reflect versioning status. Using the configuration flag ensures the list display is updated only when versioning is enabled.

Suggested implementation:

```python
    def get_list_display(self, request):
        list_display = super().get_list_display(request)
        if getattr(self, "versioning_enabled", False):
            list_display = list(list_display)
            list_display.insert(-1, "get_author")
            list_display.insert(-1, "get_modified_date")
        return list_display

```

Make sure that your admin class has a `versioning_enabled` attribute or property that accurately reflects whether versioning is enabled. If the flag is named differently or is set elsewhere, adjust the attribute name accordingly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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 this pull request may close these issues.

Missing methods get_author and get_modified_date in admin

2 participants