Skip to content

Commit 285642f

Browse files
committed
- blackened the entire NEMO codebase, limiting to 120 characters in width
1 parent 8bf5feb commit 285642f

File tree

165 files changed

+28457
-22845
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+28457
-22845
lines changed

NEMO/__init__.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,40 @@
55

66

77
def init_admin_site():
8-
from NEMO.views.customization import ApplicationCustomization, ProjectsAccountsCustomization
9-
from NEMO.admin import ProjectAdmin
10-
from django.contrib import admin
11-
12-
# customize the site
13-
site_title = ApplicationCustomization.get("site_title", raise_exception=False)
14-
admin.site.login = login_required(admin.site.login)
15-
admin.site.site_header = site_title
16-
admin.site.site_title = site_title
17-
admin.site.index_title = "Detailed administration"
18-
# update the short_description for project's application identifier here after initialization
19-
ProjectAdmin.get_application_identifier.short_description = ProjectsAccountsCustomization.get(
20-
"project_application_identifier_name", raise_exception=False)
8+
from NEMO.views.customization import ApplicationCustomization, ProjectsAccountsCustomization
9+
from NEMO.admin import ProjectAdmin
10+
from django.contrib import admin
11+
12+
# customize the site
13+
site_title = ApplicationCustomization.get("site_title", raise_exception=False)
14+
admin.site.login = login_required(admin.site.login)
15+
admin.site.site_header = site_title
16+
admin.site.site_title = site_title
17+
admin.site.index_title = "Detailed administration"
18+
# update the short_description for project's application identifier here after initialization
19+
ProjectAdmin.get_application_identifier.short_description = ProjectsAccountsCustomization.get(
20+
"project_application_identifier_name", raise_exception=False
21+
)
2122

2223

2324
def init_rates():
24-
from NEMO.rates import rate_class
25+
from NEMO.rates import rate_class
2526

26-
rate_class.load_rates()
27+
rate_class.load_rates()
2728

2829

2930
class NEMOConfig(AppConfig):
30-
default_auto_field = "django.db.models.AutoField"
31-
name = "NEMO"
31+
default_auto_field = "django.db.models.AutoField"
32+
name = "NEMO"
3233

33-
def ready(self):
34-
if "migrate" in sys.argv or "makemigrations" in sys.argv:
35-
return
36-
from django.apps import apps
34+
def ready(self):
35+
if "migrate" in sys.argv or "makemigrations" in sys.argv:
36+
return
37+
from django.apps import apps
3738

38-
if apps.is_installed("django.contrib.admin"):
39-
init_admin_site()
40-
init_rates()
39+
if apps.is_installed("django.contrib.admin"):
40+
init_admin_site()
41+
init_rates()
4142

4243

4344
default_app_config = "NEMO.NEMOConfig"

NEMO/actions.py

+90-90
Original file line numberDiff line numberDiff line change
@@ -11,129 +11,129 @@
1111

1212
@admin.action(description="Disable selected cards")
1313
def disable_selected_cards(model_admin, request, queryset: QuerySetType[InterlockCard]):
14-
for interlock_card in queryset:
15-
interlock_card.enabled = False
16-
interlock_card.save(update_fields=["enabled"])
14+
for interlock_card in queryset:
15+
interlock_card.enabled = False
16+
interlock_card.save(update_fields=["enabled"])
1717

1818

1919
@admin.action(description="Enable selected cards")
2020
def enable_selected_cards(model_admin, request, queryset: QuerySetType[InterlockCard]):
21-
for interlock_card in queryset:
22-
interlock_card.enabled = True
23-
interlock_card.save(update_fields=["enabled"])
21+
for interlock_card in queryset:
22+
interlock_card.enabled = True
23+
interlock_card.save(update_fields=["enabled"])
2424

2525

