Minor cleanup (fix comments)

This commit is contained in:
zandercymatics 2024-11-18 15:33:39 -07:00
parent 5f5bc4f616
commit a2365831ca
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
2 changed files with 11 additions and 23 deletions

View file

@ -70,7 +70,7 @@ def format_end_date(end_date):
class BaseExport(BaseModelAnnotation): class BaseExport(BaseModelAnnotation):
""" """
A generic class for exporting data which returns a csv file for the given model. A generic class for exporting data which returns a csv file for the given model.
Base class in an inheritance tree of 3. 3rd class in an inheritance tree of 4.
""" """
@classmethod @classmethod
@ -157,6 +157,8 @@ class MemberExport(BaseExport):
@classmethod @classmethod
def get_model_annotation_dict(cls, request=None, **kwargs): def get_model_annotation_dict(cls, request=None, **kwargs):
"""Combines the permissions and invitation model annotations for
the final returned csv export which combines both of these contexts"""
portfolio = request.session.get("portfolio") portfolio = request.session.get("portfolio")
if not portfolio: if not portfolio:
return {} return {}
@ -230,21 +232,9 @@ class MemberExport(BaseExport):
"Member management": member_perm_display, "Member management": member_perm_display,
"Domain management": len(user_managed_domains) > 0, "Domain management": len(user_managed_domains) > 0,
"Number of domains": len(user_managed_domains), "Number of domains": len(user_managed_domains),
# TODO - this doesn't quote enclose with one record
"Domains": managed_domains_as_csv, "Domains": managed_domains_as_csv,
} }
# "id",
# "first_name",
# "last_name",
# "email_display",
# "last_active",
# "roles",
# "additional_permissions_display",
# "member_display",
# "domain_info",
# "source",
row = [FIELDS.get(column, "") for column in columns] row = [FIELDS.get(column, "") for column in columns]
return row return row

View file

@ -1,16 +1,12 @@
""" """
Model annotation classes. Intended to return django querysets with computed fields for api endpoints and our csv reports. Model annotation classes.
Created to manage the complexity of the MembersTable and Members CSV report, as they require complex but common annotations.
These classes provide consistent, reusable query transformations that:
1. Add computed fields via annotations
2. Handle related model data
3. Format fields for display
4. Standardize field names across different contexts
Intended to return django querysets with computed fields for api endpoints and our csv reports.
Used by both API endpoints (e.g. portfolio members JSON) and data exports (e.g. CSV reports). Used by both API endpoints (e.g. portfolio members JSON) and data exports (e.g. CSV reports).
Initially created to manage the complexity of the MembersTable and Members CSV report,
as they require complex but common annotations.
Example: Example:
# For a JSON table endpoint # For a JSON table endpoint
permissions = UserPortfolioPermissionAnnotation.get_annotated_queryset(portfolio) permissions = UserPortfolioPermissionAnnotation.get_annotated_queryset(portfolio)
@ -59,6 +55,8 @@ class BaseModelAnnotation(ABC):
Subclasses define model-specific annotations, filters, and field formatting while inheriting Subclasses define model-specific annotations, filters, and field formatting while inheriting
common queryset building logic. common queryset building logic.
Intended ensure consistent data presentation across both table UI components and CSV exports. Intended ensure consistent data presentation across both table UI components and CSV exports.
Base class in an inheritance tree of 4.
""" """
@classmethod @classmethod
@ -253,7 +251,7 @@ class UserPortfolioPermissionModelAnnotation(BaseModelAnnotation):
PortfolioInvitation.objects.filter( PortfolioInvitation.objects.filter(
status=PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED, status=PortfolioInvitation.PortfolioInvitationStatus.RETRIEVED,
# Double outer ref because we first go into the LogEntry query, # Double outer ref because we first go into the LogEntry query,
# then into the # then into the parent UserPortfolioPermission.
email=OuterRef(OuterRef("user__email")), email=OuterRef(OuterRef("user__email")),
portfolio=OuterRef(OuterRef("portfolio")), portfolio=OuterRef(OuterRef("portfolio")),
).values("id")[:1] ).values("id")[:1]