Skip to content

Commit 375d26e

Browse files
committed
refactor(admin): update docstrings in backend/apps per review
1 parent 2d3c433 commit 375d26e

File tree

2 files changed

+11
-51
lines changed

2 files changed

+11
-51
lines changed

backend/apps/owasp/admin/entity_member.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class EntityMemberAdmin(admin.ModelAdmin):
4242

4343
@admin.action(description="Approve selected members")
4444
def approve_members(self, request, queryset):
45-
"""
46-
Admin action to approve selected entity members.
45+
"""Admin action to approve selected entity members.
4746
4847
Sets `is_active=True` and `is_reviewed=True` on all selected records
4948
and displays a success message showing how many were updated.
@@ -55,8 +54,7 @@ def approve_members(self, request, queryset):
5554

5655
@admin.display(description="Entity", ordering="entity_type")
5756
def entity(self, obj):
58-
"""
59-
Return a clickable admin link to the related entity.
57+
"""Return a clickable admin link to the related entity.
6058
6159
Example output: a link to the Project/Chapter/Committee admin change page.
6260
"""
@@ -83,8 +81,7 @@ def owasp_url(self, obj):
8381
)
8482

8583
def get_search_results(self, request, queryset, search_term):
86-
"""
87-
Extend default search to also match entity names and keys.
84+
"""Extend default search to also match entity names and keys.
8885
8986
In addition to the built-in search, this method searches:
9087
- Project name or key

backend/apps/owasp/admin/mixins.py

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313

1414
class BaseOwaspAdminMixin:
15-
"""
16-
Base mixin for OWASP admin classes.
15+
"""Base mixin for OWASP admin classes.
1716
1817
Provides common configuration patterns—such as default list_display,
1918
list_filter, and search_fields—so individual ModelAdmin classes can avoid
@@ -86,19 +85,10 @@ class EntityChannelInline(GenericTabularInline):
8685
ordering = ("platform", "channel_id")
8786

8887
def formfield_for_dbfield(self, db_field, request, **kwargs):
89-
"""
90-
Customize form widgets for EntityChannel inline fields.
88+
"""Customize form widgets for EntityChannel inline fields.
9189
9290
- Uses a custom ChannelIdWidget for the channel_id field.
9391
- Limits channel_type choices to only Slack Conversation content types.
94-
95-
Args:
96-
db_field (Field): The model field being rendered.
97-
request (HttpRequest): The current request.
98-
**kwargs: Additional keyword arguments passed to the widget.
99-
100-
Returns:
101-
FormField: The configured form field instance.
10292
"""
10393
if db_field.name == "channel_id":
10494
kwargs["widget"] = ChannelIdWidget()
@@ -112,16 +102,14 @@ def formfield_for_dbfield(self, db_field, request, **kwargs):
112102

113103

114104
class GenericEntityAdminMixin(BaseOwaspAdminMixin):
115-
"""
116-
Mixin providing common rendering logic for OWASP entity admin views.
105+
"""Mixin providing common rendering logic for OWASP entity admin views.
117106
118107
Adds helpers for displaying GitHub and OWASP links and prefetches related
119108
repositories for performance.
120109
"""
121110

122111
def get_queryset(self, request):
123-
"""
124-
Extend the base queryset to prefetch related repositories.
112+
"""Extend the base queryset to prefetch related repositories.
125113
126114
This reduces SQL queries when displaying GitHub-related fields.
127115
@@ -134,18 +122,11 @@ def get_queryset(self, request):
134122
return super().get_queryset(request).prefetch_related("repositories")
135123

136124
def custom_field_github_urls(self, obj):
137-
"""
138-
Render GitHub URLs for the associated entity.
125+
"""Render GitHub URLs for the associated entity.
139126
140127
Handles:
141128
- Entities with multiple repositories (uses obj.repositories)
142129
- Entities with a single owasp_repository field
143-
144-
Args:
145-
obj: The entity instance.
146-
147-
Returns:
148-
str: HTML-safe formatted GitHub links.
149130
"""
150131
if not hasattr(obj, "repositories"):
151132
if not hasattr(obj, "owasp_repository") or not obj.owasp_repository:
@@ -159,15 +140,7 @@ def custom_field_github_urls(self, obj):
159140
)
160141

161142
def custom_field_owasp_url(self, obj):
162-
"""
163-
Render a link to the official OWASP entity webpage.
164-
165-
Args:
166-
obj: The entity instance.
167-
168-
Returns:
169-
str: HTML-safe link to https://owasp.org/<entity_key>.
170-
"""
143+
"""Render a link to the official OWASP entity webpage."""
171144
if not hasattr(obj, "key") or not obj.key:
172145
return ""
173146

@@ -176,16 +149,7 @@ def custom_field_owasp_url(self, obj):
176149
)
177150

178151
def _format_github_link(self, repository):
179-
"""
180-
Format a GitHub repository link consistently.
181-
182-
Args:
183-
repository: A repository instance with owner.login and key attributes.
184-
185-
Returns:
186-
str: HTML-safe anchor tag linking to the GitHub repo, or empty string
187-
if required fields are missing.
188-
"""
152+
"""Format a GitHub repository link consistently."""
189153
if not repository or not hasattr(repository, "owner") or not repository.owner:
190154
return ""
191155
if not hasattr(repository.owner, "login") or not repository.owner.login:
@@ -203,8 +167,7 @@ def _format_github_link(self, repository):
203167

204168

205169
class StandardOwaspAdminMixin(BaseOwaspAdminMixin):
206-
"""
207-
Simple mixin for OWASP admin classes.
170+
"""Simple mixin for OWASP admin classes.
208171
209172
Provides convenient helpers for generating common admin config
210173
(list_display, list_filter, search_fields).

0 commit comments

Comments
 (0)