Added fields to changelist view. Added hyperlinks and mailto links
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import csv
|
||||
|
||||
from django.contrib.admin import DateFieldListFilter
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.forms import widgets
|
||||
from django.contrib import admin
|
||||
from django.http import HttpResponse
|
||||
@@ -10,7 +11,7 @@ from django.utils.http import urlencode
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
|
||||
from .adminClone import CloneModelAdmin
|
||||
from .context_helpers import bus_roll_context
|
||||
from .context_helpers import bus_roll_context, emergency_contacts_context
|
||||
from .email_helpers import email_companies_bus_roll, render_to_pdf
|
||||
from .models import *
|
||||
|
||||
@@ -38,6 +39,9 @@ class BusRollMixin:
|
||||
def show_bus_roll(self, request, queryset):
|
||||
return render_to_pdf('reports/bus_roll.html', bus_roll_context(queryset))
|
||||
|
||||
def show_emergency_contacts(self, request, queryset):
|
||||
return render_to_pdf('reports/emergency_contacts.html', emergency_contacts_context(queryset))
|
||||
|
||||
def email_company(self, request, queryset):
|
||||
return email_companies_bus_roll(request, queryset)
|
||||
|
||||
@@ -55,7 +59,7 @@ class MyImportExportModelAdmin(ImportExportModelAdmin):
|
||||
|
||||
@admin.register(Company)
|
||||
class CompanyAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
list_display = ["name", "buses"]
|
||||
list_display = ["name", "contact_name", "email", "buses"]
|
||||
|
||||
def buses(self, obj):
|
||||
count = obj.bus_set.count()
|
||||
@@ -66,6 +70,9 @@ class CompanyAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
)
|
||||
return format_html('<a href="{}">{} Buses</a>', url, count)
|
||||
|
||||
def email(self, obj):
|
||||
return format_html('<a href="mailto:{}">{}</a>', obj.contact_email, obj.contact_email)
|
||||
|
||||
|
||||
class DriverInline(admin.StackedInline):
|
||||
model = Driver
|
||||
@@ -83,7 +90,7 @@ class BusesAdmin(MyImportExportModelAdmin, admin.ModelAdmin, BusRollMixin):
|
||||
list_filter = ["company"]
|
||||
list_display = ["route_name", "company", "contract_number", "route_travellers"]
|
||||
readonly_fields = ["traveller_count"]
|
||||
actions = ["email_company", "show_bus_roll"]
|
||||
actions = ["email_company", "show_bus_roll", "show_emergency_contacts"]
|
||||
inlines = [DriverInline, BusStopInline]
|
||||
fieldsets = [
|
||||
(None, {'fields': [
|
||||
@@ -222,7 +229,10 @@ class TravellerRouteAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
|
||||
@admin.register(School)
|
||||
class SchoolAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
pass
|
||||
list_display = ["__str__", "address", "suburb", "school_email", "phone"]
|
||||
|
||||
def school_email(self, obj):
|
||||
return format_html('<a href="mailto:{}">{}</a>', obj.email, obj.email)
|
||||
|
||||
|
||||
@admin.register(Setting)
|
||||
@@ -245,4 +255,8 @@ class ShuttleAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
|
||||
@admin.register(Driver)
|
||||
class DriverAdmin(MyImportExportModelAdmin, admin.ModelAdmin):
|
||||
pass
|
||||
list_display = ["__str__", "route", "phone_number"]
|
||||
|
||||
def route(self, obj):
|
||||
url = reverse("admin:coord_bus_change", args=(obj.bus.id,))
|
||||
return format_html('<a href="{}">{}</a>', url, obj.bus)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
<style>
|
||||
@page {
|
||||
size: letter landscape;
|
||||
margin: 0.5cm;
|
||||
}
|
||||
|
||||
table.stopHeader th {
|
||||
text-align: left;
|
||||
@@ -11,32 +15,29 @@
|
||||
|
||||
|
||||
table.traveller td {
|
||||
table-layout: fixed;
|
||||
border-bottom: 2px solid #000;
|
||||
border-right-style: dashed;
|
||||
padding-top: 3px;
|
||||
border: 1px solid #000;
|
||||
}
|
||||
|
||||
|
||||
hr {
|
||||
border: 2px solid;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% for route in routes %}
|
||||
<h1>{{ route.bus }}</h1>
|
||||
<hr>
|
||||
<h1 style="font-size: 2.5em">{{ route.bus.company }} - {{ route.bus }}</h1>
|
||||
{% for driver in route.drivers %}
|
||||
<p><b>Driver:</b> {{ driver }} ({{ driver.phone_number }})</p>
|
||||
{% endfor %}
|
||||
<table class="traveller">
|
||||
<tr>
|
||||
<th>Student</th>
|
||||
<th>Parent A</th>
|
||||
<th>Parent B</th>
|
||||
<th>Emergency Contact A</th>
|
||||
<th>Emergency Contact B</th>
|
||||
<th>Driver notes</th>
|
||||
<th style="width: 25%">Student</th>
|
||||
<th style="width: 25%">Parent A</th>
|
||||
<th style="width: 25%">Parent B</th>
|
||||
<th style="width: 25%">Emergency Contact A</th>
|
||||
<th style="width: 25%">Emergency Contact B</th>
|
||||
<th style="width: 40%">Driver notes</th>
|
||||
</tr>
|
||||
{% for traveller in route.travellers %}
|
||||
<tr>
|
||||
<td>{{ traveller.traveller }} ({{ traveller.traveller.school.shortName }})</td>
|
||||
<td>{{ traveller.traveller.last_name }}, {{ traveller.traveller.first_name }} ({{ traveller.traveller.school.shortName }})</td>
|
||||
<td>{{ traveller.parent_a }}</td>
|
||||
<td>{{ traveller.parent_b }}</td>
|
||||
<td>{{ traveller.contact_a }}</td>
|
||||
|
||||
Reference in New Issue
Block a user