Skip to content

Conversation

@kris70lesgo
Copy link
Contributor

Proposed change

Resolves #2651

Add PEP 257–compliant docstrings to admin methods across Django admin classes in backend/apps/*/admin/*.py. This improves code documentation, readability, and onboarding for maintainers and contributors.

Changes made:

GitHub admin:

  • backend/apps/github/admin/issue.py: Added docstrings to custom_field_github_url(), custom_field_title(), get_search_results()
  • backend/apps/github/admin/pull_request.py: Added docstrings to custom_field_github_url(), get_search_results()
  • backend/apps/github/admin/repository.py: Verified existing docstrings comply with PEP 257

OWASP admin:

  • backend/apps/owasp/admin/entity.py: Added docstrings to custom_field_github_url(), get_queryset()
  • backend/apps/owasp/admin/entity_member.py: Added docstrings to entity(), owasp_url(), get_search_results(), approve_members()
  • backend/apps/owasp/admin/member.py: Added docstrings to custom_field_github_url(), approve_suggested_users()
  • backend/apps/owasp/admin/mixins.py: Added docstrings to ReadOnlyFieldsMixin.get_readonly_fields(), ApprovalMixin.approve_selected()
  • backend/apps/owasp/admin/project.py: Added docstrings to custom_field_github_url(), get_queryset()
  • backend/apps/owasp/admin/project_health_metrics.py: Added docstrings to get_queryset()

Slack admin:

  • backend/apps/slack/admin/workspace.py: Added docstrings to get_queryset()

All docstrings follow PEP 257 style with:

  • Summary on the same line as opening quotes (D212)
  • Blank line before closing quotes for multi-line docstrings (D413)
  • Descriptive WHAT/WHY focus, no implementation details
  • Args/Returns sections only where meaningful

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 5, 2025

Summary by CodeRabbit

  • Documentation

    • Expanded admin docs across modules to clarify method behavior, parameters, and return values.
  • Refactor

    • Improved admin link rendering for related entities and public site links.
    • Admin search broadened to match related Project/Chapter/Committee identifiers and return distinct results.
    • Admin form handling adjusted: form customization now returns the customized form instance for clearer behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Docstrings were expanded across multiple admin modules; most edits are documentation-only. Two functional changes: EntityChannelAdmin.get_form now explicitly returns the customized form instance, and EntityMemberAdmin.get_search_results was extended to search related Project/Chapter/Committee via ContentType, OR-filter the queryset with those matches, and set use_distinct=True.

Changes

Cohort / File(s) Summary
OWASP — Entity Channel
backend/apps/owasp/admin/entity_channel.py
Expanded docstrings for mark_as_reviewed and channel_search_display. get_form now documents and explicitly returns the customized form instance after calling the superclass.
OWASP — Entity Member
backend/apps/owasp/admin/entity_member.py
Expanded docstrings for approve_members, entity, owasp_url, and get_search_results. entity now builds an admin reverse URL for the related entity. get_search_results now searches related Project/Chapter/Committee by name/key using ContentType, OR-filters the queryset with those matches, and sets use_distinct=True.
OWASP — Member Profiles / Snapshots
backend/apps/owasp/admin/member_profile.py, backend/apps/owasp/admin/member_snapshot.py
Expanded docstrings for get_queryset; behavior unchanged — returns querysets with select_related("github_user").
OWASP — Mixins & Project
backend/apps/owasp/admin/mixins.py, backend/apps/owasp/admin/project.py, backend/apps/owasp/admin/project_health_metrics.py
Minor local refactor in get_base_list_display/get_base_search_fields and expanded docstrings for helper methods (e.g., _format_github_link, custom_field_name, project). No signature changes.
Slack — Admin
backend/apps/slack/admin/member.py
Expanded docstring for approve_suggested_users. No behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review focus:
    • backend/apps/owasp/admin/entity_channel.py: confirm callers and admin lifecycle tolerate get_form returning the form instance.
    • backend/apps/owasp/admin/entity_member.py: validate ContentType construction, composition of the OR-filter, use_distinct=True necessity, and correctness of the admin reverse URL for entity.
    • Quick skim of docstring-only changes and minor refactors for consistency.

Possibly related PRs

Suggested reviewers

  • kasya
  • arkid15r

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add admin method docstrings' is clear, concise, and directly describes the main change—adding docstrings to admin methods. It accurately reflects the primary objective of the PR.
Description check ✅ Passed The PR description is comprehensive and fully related to the changeset. It details which files were modified, what docstrings were added, and references issue #2651. The description includes a checklist confirming guidelines were followed.
Linked Issues check ✅ Passed The PR successfully implements the objectives from issue #2651 by adding PEP 257–compliant docstrings to admin methods across multiple files in backend/apps/*/admin/ directories, covering custom display methods, filters, actions, and overrides like get_queryset().
Out of Scope Changes check ✅ Passed All changes are within scope of issue #2651. The PR adds docstrings to admin methods, improves documentation without altering method signatures or behavior, and focuses exclusively on documentation improvements to backend/apps/*/admin/ files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbb9e38 and 665d3c8.

