-
-
Notifications
You must be signed in to change notification settings - Fork 323
feat: add admin method docstrings #2802
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
base: main
Are you sure you want to change the base?
feat: add admin method docstrings #2802
Conversation
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughDocstrings were expanded across multiple admin modules; most edits are documentation-only. One behavioral change: Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (8)
🚧 Files skipped from review as they are similar to previous changes (5)
🧰 Additional context used🧬 Code graph analysis (1)backend/apps/owasp/admin/entity_member.py (1)
🔇 Additional comments (6)
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. Comment |
There was a problem hiding this 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
📒 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 behaviorThe updated docstring clearly reflects the
projectmethod’s behavior and follows the stated docstring conventions. No changes needed.backend/apps/slack/admin/member.py (1)
26-33: Nice, clear admin action docstringThe new docstring concisely explains what the action does and documents
requestandquerysetclearly while matching existing behavior. Looks good.backend/apps/owasp/admin/project.py (1)
56-58: Docstring matches list display behaviorThe updated docstring accurately describes the
custom_field_namefallback tonameorkeyand 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_reviewedThe new docstring for
mark_as_reviewednicely documents what the action does and the meaning of each parameter without leaking implementation details. Looks good.
71-80: channel_search_display docstring matches behaviorThe 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 helpfulThe expanded docstring for
get_formclearly 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 consistentThe new docstrings for
approve_members,entity,owasp_url, andget_search_resultsclearly describe each method’s purpose and inputs/outputs while staying concise. They align with the existing behavior (including the DISTINCT flag inget_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 alignedThe 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 clarityThe added docstring for
formfield_for_dbfielddocuments the special handling forchannel_idandchannel_typefields, making the inline behavior aroundConversation-only content types much easier to understand.
121-135: GenericEntityAdminMixin.get_queryset docstring matches prefetch logicThe 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 aboutentity_leaders). Based on learnings, this looks appropriate.
136-147: custom_field_github_urls docstring is accurate and conciseThe docstring succinctly describes that this method returns formatted GitHub repository links for the entity, matching the HTML-link–generating implementation and its
owasp_repositoryfallback.
149-156: custom_field_owasp_url docstring matches OWASP link behaviorThe 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
escapeandmark_safe.
158-178: _format_github_link documentation clearly captures edge casesThe new docstring thoroughly documents the expected
repositoryargument 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: Clarifyget_querysetdocstring to reflectselect_relatedAs with
MemberProfileAdmin, the docstring mentions "prefetched relations" while the code usesselect_related("github_user"). To avoid confusion between Django'sselect_relatedandprefetch_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 withselect_relatedbehaviorThe Returns section says "prefetched relations" while the implementation uses
select_related("github_user"). In Django,select_relatedandprefetch_relatedare 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.
db2f1d3 to
4363059
Compare
|
@rudransh-shrivastava @kasya @arkid15r can u review the pr ? |
|



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 tocustom_field_github_url(),custom_field_title(),get_search_results()backend/apps/github/admin/pull_request.py: Added docstrings tocustom_field_github_url(),get_search_results()backend/apps/github/admin/repository.py: Verified existing docstrings comply with PEP 257OWASP admin:
backend/apps/owasp/admin/entity.py: Added docstrings tocustom_field_github_url(),get_queryset()backend/apps/owasp/admin/entity_member.py: Added docstrings toentity(),owasp_url(),get_search_results(),approve_members()backend/apps/owasp/admin/member.py: Added docstrings tocustom_field_github_url(),approve_suggested_users()backend/apps/owasp/admin/mixins.py: Added docstrings toReadOnlyFieldsMixin.get_readonly_fields(),ApprovalMixin.approve_selected()backend/apps/owasp/admin/project.py: Added docstrings tocustom_field_github_url(),get_queryset()backend/apps/owasp/admin/project_health_metrics.py: Added docstrings toget_queryset()Slack admin:
backend/apps/slack/admin/workspace.py: Added docstrings toget_queryset()All docstrings follow PEP 257 style with:
Checklist
make check-testlocally; all checks and tests passed.