Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/4.2/ref/settings/
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import platform
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
@@ -45,6 +46,12 @@ INSTALLED_APPS = [
|
|||||||
'rangefilter',
|
'rangefilter',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
INSTALLED_APPS.append('django_crontab')
|
||||||
|
CRONJOBS = [
|
||||||
|
('0 6 * * *', 'coord.scheduled_tasks.nightly_check_active_status')
|
||||||
|
]
|
||||||
|
|
||||||
TWILIO = {
|
TWILIO = {
|
||||||
"ACCOUNT_SID": os.environ.get('TWILIO_SID'),
|
"ACCOUNT_SID": os.environ.get('TWILIO_SID'),
|
||||||
"AUTH_TOKEN": os.environ.get('TWILIO_TOKEN'),
|
"AUTH_TOKEN": os.environ.get('TWILIO_TOKEN'),
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from rangefilter.filters import DateRangeFilterBuilder
|
|||||||
|
|
||||||
from .adminClone import CloneModelAdmin
|
from .adminClone import CloneModelAdmin
|
||||||
from .context_helpers import *
|
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 .models import *
|
||||||
from .utils.send_sms import send_sms
|
from .utils.send_sms import send_sms
|
||||||
|
|
||||||
@@ -25,10 +26,14 @@ class BusRollMixin:
|
|||||||
def show_emergency_contacts(self, request, queryset):
|
def show_emergency_contacts(self, request, queryset):
|
||||||
return render_to_pdf('reports/emergency_contacts.html', emergency_contacts_context(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)
|
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:
|
class ShuttleRollMixin:
|
||||||
@@ -132,7 +137,7 @@ class BusesAdmin(MyImportExportModelAdmin, admin.ModelAdmin, BusRollMixin):
|
|||||||
list_filter = ["company"]
|
list_filter = ["company"]
|
||||||
list_display = ["route_name", "company", "contract_number", "seating_capacity", "route_travellers"]
|
list_display = ["route_name", "company", "contract_number", "seating_capacity", "route_travellers"]
|
||||||
readonly_fields = ["traveller_count"]
|
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]
|
inlines = [DriverInline, BusStopInline]
|
||||||
fieldsets = [
|
fieldsets = [
|
||||||
(None, {'fields': [
|
(None, {'fields': [
|
||||||
|
|||||||
@@ -6,8 +6,15 @@ from django.http import HttpResponse
|
|||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from xhtml2pdf import pisa
|
from xhtml2pdf import pisa
|
||||||
|
|
||||||
from coord.context_helpers import bus_roll_context, school_roll_context
|
from .models import Company, School, Setting
|
||||||
from coord.models import Company, School
|
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):
|
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"
|
message = f"A new bus roll for {company.name} has been generated"
|
||||||
email_from = "bus.manager@education.vic.gov.au"
|
email_from = "bus.manager@education.vic.gov.au"
|
||||||
recipient = [company.contact_email]
|
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.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
|
||||||
email.send(fail_silently=True)
|
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"
|
message = f"A new bus roll for {school.name} has been generated"
|
||||||
email_from = "bus.manager@education.vic.gov.au"
|
email_from = "bus.manager@education.vic.gov.au"
|
||||||
recipient = [school.email]
|
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.attach(f"school_bus_roll_{date.today()}.pdf", pdf.content)
|
||||||
email.send(fail_silently=True)
|
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>
|
<td>{{ stop.pm }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<table class="traveller">
|
{% if stop.travellers %}
|
||||||
<tr>
|
<table class="traveller">
|
||||||
<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 %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding-top: 3px; padding-left: 2px; text-align: left">{{ traveller.display }}</td>
|
<th style="width: 100%; text-align: left">Student</th>
|
||||||
<td style="padding-top: 3px; text-align: center"><b>{{ traveller.isFared }}</b></td>
|
<th style="width: 10%">Fare</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Mon AM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Mon PM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Tue AM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Tue PM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Wed AM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Wed PM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Thu AM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Thu PM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Fri AM</th>
|
||||||
<td> </td>
|
<th style="width: 8%">Fri PM</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% for traveller in stop.travellers %}
|
||||||
</table>
|
<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>
|
<br>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if route.route_stops %}
|
{% if route.route_stops %}
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
<th style="width: 5%">Fare</th>
|
<th style="width: 5%">Fare</th>
|
||||||
<th style="width: 30%">Shuttle</th>
|
<th style="width: 30%">Shuttle</th>
|
||||||
<th style="width: 30%">Stop</th>
|
<th style="width: 30%">Stop</th>
|
||||||
<th style="width: 8%">AM Time</th>
|
<th style="width: 8%">Pickup</th>
|
||||||
<th style="width: 8%">PM Time</th>
|
<th style="width: 8%">Drop off</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for traveller in route.travellers %}
|
{% for traveller in route.travellers %}
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user