📒 Files selected for processing (3)
  • backend/apps/owasp/admin/member_profile.py (1 hunks)
  • backend/apps/owasp/admin/member_snapshot.py (1 hunks)
  • backend/apps/owasp/admin/mixins.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/apps/owasp/admin/mixins.py
🔇 Additional comments (2)
backend/apps/owasp/admin/member_profile.py (1)

74-85: Docstring for get_queryset is clear and aligned with style guidance.

The docstring cleanly explains what the override returns, uses correct terminology (QuerySet, HttpRequest), and follows the multi-line docstring conventions you described for this PR. The method body remains simple and matches the description.

backend/apps/owasp/admin/member_snapshot.py (1)

110-121: Updated get_queryset docstring is accurate and consistent.

This docstring now cleanly describes the method’s behavior and return value without drifting into implementation details, and the terminology (QuerySet, github_user) is correct and consistent with other admin classes.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8d6831 and db2f1d3.

📒 Files selected for processing (8)
  • backend/apps/owasp/admin/entity_channel.py (3 hunks)
  • backend/apps/owasp/admin/entity_member.py (2 hunks)
  • backend/apps/owasp/admin/member_profile.py (1 hunks)
  • backend/apps/owasp/admin/member_snapshot.py (1 hunks)
  • backend/apps/owasp/admin/mixins.py (5 hunks)
  • backend/apps/owasp/admin/project.py (1 hunks)
  • backend/apps/owasp/admin/project_health_metrics.py (1 hunks)
  • backend/apps/slack/admin/member.py (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-11-23T11:37:26.253Z
Learnt from: rudransh-shrivastava
Repo: OWASP/Nest PR: 2606
File: backend/apps/api/rest/v0/project.py:43-48
Timestamp: 2025-11-23T11:37:26.253Z
Learning: In the OWASP Nest backend, `entity_leaders` is a `property` method defined in `RepositoryBasedEntityModel` (backend/apps/owasp/models/common.py) that returns a dynamically constructed QuerySet. It cannot be prefetched using standard `prefetch_related()` because Django's prefetch mechanism only works on model fields and relations, not property methods.

Applied to files:

  • backend/apps/owasp/admin/mixins.py
📚 Learning: 2025-09-06T19:28:14.297Z
Learnt from: rudransh-shrivastava
Repo: OWASP/Nest PR: 2223
File: backend/apps/owasp/models/entity_member.py:50-56
Timestamp: 2025-09-06T19:28:14.297Z
Learning: In the OWASP/Nest project, when migrating scraper logic to GitHub .md file parsing, the sync_leaders method uses member_name as the primary identifier for finding and updating existing EntityMember records, not member_email. This approach is chosen because names are more stable identifiers in markdown files, while emails might be added/updated over time.

Applied to files:

  • backend/apps/owasp/admin/entity_member.py
🧬 Code graph analysis (2)
backend/apps/owasp/admin/mixins.py (3)
backend/apps/owasp/admin/member_profile.py (1)
  • get_queryset (74-85)
backend/apps/owasp/admin/member_snapshot.py (1)
  • get_queryset (110-121)
backend/apps/owasp/models/managers/chapter.py (1)
  • get_queryset (10-20)
backend/apps/owasp/admin/entity_member.py (1)
backend/apps/owasp/models/common.py (1)
  • owasp_url (144-146)
🔇 Additional comments (15)
backend/apps/owasp/admin/project_health_metrics.py (1)

31-33: Docstring accurately documents fallback behavior

The updated docstring clearly reflects the project method’s behavior and follows the stated docstring conventions. No changes needed.

backend/apps/slack/admin/member.py (1)

26-33: Nice, clear admin action docstring

The new docstring concisely explains what the action does and documents request and queryset clearly while matching existing behavior. Looks good.

backend/apps/owasp/admin/project.py (1)

56-58: Docstring matches list display behavior

The updated docstring accurately describes the custom_field_name fallback to name or key and follows the project’s docstring style. No changes required.

backend/apps/owasp/admin/entity_channel.py (3)

10-23: Action docstring clearly explains mark_as_reviewed

The new docstring for mark_as_reviewed nicely documents what the action does and the meaning of each parameter without leaking implementation details. Looks good.


71-80: channel_search_display docstring matches behavior

The docstring succinctly captures that this returns a human-friendly channel name (or a fallback) for display, which aligns with the method logic. No changes needed.


84-99: get_form documentation is precise and helpful

The expanded docstring for get_form clearly describes the EntityChannel-specific customization and the returned form class, making this override easier to understand and maintain.

backend/apps/owasp/admin/entity_member.py (1)

45-51: EntityMember admin docstrings are clear and consistent

The new docstrings for approve_members, entity, owasp_url, and get_search_results clearly describe each method’s purpose and inputs/outputs while staying concise. They align with the existing behavior (including the DISTINCT flag in get_search_results) and improve the readability of this admin class.

Also applies to: 58-71, 73-80, 82-93

backend/apps/owasp/admin/mixins.py (6)

44-53: get_base_search_fields docstring and behavior are aligned

The new docstring clearly explains that additional field names are appended to search_field_names, and the implementation using tuple concatenation matches that description.


98-109: formfield_for_dbfield docstring improves inline admin clarity

The added docstring for formfield_for_dbfield documents the special handling for channel_id and channel_type fields, making the inline behavior around Conversation-only content types much easier to understand.


121-135: GenericEntityAdminMixin.get_queryset docstring matches prefetch logic

The docstring correctly states that the queryset is returned with repositories prefetched, which aligns with the prefetch_related("repositories") call and avoids attempting to prefetch non-relational properties (consistent with prior project learnings about entity_leaders). Based on learnings, this looks appropriate.


136-147: custom_field_github_urls docstring is accurate and concise

The docstring succinctly describes that this method returns formatted GitHub repository links for the entity, matching the HTML-link–generating implementation and its owasp_repository fallback.


149-156: custom_field_owasp_url docstring matches OWASP link behavior

The description of returning a formatted link to the entity’s OWASP site (or an empty string when no key is present) accurately reflects the implementation using escape and mark_safe.


158-178: _format_github_link documentation clearly captures edge cases

The new docstring thoroughly documents the expected repository argument and that an empty string is returned when required data is missing. This matches the defensive checks in the method and makes its behavior explicit.

backend/apps/owasp/admin/member_snapshot.py (1)

110-119: Clarify get_queryset docstring to reflect select_related

As with MemberProfileAdmin, the docstring mentions "prefetched relations" while the code uses select_related("github_user"). To avoid confusion between Django's select_related and prefetch_related, align the wording with the implementation.

Consider updating the docstring to say "eagerly loads the related GitHub user" and "Optimized queryset with github_user loaded via select_related" to keep behavior unchanged while making documentation precise.

backend/apps/owasp/admin/member_profile.py (1)

75-83: Align docstring wording with select_related behavior

The Returns section says "prefetched relations" while the implementation uses select_related("github_user"). In Django, select_related and prefetch_related are different mechanisms, so this wording can be misleading.

Suggest adjusting the docstring to match the actual behavior, for example:

-        """Return queryset with select_related github_user.
+        """Return queryset that eagerly loads the related GitHub user.
@@
-        Returns:
-            QuerySet: Optimized queryset with prefetched relations.
+        Returns:
+            QuerySet: Optimized queryset with github_user loaded via select_related.

This keeps the docstring concise while accurately reflecting how the relation is loaded.

@kris70lesgo kris70lesgo force-pushed the feature/admin-docstrings-issue-2651 branch from db2f1d3 to 4363059 Compare December 5, 2025 07:03
@kris70lesgo
Copy link
Contributor Author

kris70lesgo commented Dec 5, 2025

@rudransh-shrivastava @kasya @arkid15r can u review the pr ?
Thanks

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

These changes do not follow docstring good practices. If it's ai-generated the model is bad. In any way you as a PR author is responsible for the contents.

Please do not add implementation details to the docstrings. You should understand method's context first in order to come up with a proper description.


def project(self, obj):
"""Display project name."""
"""Return the project name or N/A if not available."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's with the docstring format here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed with the current commit , duplicate docstring was an incomplete .

Copy link
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: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4363059 and 0b90be6.

📒 Files selected for processing (8)
  • backend/apps/owasp/admin/entity_channel.py (3 hunks)
  • backend/apps/owasp/admin/entity_member.py (2 hunks)
  • backend/apps/owasp/admin/member_profile.py (1 hunks)
  • backend/apps/owasp/admin/member_snapshot.py (1 hunks)
  • backend/apps/owasp/admin/mixins.py (5 hunks)
  • backend/apps/owasp/admin/project.py (1 hunks)
  • backend/apps/owasp/admin/project_health_metrics.py (1 hunks)
  • backend/apps/slack/admin/member.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • backend/apps/owasp/admin/project_health_metrics.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • backend/apps/owasp/admin/entity_channel.py
  • backend/apps/slack/admin/member.py
  • backend/apps/owasp/admin/member_profile.py
  • backend/apps/owasp/admin/entity_member.py
🧰 Additional context used
🧬 Code graph analysis (1)
backend/apps/owasp/admin/mixins.py (3)
backend/apps/owasp/admin/member_profile.py (1)
  • get_queryset (74-85)
backend/apps/owasp/admin/member_snapshot.py (1)
  • get_queryset (110-121)
backend/apps/owasp/models/managers/chapter.py (1)
  • get_queryset (10-20)
🔇 Additional comments (7)
backend/apps/owasp/admin/project.py (1)

56-58: LGTM!

The docstring is clear and concise, describing what the method displays without implementation details.

backend/apps/owasp/admin/mixins.py (6)

28-39: LGTM!

The docstring clearly describes the method's purpose (building list display configuration) with appropriate Args and Returns sections.


41-51: LGTM!

The docstring appropriately describes what the method builds without revealing implementation details.


95-115: LGTM!

The docstring provides a clear description of the customization with well-documented Args and Returns sections.


133-144: LGTM!

The docstring is concise and describes the display purpose clearly.


146-153: LGTM!

Simple and clear description of what the method displays.


155-175: LGTM!

The docstring clearly describes the return value with appropriate Args and Returns documentation.

Copy link
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: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b90be6 and fbb9e38.

📒 Files selected for processing (3)
  • backend/apps/owasp/admin/member_profile.py (1 hunks)
  • backend/apps/owasp/admin/member_snapshot.py (1 hunks)
  • backend/apps/owasp/admin/mixins.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • backend/apps/owasp/admin/member_snapshot.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-23T11:37:26.253Z
Learnt from: rudransh-shrivastava
Repo: OWASP/Nest PR: 2606
File: backend/apps/api/rest/v0/project.py:43-48
Timestamp: 2025-11-23T11:37:26.253Z
Learning: In the OWASP Nest backend, `entity_leaders` is a `property` method defined in `RepositoryBasedEntityModel` (backend/apps/owasp/models/common.py) that returns a dynamically constructed QuerySet. It cannot be prefetched using standard `prefetch_related()` because Django's prefetch mechanism only works on model fields and relations, not property methods.

Applied to files:

  • backend/apps/owasp/admin/mixins.py
🧬 Code graph analysis (1)
backend/apps/owasp/admin/mixins.py (3)
backend/apps/owasp/admin/member_profile.py (1)
  • get_queryset (74-85)
backend/apps/owasp/admin/member_snapshot.py (1)
  • get_queryset (110-121)
backend/apps/owasp/models/managers/chapter.py (1)
  • get_queryset (10-20)
🔇 Additional comments (6)
backend/apps/owasp/admin/mixins.py (6)

28-39: LGTM!

The docstring clearly describes the method's purpose, and the implementation correctly uses tuple concatenation. The refactoring addresses the previous tuple construction issue.


41-51: LGTM!

The docstring is clear and follows the same pattern as get_base_list_display.


95-115: LGTM!

The docstring provides clear documentation for the method parameters and return value.


133-144: LGTM!

The single-line docstring clearly describes the method's display purpose.


146-153: LGTM!

The single-line docstring clearly describes the method's display purpose.


155-175: LGTM!

The docstring provides comprehensive documentation including both the success case (HTML link) and edge case (empty string when data is incomplete).

@sonarqubecloud
Copy link

@kris70lesgo
Copy link
Contributor Author

@arkid15r thanks for taking the time to review the pr , I have removed implementaion details to the docstrings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Docstrings to Admin Class Methods

2 participants