2626
@admin.action(description="Lock selected interlocks")
2727
def lock_selected_interlocks(model_admin, request, queryset):
28-
for interlock in queryset:
29-
try:
30-
command_succeeded = interlock.lock()
31-
if command_succeeded:
32-
messages.success(request, f"{interlock} has been successfully locked")
33-
else:
34-
messages.error(request, f"{interlock} could not be locked. {interlock.most_recent_reply}")
35-
except Exception as error:
36-
messages.error(request, f"{interlock} could not be locked due to the following error: {str(error)}")
28+
for interlock in queryset:
29+
try:
30+
command_succeeded = interlock.lock()
31+
if command_succeeded:
32+
messages.success(request, f"{interlock} has been successfully locked")
33+
else:
34+
messages.error(request, f"{interlock} could not be locked. {interlock.most_recent_reply}")
35+
except Exception as error:
36+
messages.error(request, f"{interlock} could not be locked due to the following error: {str(error)}")
3737

3838

3939
@admin.action(description="Unlock selected interlocks")
4040
def unlock_selected_interlocks(model_admin, request, queryset):
41-
for interlock in queryset:
42-
try:
43-
command_succeeded = interlock.unlock()
44-
if command_succeeded:
45-
messages.success(request, f"{interlock} has been successfully unlocked")
46-
else:
47-
messages.error(request, f"{interlock} could not be unlocked. {interlock.most_recent_reply}")
48-
except Exception as error:
49-
messages.error(request, f"{interlock} could not be unlocked due to the following error: {str(error)}")
41+
for interlock in queryset:
42+
try:
43+
command_succeeded = interlock.unlock()
44+
if command_succeeded:
45+
messages.success(request, f"{interlock} has been successfully unlocked")
46+
else:
47+
messages.error(request, f"{interlock} could not be unlocked. {interlock.most_recent_reply}")
48+
except Exception as error:
49+
messages.error(request, f"{interlock} could not be unlocked due to the following error: {str(error)}")
5050

5151

5252
@admin.action(description="Synchronize selected interlocks with tool usage")
5353
def synchronize_with_tool_usage(model_admin, request, queryset):
54-
for interlock in queryset:
55-
# Ignore interlocks with no tool assigned, and ignore interlocks connected to doors
56-
if not hasattr(interlock, "tool") or hasattr(interlock, "door"):
57-
continue
58-
if interlock.tool.in_use():
59-
interlock.unlock()
60-
else:
61-
interlock.lock()
54+
for interlock in queryset:
55+
# Ignore interlocks with no tool assigned, and ignore interlocks connected to doors
56+
if not hasattr(interlock, "tool") or hasattr(interlock, "door"):
57+
continue
58+
if interlock.tool.in_use():
59+
interlock.unlock()
60+
else:
61+
interlock.lock()
6262

6363

6464
@admin.action(description="Create next interlock")
6565
def create_next_interlock(model_admin, request, queryset):
66-
for interlock in queryset:
67-
new_interlock = Interlock()
68-
new_interlock.card = interlock.card
69-
new_interlock.unit_id = interlock.unit_id
70-
max_channel = Interlock.objects.filter(card=interlock.card).aggregate(Max("channel"))["channel__max"]
71-
new_interlock.channel = max_channel + 1 if max_channel is not None else None
72-
new_interlock.save()
66+
for interlock in queryset:
67+
new_interlock = Interlock()
68+
new_interlock.card = interlock.card
69+
new_interlock.unit_id = interlock.unit_id
70+
max_channel = Interlock.objects.filter(card=interlock.card).aggregate(Max("channel"))["channel__max"]
71+
new_interlock.channel = max_channel + 1 if max_channel is not None else None
72+
new_interlock.save()
7373

7474

