Skip to content

Admin action groups#3

Merged
KommuSoft merged 3 commits intomasterfrom
admin-action-groups
Jun 13, 2025
Merged

Admin action groups#3
KommuSoft merged 3 commits intomasterfrom
admin-action-groups

Conversation

@KommuSoft
Copy link
Copy Markdown
Member

@KommuSoft KommuSoft commented Jun 13, 2025

Summary by CodeRabbit

  • New Features
    • Introduced the ability to group Django admin actions into categories, improving organization and navigation in the admin interface.
  • Documentation
    • Added a new section to the README explaining how to use action grouping, including usage examples and details on the new grouping functionality.
  • Chores
    • Updated and simplified the publishing workflow for package releases.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 13, 2025

Caution

Review failed

The pull request is closed.

"""

Walkthrough

The changes introduce a new Django admin feature for grouping actions using a GroupedActionAdminMixin and a grouped_action decorator, update the documentation with usage instructions, and streamline the CI workflow by consolidating publishing steps into a single job that publishes to PyPI on master or tag pushes.

Changes

File(s) Change Summary
.github/workflows/django-adminlink-ci.yml Renamed test-publish job to publish, removed redundant publish job, consolidated and simplified steps.
README.md Added documentation for grouping admin actions with GroupedActionAdminMixin and grouped_action.
django_adminlink/admin.py Added grouped_action decorator, GroupedActionAdminMixin, and GroupedActionAdmin class for grouped actions.

Sequence Diagram(s)

sequenceDiagram
    participant AdminUser
    participant DjangoAdmin
    participant GroupedActionAdminMixin

    AdminUser->>DjangoAdmin: Open admin actions menu
    DjangoAdmin->>GroupedActionAdminMixin: get_action_choices(request)
    GroupedActionAdminMixin-->>DjangoAdmin: Return grouped actions by action_group
    DjangoAdmin-->>AdminUser: Display grouped actions in UI
    AdminUser->>DjangoAdmin: Select grouped action
    DjangoAdmin->>GroupedActionAdminMixin: Execute selected action
Loading

Possibly related PRs

  • parameterize namespace #1: Introduces SingleItemActionMixin and SingleItemActionAdmin for per-row action buttons; related as both PRs extend admin action functionality and define similar base classes.

Poem

🐇
In the garden of Django, actions now bloom,
Grouped by their purpose, dispelling the gloom.
With a mixin and decorator, the admin feels new,
While the CI hops forward, its steps now few.
The README grows richer, the features in view!

"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e233204 and c48abdf.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • django_adminlink/admin.py (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
.github/workflows/django-adminlink-ci.yml (1)

107-124: Reuse build artefacts instead of rebuilding in publish job

publish repeats an entire build (setup.py sdist bdist_wheel) although the same artefacts are already produced in the build job.
Duplicating work slows the pipeline and risks publishing wheels built under a different Python version than the matrix used for tests.

Consider uploading the artefacts in build with actions/upload-artifact and downloading them here, then feed them to pypa/gh-action-pypi-publish.

-    - run: |
-        pip install 'setuptools>=38.6.0,<69.0' twine>=1.11.0 wheel>=0.31.0 setuptools_scm>=6.2
-        python -m setuptools_scm
-        python setup.py sdist bdist_wheel
+    - uses: actions/download-artifact@v3
+      with:
+        name: dist

This keeps CI faster and ensures the tested artefact is the one released.

🧰 Tools
🪛 actionlint (1.7.7)

115-115: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

README.md (2)

89-92: Minor grammar – add comma after introductory phrase

“For this we introduced …” → “For this, we introduced …”
This matches LanguageTool’s suggestion.

🧰 Tools
🪛 LanguageTool

[typographical] ~89-~89: Use a comma after an introductory phrase.
Context: ...st like in other Django ChoiceFields. For this we introduced the `GroupedActionAdminMi...

(COMMA_INTRODUCTORY_WORDS_PHRASES)


116-116: Spelling typo

“indivual” → “individual”.

django_adminlink/admin.py (2)

135-151: Streamline grouped_action implementation

  1. Early-return makes the else block unnecessary (pylint R1705).
  2. When the decorator is used without arguments (@grouped_action) any supplied permissions/description are silently ignored. Forward them for consistency.
 def grouped_action(function=None, *, permissions=None, description=None, action_group=None):
-    if function is None:
-        base_decorator = admin.action(permissions=permissions, description=description)
-        def decorator(func):
-            func = base_decorator(func)
-            func.action_group = action_group
-            return func
-        return decorator
-    else:
-        function = admin.action(function)
-        function.action_group = action_group
-        return function
+    if function is None:
+        def decorator(func):
+            wrapped = admin.action(
+                permissions=permissions, description=description
+            )(func)
+            wrapped.action_group = action_group
+            return wrapped
+        return decorator
+
+    wrapped = admin.action(
+        permissions=permissions, description=description
+    )(function)
+    wrapped.action_group = action_group
+    return wrapped
🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 138-150: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


154-162: Return value should preserve deterministic order

grouped_items is a defaultdict(list) – order is preserved, but wrapping it with a list-comprehension is unnecessary:

-        return [(k, v) for k, v in grouped_items.items()]
+        return list(grouped_items.items())

Pure readability; no functional change.

🧰 Tools
🪛 Pylint (3.3.7)

[refactor] 161-161: Unnecessary use of a comprehension, use list(grouped_items.items()) instead.

(R1721)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6932353 and e233204.

📒 Files selected for processing (3)
  • .github/workflows/django-adminlink-ci.yml (1 hunks)
  • README.md (1 hunks)
  • django_adminlink/admin.py (2 hunks)
🧰 Additional context used
🪛 LanguageTool
README.md

[typographical] ~89-~89: Use a comma after an introductory phrase.
Context: ...st like in other Django ChoiceFields. For this we introduced the `GroupedActionAdminMi...

(COMMA_INTRODUCTORY_WORDS_PHRASES)

🪛 Pylint (3.3.7)
django_adminlink/admin.py

[refactor] 138-150: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it

(R1705)


[refactor] 161-161: Unnecessary use of a comprehension, use list(grouped_items.items()) instead.

(R1721)


[refactor] 153-153: Too few public methods (1/2)

(R0903)

🔇 Additional comments (1)
README.md (1)

100-105: Example misses SingleItemActionMixin

action_buttons is only interpreted by SingleItemActionMixin.
Either add the mixin:

-class MovieAdmin(GroupedActionAdminMixin, admin.ModelAdmin):
+class MovieAdmin(GroupedActionAdminMixin, SingleItemActionMixin, admin.ModelAdmin):

or drop action_buttons to avoid confusion.

Comment thread django_adminlink/admin.py
Comment on lines +164 to +165
class GroupedActionAdmin(SingleItemActionMixin, admin.ModelAdmin):
pass
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

GroupedActionAdmin does not enable grouping – missing mixin

GroupedActionAdmin currently inherits only SingleItemActionMixin, so get_action_choices stays unpatched and no groups will appear in the UI.

-class GroupedActionAdmin(SingleItemActionMixin, admin.ModelAdmin):
+class GroupedActionAdmin(GroupedActionAdminMixin, SingleItemActionMixin, admin.ModelAdmin):

Without this, users following the README example will see a flat action list.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class GroupedActionAdmin(SingleItemActionMixin, admin.ModelAdmin):
pass
class GroupedActionAdmin(GroupedActionAdminMixin, SingleItemActionMixin, admin.ModelAdmin):
pass
🤖 Prompt for AI Agents
In django_adminlink/admin.py at lines 164-165, the GroupedActionAdmin class
lacks the mixin that enables action grouping, so get_action_choices is not
overridden and no grouped actions appear in the UI. To fix this, add the
appropriate mixin that patches get_action_choices for grouping alongside
SingleItemActionMixin in the class inheritance list.

@KommuSoft KommuSoft merged commit 29e726e into master Jun 13, 2025
22 of 23 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jun 13, 2025
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.

1 participant