2022-02-14 11:05:35 -05:00
|
|
|
from django.core import mail
|
|
|
|
from django.contrib import admin, messages
|
|
|
|
from django.db.models.functions import Now
|
2021-03-23 17:08:00 -04:00
|
|
|
|
2022-02-11 13:48:47 -05:00
|
|
|
from .models import (
|
|
|
|
CmsRedRiverVeteransScholarship,
|
|
|
|
CertificationDefinition,
|
|
|
|
Certification,
|
|
|
|
CertificationVersion,
|
|
|
|
InstructorOrVendor,
|
|
|
|
SpecialProgram,
|
|
|
|
Waiver,
|
|
|
|
)
|
2022-02-14 11:05:35 -05:00
|
|
|
from .certification_emails import all_certification_emails
|
2021-03-23 17:08:00 -04:00
|
|
|
|
|
|
|
|
2022-02-04 16:30:52 -05:00
|
|
|
class CertificationVersionInline(admin.TabularInline):
|
|
|
|
model = CertificationVersion
|
|
|
|
extra = 1
|
|
|
|
|
|
|
|
|
2022-02-03 13:45:58 -05:00
|
|
|
@admin.register(CertificationDefinition)
|
2021-03-23 17:08:00 -04:00
|
|
|
class CertificationDefinitionAdmin(admin.ModelAdmin):
|
2022-02-11 13:48:47 -05:00
|
|
|
search_fields = ["certification_name"]
|
|
|
|
list_display = ["certification_name", "department"]
|
|
|
|
list_filter = ["department"]
|
2022-02-04 16:30:52 -05:00
|
|
|
inlines = [CertificationVersionInline]
|
2021-03-23 17:08:00 -04:00
|
|
|
|
|
|
|
|
2022-02-03 13:45:58 -05:00
|
|
|
@admin.register(Certification)
|
2021-03-23 17:08:00 -04:00
|
|
|
class CertificationAdmin(admin.ModelAdmin):
|
2022-02-11 13:48:47 -05:00
|
|
|
search_fields = [
|
|
|
|
"name",
|
2022-02-24 18:41:53 -05:00
|
|
|
"certification_version__definition__certification_name",
|
|
|
|
"certification_version__definition__department",
|
2022-02-11 13:48:47 -05:00
|
|
|
]
|
|
|
|
autocomplete_fields = ["member"]
|
|
|
|
exclude = ["shop_lead_notified"]
|
2022-02-05 00:28:58 -05:00
|
|
|
|
2022-02-11 13:48:47 -05:00
|
|
|
@admin.display(
|
|
|
|
description="Certification Name",
|
|
|
|
ordering="certification_version__definition__certification_name",
|
|
|
|
)
|
2022-02-05 00:28:58 -05:00
|
|
|
def certification_name(self, obj):
|
|
|
|
return obj.certification_version.definition.certification_name
|
|
|
|
|
2022-02-11 13:48:47 -05:00
|
|
|
@admin.display(
|
|
|
|
description="Certification Version", ordering="certification_version__version"
|
|
|
|
)
|
2022-02-05 00:28:58 -05:00
|
|
|
def certification_version_version(self, obj):
|
|
|
|
return obj.certification_version.version
|
|
|
|
|
2022-02-11 13:48:47 -05:00
|
|
|
@admin.display(
|
|
|
|
description="Department",
|
|
|
|
ordering="certification_version__definition__department",
|
|
|
|
)
|
2022-02-05 00:28:58 -05:00
|
|
|
def certification_department(self, obj):
|
|
|
|
return obj.certification_version.definition.department
|
|
|
|
|
|
|
|
list_display = [
|
2022-02-11 13:48:47 -05:00
|
|
|
"certification_name",
|
|
|
|
"name",
|
|
|
|
"certification_version_version",
|
|
|
|
"certification_department",
|
|
|
|
"date",
|
|
|
|
"shop_lead_notified",
|
|
|
|
"certified_by",
|
2022-02-05 00:28:58 -05:00
|
|
|
]
|
|
|
|
list_display_links = [
|
2022-02-11 13:48:47 -05:00
|
|
|
"certification_name",
|
|
|
|
"name",
|
2022-02-05 00:28:58 -05:00
|
|
|
]
|
|
|
|
list_filter = [
|
2022-02-11 13:48:47 -05:00
|
|
|
"certification_version__definition__department",
|
|
|
|
("shop_lead_notified", admin.EmptyFieldListFilter),
|
2022-02-05 00:28:58 -05:00
|
|
|
]
|
2021-03-23 17:08:00 -04:00
|
|
|
|
2022-02-14 11:05:35 -05:00
|
|
|
actions = ["send_notifications"]
|
|
|
|
|
|
|
|
@admin.action(
|
|
|
|
description="Notify Shop Leads and Members of selected certifications"
|
|
|
|
)
|
|
|
|
def send_notifications(self, request, queryset):
|
|
|
|
try:
|
|
|
|
emails = list(all_certification_emails(queryset))
|
|
|
|
|
|
|
|
with mail.get_connection() as conn:
|
|
|
|
conn.send_messages(emails)
|
|
|
|
|
|
|
|
for cert in queryset:
|
2022-02-24 21:59:16 -05:00
|
|
|
cert.shop_lead_notified = Now()
|
|
|
|
cert.save()
|
2022-02-14 11:05:35 -05:00
|
|
|
|
|
|
|
self.message_user(
|
|
|
|
request,
|
|
|
|
f"{len(emails)} notifications sent for {len(queryset)} certifications",
|
|
|
|
messages.SUCCESS,
|
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
self.message_user(
|
|
|
|
request,
|
|
|
|
f"Failed to send notifications! {e}",
|
|
|
|
messages.ERROR,
|
|
|
|
)
|
|
|
|
raise
|
|
|
|
|
2021-03-23 17:08:00 -04:00
|
|
|
|
2022-02-03 13:45:58 -05:00
|
|
|
@admin.register(InstructorOrVendor)
|
2021-03-23 17:08:00 -04:00
|
|
|
class InstructorOrVendorAdmin(admin.ModelAdmin):
|
2022-02-11 13:48:47 -05:00
|
|
|
search_fields = ["name"]
|
2022-07-21 18:49:24 -04:00
|
|
|
list_display = [
|
|
|
|
"name",
|
|
|
|
"instructor_agreement_date",
|
|
|
|
"w9_date",
|
|
|
|
"phone",
|
|
|
|
"email_address",
|
|
|
|
]
|
2021-03-23 17:08:00 -04:00
|
|
|
|
|
|
|
|
2022-02-03 13:45:58 -05:00
|
|
|
@admin.register(SpecialProgram)
|
2021-03-23 17:08:00 -04:00
|
|
|
class SpecialProgramAdmin(admin.ModelAdmin):
|
2022-02-11 13:48:47 -05:00
|
|
|
search_fields = ["program_name"]
|
2022-07-21 18:49:24 -04:00
|
|
|
list_display = [
|
|
|
|
"program_name",
|
|
|
|
"discount_percent",
|
|
|
|
"discount_code",
|
|
|
|
"membership_code",
|
|
|
|
"start_date",
|
|
|
|
"end_date",
|
|
|
|
"program_amount",
|
|
|
|
"program_status",
|
|
|
|
]
|
2021-03-23 17:08:00 -04:00
|
|
|
|
|
|
|
|
2022-02-03 13:45:58 -05:00
|
|
|
@admin.register(Waiver)
|
2021-03-23 17:08:00 -04:00
|
|
|
class WaiverAdmin(admin.ModelAdmin):
|
2022-02-11 13:48:47 -05:00
|
|
|
search_fields = ["name"]
|
2021-03-23 17:08:00 -04:00
|
|
|
|
2022-07-21 18:49:24 -04:00
|
|
|
list_display = [
|
|
|
|
"name",
|
|
|
|
"date",
|
|
|
|
"emergency_contact_name",
|
|
|
|
"emergency_contact_number",
|
|
|
|
"waiver_version",
|
|
|
|
"guardian_name",
|
|
|
|
"guardian_relation",
|
|
|
|
"guardian_date",
|
|
|
|
]
|
|
|
|
|
2021-03-23 17:08:00 -04:00
|
|
|
|
|
|
|
admin.site.register(CmsRedRiverVeteransScholarship)
|