7575
@admin.action(description="Duplicate selected tool configuration")
7676
def duplicate_tool_configuration(model_admin, request, queryset):
77-
for tool in queryset:
78-
original_name = tool.name
79-
new_name = "Copy of " + tool.name
80-
try:
81-
if Tool.objects.filter(name=new_name).exists():
82-
messages.error(
83-
request,
84-
mark_safe(
85-
f'There is already a copy of {original_name} as <a href="{reverse("admin:NEMO_tool_change", args=[tool.id])}">{new_name}</a>. Change the copy\'s name and try again'
86-
),
87-
)
88-
continue
89-
elif tool.is_child_tool():
90-
messages.warning(request, f"{original_name} is a child tool and cannot be duplicated")
91-
continue
92-
else:
93-
old_required_resources = tool.required_resource_set.all()
94-
old_nonrequired_resources = tool.nonrequired_resource_set.all()
95-
old_backup_users = tool.backup_owners.all()
96-
old_superusers = tool.superusers.all()
97-
old_reviewers = tool.adjustment_request_reviewers.all()
98-
old_qualified_users = User.objects.filter(qualifications__id=tool.pk).distinct()
99-
tool.pk = None
100-
tool.interlock = None
101-
tool.visible = False
102-
tool.operational = False
103-
tool.name = new_name
104-
tool.image = None
105-
tool.description = None
106-
tool.serial = None
107-
tool.save()
108-
tool.required_resource_set.set(old_required_resources)
109-
tool.nonrequired_resource_set.set(old_nonrequired_resources)
110-
tool.backup_owners.set(old_backup_users)
111-
tool.superusers.set(old_superusers)
112-
tool.adjustment_request_reviewers.set(old_reviewers)
113-
for user in old_qualified_users:
114-
user.qualifications.add(tool)
115-
messages.success(
116-
request,
117-
mark_safe(
118-
f'A duplicate of {original_name} has been made as <a href="{reverse("admin:NEMO_tool_change", args=[tool.id])}">{tool.name}</a>'
119-
),
120-
)
121-
except Exception as error:
122-
messages.error(
123-
request, f"{original_name} could not be duplicated because of the following error: {str(error)}"
124-
)
77+
for tool in queryset:
78+
original_name = tool.name
79+
new_name = "Copy of " + tool.name
80+
try:
81+
if Tool.objects.filter(name=new_name).exists():
82+
messages.error(
83+
request,
84+
mark_safe(
85+
f'There is already a copy of {original_name} as <a href="{reverse("admin:NEMO_tool_change", args=[tool.id])}">{new_name}</a>. Change the copy\'s name and try again'
86+
),
87+
)
88+
continue
89+
elif tool.is_child_tool():
90+
messages.warning(request, f"{original_name} is a child tool and cannot be duplicated")
91+
continue
92+
else:
93+
old_required_resources = tool.required_resource_set.all()
94+
old_nonrequired_resources = tool.nonrequired_resource_set.all()
95+
old_backup_users = tool.backup_owners.all()
96+
old_superusers = tool.superusers.all()
97+
old_reviewers = tool.adjustment_request_reviewers.all()
98+
old_qualified_users = User.objects.filter(qualifications__id=tool.pk).distinct()
99+
tool.pk = None
100+
tool.interlock = None
101+
tool.visible = False
102+
tool.operational = False
103+
tool.name = new_name
104+
tool.image = None
105+
tool.description = None
106+
tool.serial = None
107+
tool.save()
108+
tool.required_resource_set.set(old_required_resources)
109+
tool.nonrequired_resource_set.set(old_nonrequired_resources)
110+
tool.backup_owners.set(old_backup_users)
111+
tool.superusers.set(old_superusers)
112+
tool.adjustment_request_reviewers.set(old_reviewers)
113+
for user in old_qualified_users:
114+
user.qualifications.add(tool)
115+
messages.success(
116+
request,
117+
mark_safe(
118+
f'A duplicate of {original_name} has been made as <a href="{reverse("admin:NEMO_tool_change", args=[tool.id])}">{tool.name}</a>'
119+
),
120+
)
121+
except Exception as error:
122+
messages.error(
123+
request, f"{original_name} could not be duplicated because of the following error: {str(error)}"
124+
)
125125

126126

127127
@admin.action(description="Rebuild area tree")
128128
def rebuild_area_tree(model_admin, request, queryset):
129-
Area.objects.rebuild()
129+
Area.objects.rebuild()
130130

131131

132132
@admin.action(description="Export selected adjustment requests in CSV")
133133
def adjustment_requests_export_csv(modeladmin, request, queryset):
134-
return adjustments_csv_export(queryset.all())
134+
return adjustments_csv_export(queryset.all())
135135

136136

137137
@admin.action(description="Export selected access requests in CSV")
138138
def access_requests_export_csv(modeladmin, request, queryset):
139-
return access_csv_export(queryset.all())
139+
return access_csv_export(queryset.all())

0 commit comments

Comments
 (0)