1212
1313
1414class BaseOwaspAdminMixin :
15- """Base mixin for OWASP admin classes providing common patterns."""
15+ """Base mixin for OWASP admin classes.
16+
17+ Provides common configuration patterns—such as default list_display,
18+ list_filter, and search_fields—so individual ModelAdmin classes can avoid
19+ duplicated boilerplate.
20+ """
1621
1722 # Common configuration patterns.
1823 list_display_field_names = (
@@ -26,20 +31,20 @@ class BaseOwaspAdminMixin:
2631 )
2732
2833 def get_base_list_display (self , * additional_fields ):
29- """Get base list display with additional fields."""
34+ """Construct a standard list_display value with optional extra fields."""
3035 return tuple (
3136 ("name" ,) if hasattr (self .model , "name" ) else (),
3237 * additional_fields ,
3338 * self .list_display_field_names ,
3439 )
3540
3641 def get_base_search_fields (self , * additional_fields ):
37- """Get base search fields with additional fields."""
42+ """Construct a standard search_fields value with optional extra fields."""
3843 return self .search_field_names + additional_fields
3944
4045
4146class EntityMemberInline (GenericTabularInline ):
42- """EntityMember inline for admin ."""
47+ """Inline admin for EntityMember entries linking users to OWASP entities ."""
4348
4449 ct_field = "entity_type"
4550 ct_fk_field = "entity_id"
@@ -63,7 +68,7 @@ class EntityMemberInline(GenericTabularInline):
6368
6469
6570class EntityChannelInline (GenericTabularInline ):
66- """EntityChannel inline for admin ."""
71+ """Inline admin interface for EntityChannel records associated with an entity ."""
6772
6873 ct_field = "entity_type"
6974 ct_fk_field = "entity_id"
@@ -80,7 +85,11 @@ class EntityChannelInline(GenericTabularInline):
8085 ordering = ("platform" , "channel_id" )
8186
8287 def formfield_for_dbfield (self , db_field , request , ** kwargs ):
83- """Override to add custom widget for channel_id field and limit channel_type options."""
88+ """Customize form widgets for EntityChannel inline fields.
89+
90+ - Uses a custom ChannelIdWidget for the channel_id field.
91+ - Limits channel_type choices to only Slack Conversation content types.
92+ """
8493 if db_field .name == "channel_id" :
8594 kwargs ["widget" ] = ChannelIdWidget ()
8695 elif db_field .name == "channel_type" :
@@ -93,14 +102,26 @@ def formfield_for_dbfield(self, db_field, request, **kwargs):
93102
94103
95104class GenericEntityAdminMixin (BaseOwaspAdminMixin ):
96- """Mixin for generic entity admin with common entity functionality."""
105+ """Mixin providing common rendering logic for OWASP entity admin views.
106+
107+ Adds helpers for displaying GitHub and OWASP links and prefetches related
108+ repositories for performance.
109+ """
97110
98111 def get_queryset (self , request ):
99- """Get queryset with optimized relations."""
112+ """Extend the base queryset to prefetch related repositories.
113+
114+ This reduces SQL queries when displaying GitHub-related fields.
115+ """
100116 return super ().get_queryset (request ).prefetch_related ("repositories" )
101117
102118 def custom_field_github_urls (self , obj ):
103- """Entity GitHub URLs with uniform formatting."""
119+ """Render GitHub URLs for the associated entity.
120+
121+ Handles:
122+ - Entities with multiple repositories (uses obj.repositories)
123+ - Entities with a single owasp_repository field
124+ """
104125 if not hasattr (obj , "repositories" ):
105126 if not hasattr (obj , "owasp_repository" ) or not obj .owasp_repository :
106127 return ""
@@ -113,7 +134,7 @@ def custom_field_github_urls(self, obj):
113134 )
114135
115136 def custom_field_owasp_url (self , obj ):
116- """Entity OWASP URL with uniform formatting ."""
137+ """Render a link to the official OWASP entity webpage ."""
117138 if not hasattr (obj , "key" ) or not obj .key :
118139 return ""
119140
@@ -122,7 +143,7 @@ def custom_field_owasp_url(self, obj):
122143 )
123144
124145 def _format_github_link (self , repository ):
125- """Format a single GitHub repository link."""
146+ """Format a GitHub repository link consistently ."""
126147 if not repository or not hasattr (repository , "owner" ) or not repository .owner :
127148 return ""
128149 if not hasattr (repository .owner , "login" ) or not repository .owner .login :
@@ -140,12 +161,16 @@ def _format_github_link(self, repository):
140161
141162
142163class StandardOwaspAdminMixin (BaseOwaspAdminMixin ):
143- """Standard mixin for simple OWASP admin classes."""
164+ """Simple mixin for OWASP admin classes.
165+
166+ Provides convenient helpers for generating common admin config
167+ (list_display, list_filter, search_fields).
168+ """
144169
145170 def get_common_config (
146171 self , extra_list_display = None , extra_search_fields = None , extra_list_filters = None
147172 ):
148- """Get common admin configuration to reduce boilerplate ."""
173+ """Build a dictionary of common ModelAdmin configuration values ."""
149174 config = {}
150175
151176 if extra_list_display :
0 commit comments