Skip to content

Commit 873d083

Browse files
committed
Apply code formatting with Black and isort
- Format all Python files with Black (88 char line length) - Fix import order with isort - Ensure code style compliance for CI/CD workflows - No functional changes, only formatting improvements
1 parent 7c287ad commit 873d083

38 files changed

+2953
-1948
lines changed

accounts/admin.py

Lines changed: 85 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.contrib import admin
2-
from django.utils.html import format_html
32
from django.urls import reverse
3+
from django.utils.html import format_html
4+
45
from .models import SavingsAccount
56

67

@@ -10,174 +11,151 @@ class SavingsAccountAdmin(admin.ModelAdmin):
1011
Admin configuration for SavingsAccount model.
1112
Optimized for banking account management.
1213
"""
13-
14+
1415
# Fields shown in list
1516
list_display = (
16-
'account_number',
17-
'customer_link',
18-
'balance_display_formatted',
19-
'currency',
20-
'status',
21-
'opening_date',
22-
'last_movement_date',
23-
'version'
17+
"account_number",
18+
"customer_link",
19+
"balance_display_formatted",
20+
"currency",
21+
"status",
22+
"opening_date",
23+
"last_movement_date",
24+
"version",
2425
)
25-
26+
2627
# Side filters
2728
list_filter = (
28-
'status',
29-
'currency',
30-
'opening_date',
31-
'customer__status',
29+
"status",
30+
"currency",
31+
"opening_date",
32+
"customer__status",
3233
)
33-
34+
3435
# Search fields
3536
search_fields = (
36-
'account_number',
37-
'customer__first_names',
38-
'customer__last_names',
39-
'customer__document_number',
40-
'customer__email'
37+
"account_number",
38+
"customer__first_names",
39+
"customer__last_names",
40+
"customer__document_number",
41+
"customer__email",
4142
)
42-
43+
4344
# Default ordering
44-
ordering = ('-opening_date',)
45-
45+
ordering = ("-opening_date",)
46+
4647
# Inline editable fields
47-
list_editable = ('status',)
48-
48+
list_editable = ("status",)
49+
4950
# Fieldset configuration for the form
5051
fieldsets = (
51-
('Información de Cuenta', {
52-
'fields': (
53-
'account_number',
54-
'customer',
55-
'currency'
56-
)
57-
}),
58-
('Saldos', {
59-
'fields': (
60-
'current_balance',
61-
'available_balance'
62-
)
63-
}),
64-
('Estado y Control', {
65-
'fields': (
66-
'status',
67-
'version'
68-
)
69-
}),
70-
('Fechas', {
71-
'fields': (
72-
'opening_date',
73-
'last_movement_date'
74-
),
75-
'classes': ('collapse',)
76-
})
52+
(
53+
"Información de Cuenta",
54+
{"fields": ("account_number", "customer", "currency")},
55+
),
56+
("Saldos", {"fields": ("current_balance", "available_balance")}),
57+
("Estado y Control", {"fields": ("status", "version")}),
58+
(
59+
"Fechas",
60+
{
61+
"fields": ("opening_date", "last_movement_date"),
62+
"classes": ("collapse",),
63+
},
64+
),
7765
)
78-
66+
7967
# Read-only fields
80-
readonly_fields = (
81-
'opening_date',
82-
'version'
83-
)
84-
68+
readonly_fields = ("opening_date", "version")
69+
8570
# Date filters
86-
date_hierarchy = 'opening_date'
87-
71+
date_hierarchy = "opening_date"
72+
8873
def customer_link(self, obj):
8974
"""Shows customer with link to customer admin"""
9075
if obj.customer:
9176
return format_html(
9277
'<a href="{}?id={}">{}</a>',
93-
reverse('admin:customers_customer_changelist'),
78+
reverse("admin:customers_customer_changelist"),
9479
obj.customer.id,
95-
obj.customer.full_name
80+
obj.customer.full_name,
9681
)
97-
return '-'
98-
customer_link.short_description = 'Cliente'
99-
82+
return "-"
83+
84+
customer_link.short_description = "Cliente"
85+
10086
def balance_display_formatted(self, obj):
10187
"""Shows formatted balance with color coding"""
10288
balance = obj.current_balance
10389
if balance == 0:
104-
color = 'gray'
90+
color = "gray"
10591
elif balance < 100:
106-
color = 'orange'
92+
color = "orange"
10793
else:
108-
color = 'green'
109-
94+
color = "green"
95+
11096
return format_html(
11197
'<span style="color: {}; font-weight: bold;">{} {}</span>',
11298
color,
11399
balance,
114-
obj.currency
100+
obj.currency,
115101
)
116-
balance_display_formatted.short_description = 'Saldo Actual'
117-
102+
103+
balance_display_formatted.short_description = "Saldo Actual"
104+
118105
def status_display(self, obj):
119106
"""Shows status with colors"""
120-
colors = {
121-
'ACTIVE': 'green',
122-
'BLOCKED': 'orange',
123-
'CLOSED': 'red'
124-
}
125-
color = colors.get(obj.status, 'black')
107+
colors = {"ACTIVE": "green", "BLOCKED": "orange", "CLOSED": "red"}
108+
color = colors.get(obj.status, "black")
126109
return format_html(
127110
'<span style="color: {}; font-weight: bold;">{}</span>',
128111
color,
129-
obj.get_status_display()
112+
obj.get_status_display(),
130113
)
131-
status_display.short_description = 'Estado'
132-
114+
115+
status_display.short_description = "Estado"
116+
133117
def get_queryset(self, request):
134118
"""Optimizes queries with select_related"""
135-
return super().get_queryset(request).select_related('customer')
136-
119+
return super().get_queryset(request).select_related("customer")
120+
137121
# Custom actions
138-
actions = ['activate_accounts', 'block_accounts', 'close_accounts']
139-
122+
actions = ["activate_accounts", "block_accounts", "close_accounts"]
123+
140124
def activate_accounts(self, request, queryset):
141125
"""Activates selected accounts"""
142-
count = queryset.update(status='ACTIVE')
143-
self.message_user(
144-
request,
145-
f'{count} cuenta(s) activada(s) exitosamente.'
146-
)
126+
count = queryset.update(status="ACTIVE")
127+
self.message_user(request, f"{count} cuenta(s) activada(s) exitosamente.")
128+
147129
activate_accounts.short_description = "Activar cuentas seleccionadas"
148-
130+
149131
def block_accounts(self, request, queryset):
150132
"""Blocks selected accounts"""
151-
count = queryset.update(status='BLOCKED')
152-
self.message_user(
153-
request,
154-
f'{count} cuenta(s) bloqueada(s) exitosamente.'
155-
)
133+
count = queryset.update(status="BLOCKED")
134+
self.message_user(request, f"{count} cuenta(s) bloqueada(s) exitosamente.")
135+
156136
block_accounts.short_description = "Bloquear cuentas seleccionadas"
157-
137+
158138
def close_accounts(self, request, queryset):
159139
"""Closes selected accounts"""
160140
# Only close accounts with zero balance
161141
zero_balance_accounts = queryset.filter(current_balance=0)
162-
count = zero_balance_accounts.update(status='CLOSED')
163-
142+
count = zero_balance_accounts.update(status="CLOSED")
143+
164144
if count < queryset.count():
165145
self.message_user(
166146
request,
167-
f'{count} cuenta(s) cerrada(s). Solo se pueden cerrar cuentas con saldo cero.',
168-
level='WARNING'
147+
f"{count} cuenta(s) cerrada(s). Solo se pueden cerrar cuentas con saldo cero.",
148+
level="WARNING",
169149
)
170150
else:
171-
self.message_user(
172-
request,
173-
f'{count} cuenta(s) cerrada(s) exitosamente.'
174-
)
151+
self.message_user(request, f"{count} cuenta(s) cerrada(s) exitosamente.")
152+
175153
close_accounts.short_description = "Cerrar cuentas seleccionadas (solo saldo cero)"
176-
154+
177155
# Additional configuration
178156
list_per_page = 25
179157
list_max_show_all = 100
180-
158+
181159
def save_model(self, request, obj, form, change):
182160
"""Override for additional logic if needed"""
183161
super().save_model(request, obj, form, change)

accounts/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33

44
class AccountsConfig(AppConfig):
5-
default_auto_field = 'django.db.models.BigAutoField'
6-
name = 'accounts'
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "accounts"

0 commit comments

Comments
 (0)