Merge remote-tracking branch 'origin/main'

This commit is contained in:
John Mullins
2024-08-26 14:30:54 +10:00
6 changed files with 90 additions and 41 deletions
+7
View File
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os
from pathlib import Path
import platform
from dotenv import load_dotenv
@@ -45,6 +46,12 @@ INSTALLED_APPS = [
'rangefilter',
]
if platform.system() == "Linux":
INSTALLED_APPS.append('django_crontab')
CRONJOBS = [
('0 6 * * *', 'coord.scheduled_tasks.nightly_check_active_status')
]
TWILIO = {
"ACCOUNT_SID": os.environ.get('TWILIO_SID'),
"AUTH_TOKEN": os.environ.get('TWILIO_TOKEN'),
+9 -4
View File
@@ -12,7 +12,8 @@ from rangefilter.filters import DateRangeFilterBuilder
from .adminClone import CloneModelAdmin
from .context_helpers import *
from .email_helpers import email_companies_bus_roll, render_to_pdf, email_school_roll
from .email_helpers import email_companies_bus_roll, render_to_pdf, email_school_roll, \
email_companies_emergency_contacts
from .models import *
from .utils.send_sms import send_sms
@@ -25,10 +26,14 @@ class BusRollMixin:
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):
def email_bus_roll(self, request, queryset):
return email_companies_bus_roll(request, queryset)
email_company.short_description = "Email Bus Roll to Company"
def email_emergency_contacts(self, request, queryset):
return email_companies_emergency_contacts(request, queryset)
email_bus_roll.short_description = "Email Bus Roll to Company"
email_emergency_contacts.short_description = "Email Emergency Contacts to Company"
class ShuttleRollMixin:
@@ -132,7 +137,7 @@ class BusesAdmin(MyImportExportModelAdmin, admin.ModelAdmin, BusRollMixin):
list_filter = ["company"]
list_display = ["route_name", "company", "contract_number", "seating_capacity", "route_travellers"]
readonly_fields = ["traveller_count"]
actions = ["email_company", "show_bus_roll", "show_emergency_contacts"]
actions = ["show_bus_roll", "show_emergency_contacts", "email_bus_roll", "email_emergency_contacts"]
inlines = [DriverInline, BusStopInline]
fieldsets = [
(None, {'fields': [
+40 -5
View File
@@ -6,8 +6,15 @@ from django.http import HttpResponse
from django.template.loader import get_template
from xhtml2pdf import pisa
from coord.context_helpers import bus_roll_context, school_roll_context
from coord.models import Company, School
from .models import Company, School, Setting
from .context_helpers import bus_roll_context, emergency_contacts_context, school_roll_context
def _getBCC():
address = Setting.objects.filter(name="MAIL_BCC")
if address.exists():
return [address.first().value]
return []
def render_to_pdf(template, context):
@@ -40,7 +47,35 @@ def email_companies_bus_roll(request, query_set=None):
message = f"A new bus roll for {company.name} has been generated"
email_from = "bus.manager@education.vic.gov.au"
recipient = [company.contact_email]
email = EmailMessage(subject, message, email_from, recipient)
email = EmailMessage(subject, message, email_from, recipient, _getBCC())
email.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
email.send(fail_silently=True)
return render_to_pdf(html_template, context)
def email_companies_emergency_contacts(request, query_set=None):
html_template = 'reports/emergency_contacts.html'
context = emergency_contacts_context(query_set)
for company in Company.objects.all():
if not company.contact_email:
continue
company_route = []
for route in context.get("routes"):
if route.get("bus").company == company:
company_route.append(route)
if not company_route:
continue
company_context = {'routes': company_route}
pdf = render_to_pdf(html_template, company_context)
subject = "Echuca School Buses Emergency Contacts"
message = f"A new emergency contact list for {company.name} has been generated"
email_from = "bus.manager@education.vic.gov.au"
recipient = [company.contact_email]
email = EmailMessage(subject, message, email_from, recipient, _getBCC())
email.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
email.send(fail_silently=True)
@@ -67,8 +102,8 @@ def email_school_roll(request, query_set):
message = f"A new bus roll for {school.name} has been generated"
email_from = "bus.manager@education.vic.gov.au"
recipient = [school.email]
email = EmailMessage(subject, message, email_from, recipient)
email = EmailMessage(subject, message, email_from, recipient, _getBCC())
email.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
email.send(fail_silently=True)
return render_to_pdf(html_template, context)
return render_to_pdf(html_template, context)
@@ -43,38 +43,40 @@
<td>{{ stop.pm }}</td>
</tr>
</table>
<table class="traveller">
<tr>
<th style="width: 100%; text-align: left">Student</th>
<th style="width: 10%">Fare</th>
<th style="width: 8%">Mon AM</th>
<th style="width: 8%">Mon PM</th>
<th style="width: 8%">Tue AM</th>
<th style="width: 8%">Tue PM</th>
<th style="width: 8%">Wed AM</th>
<th style="width: 8%">Wed PM</th>
<th style="width: 8%">Thu AM</th>
<th style="width: 8%">Thu PM</th>
<th style="width: 8%">Fri AM</th>
<th style="width: 8%">Fri PM</th>
</tr>
{% for traveller in stop.travellers %}
{% if stop.travellers %}
<table class="traveller">
<tr>
<td style="padding-top: 3px; padding-left: 2px; text-align: left">{{ traveller.display }}</td>
<td style="padding-top: 3px; text-align: center"><b>{{ traveller.isFared }}</b></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<th style="width: 100%; text-align: left">Student</th>
<th style="width: 10%">Fare</th>
<th style="width: 8%">Mon AM</th>
<th style="width: 8%">Mon PM</th>
<th style="width: 8%">Tue AM</th>
<th style="width: 8%">Tue PM</th>
<th style="width: 8%">Wed AM</th>
<th style="width: 8%">Wed PM</th>
<th style="width: 8%">Thu AM</th>
<th style="width: 8%">Thu PM</th>
<th style="width: 8%">Fri AM</th>
<th style="width: 8%">Fri PM</th>
</tr>
{% endfor %}
</table>
{% for traveller in stop.travellers %}
<tr>
<td style="padding-top: 3px; padding-left: 2px; text-align: left">{{ traveller.display }}</td>
<td style="padding-top: 3px; text-align: center"><b>{{ traveller.isFared }}</b></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
{% endfor %}
</table>
{% endif %}
<br>
{% endfor %}
{% if route.route_stops %}
@@ -18,8 +18,8 @@
<th style="width: 5%">Fare</th>
<th style="width: 30%">Shuttle</th>
<th style="width: 30%">Stop</th>
<th style="width: 8%">AM Time</th>
<th style="width: 8%">PM Time</th>
<th style="width: 8%">Pickup</th>
<th style="width: 8%">Drop off</th>
</tr>
{% for traveller in route.travellers %}
<tr>
BIN
View File
Binary file not shown.