Migration Copy Scripts
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
from django.contrib import messages
|
||||||
|
from django.views.generic import (TemplateView, ListView, DetailView, CreateView, UpdateView)
|
||||||
|
|
||||||
|
|
||||||
|
class BaseContextMixin:
|
||||||
|
title = "Bus Portal"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super().get_context_data(**kwargs)
|
||||||
|
user = self.request.user
|
||||||
|
|
||||||
|
context["theme"] = getattr(user, "theme", "theme-light")
|
||||||
|
|
||||||
|
nav_links = [
|
||||||
|
{"name": "Dashboard", "url": "/"},
|
||||||
|
{"name": "ORBAT", "url": "/orbat/"},
|
||||||
|
{"name": "Events", "url": "/events/"},
|
||||||
|
{"name": "Training", "url": "/training/"},
|
||||||
|
]
|
||||||
|
|
||||||
|
context["nav_links"] = nav_links
|
||||||
|
context.setdefault("breadcrumbs", [])
|
||||||
|
context["title"] = getattr(self, "title", "Bus Portal")
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
def add_message(self, message, level=messages.INFO):
|
||||||
|
"""
|
||||||
|
Helper to add a message prompt to the user.
|
||||||
|
Can be called from any view inheriting this base.
|
||||||
|
"""
|
||||||
|
messages.add_message(self.request, level, message)
|
||||||
|
|
||||||
|
class BaseTemplateView(BaseContextMixin, TemplateView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BaseListView(BaseContextMixin, ListView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BaseDetailView(BaseContextMixin, DetailView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BaseCreateView(BaseContextMixin, CreateView):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BaseUpdateView(BaseContextMixin, UpdateView):
|
||||||
|
pass
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import Bus as OldModel
|
||||||
|
from transport.models import Bus as NewModel
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldModel.objects.all():
|
||||||
|
obj, was_created = NewModel.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"company_id": old.company_id,
|
||||||
|
"route_name": old.route_name,
|
||||||
|
"contract_number": old.contract_number,
|
||||||
|
"registration": old.registration,
|
||||||
|
"seating_capacity": old.seating_capacity,
|
||||||
|
"make": old.make,
|
||||||
|
"model": old.model,
|
||||||
|
"notes": old.notes,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Buses — created: {created}, skipped: {skipped}")
|
||||||
|
print("Buses:", OldModel.objects.count(), NewModel.objects.count())
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import BusStop as OldModel
|
||||||
|
from transport.models import BusStop as NewModel
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldModel.objects.all():
|
||||||
|
obj, was_created = NewModel.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"bus_id": old.bus_id,
|
||||||
|
"am_time": old.am_time,
|
||||||
|
"pm_time": old.pm_time,
|
||||||
|
"address": old.address,
|
||||||
|
"notes": old.notes,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"BusStops — created: {created}, skipped: {skipped}")
|
||||||
|
print("BusStops:", OldModel.objects.count(), NewModel.objects.count())
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import Company as OldModel
|
||||||
|
from transport.models import Company as NewModel
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldModel.objects.all():
|
||||||
|
obj, was_created = NewModel.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"name": old.name,
|
||||||
|
"contact_name": old.contact_name,
|
||||||
|
"contact_number": old.contact_number,
|
||||||
|
"contact_mobile": old.contact_mobile,
|
||||||
|
"contact_email": old.contact_email,
|
||||||
|
"address": old.address,
|
||||||
|
"suburb_id": old.suburb_id,
|
||||||
|
"notes": old.notes,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Companies — created: {created}, skipped: {skipped}")
|
||||||
|
print("Companies:", OldModel.objects.count(), NewModel.objects.count())
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import Driver as OldModel
|
||||||
|
from transport.models import Driver as NewModel
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldModel.objects.all():
|
||||||
|
obj, was_created = NewModel.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"bus_id": old.bus_id,
|
||||||
|
"first_name": old.first_name,
|
||||||
|
"last_name": old.last_name,
|
||||||
|
"phone_number": old.phone_number,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Drivers — created: {created}, skipped: {skipped}")
|
||||||
|
print("Drivers:", OldModel.objects.count(), NewModel.objects.count())
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import Family as OldFamily
|
||||||
|
from traveller.models import Family as NewFamily
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldFamily.objects.all():
|
||||||
|
obj, was_created = NewFamily.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"traveller_id": old.traveller_id,
|
||||||
|
"residential_address": old.residential_address,
|
||||||
|
"residential_suburb_id": old.residential_suburb_id,
|
||||||
|
"postal_address": old.postal_address,
|
||||||
|
"postal_suburb_id": old.postal_suburb_id,
|
||||||
|
"parent_A_firstname": old.parent_A_firstname,
|
||||||
|
"parent_A_lastname": old.parent_A_lastname,
|
||||||
|
"parent_A_phone": old.parent_A_phone,
|
||||||
|
"parent_A_email": old.parent_A_email,
|
||||||
|
"parent_B_firstname": old.parent_B_firstname,
|
||||||
|
"parent_B_lastname": old.parent_B_lastname,
|
||||||
|
"parent_B_phone": old.parent_B_phone,
|
||||||
|
"parent_B_email": old.parent_B_email,
|
||||||
|
"emergency_contact_A_firstname": old.emergency_contact_A_firstname,
|
||||||
|
"emergency_contact_A_lastname": old.emergency_contact_A_lastname,
|
||||||
|
"emergency_contact_A_phone": old.emergency_contact_A_phone,
|
||||||
|
"emergency_contact_A_relation": old.emergency_contact_A_relation,
|
||||||
|
"emergency_contact_B_firstname": old.emergency_contact_B_firstname,
|
||||||
|
"emergency_contact_B_lastname": old.emergency_contact_B_lastname,
|
||||||
|
"emergency_contact_B_phone": old.emergency_contact_B_phone,
|
||||||
|
"emergency_contact_B_relation": old.emergency_contact_B_relation,
|
||||||
|
"created_on": old.created_on,
|
||||||
|
"last_edit": old.last_edit,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Families — created: {created}, skipped: {skipped}")
|
||||||
|
print("Families:", OldFamily.objects.count(), NewFamily.objects.count())
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import School as OldSchool
|
||||||
|
from traveller.models import School as NewSchool
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldSchool.objects.all():
|
||||||
|
obj, was_created = NewSchool.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"name": old.name,
|
||||||
|
"shortName": old.shortName,
|
||||||
|
"address": old.address,
|
||||||
|
"suburb_id": old.suburb_id,
|
||||||
|
"email": old.email,
|
||||||
|
"phone": old.phone,
|
||||||
|
"principal_name": old.principal_name,
|
||||||
|
"principal_phone": old.principal_phone,
|
||||||
|
"notes": old.notes,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Schools — created: {created}, skipped: {skipped}")
|
||||||
|
print("Schools:", OldSchool.objects.count(), NewSchool.objects.count())
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import Shuttle as OldModel
|
||||||
|
from transport.models import Shuttle as NewModel
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldModel.objects.all():
|
||||||
|
obj, was_created = NewModel.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"bus_id": old.bus_id,
|
||||||
|
"school_id": old.school_id,
|
||||||
|
"custom_name": old.custom_name,
|
||||||
|
"am_service": old.am_service,
|
||||||
|
"pm_service": old.pm_service,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Shuttles — created: {created}, skipped: {skipped}")
|
||||||
|
print("Shuttles:", OldModel.objects.count(), NewModel.objects.count())
|
||||||
@@ -1,24 +1,26 @@
|
|||||||
import os
|
from setup_django import *
|
||||||
import sys
|
|
||||||
|
|
||||||
import django
|
|
||||||
|
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
||||||
|
|
||||||
# Setup Django environment
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "busManager.settings")
|
|
||||||
django.setup()
|
|
||||||
|
|
||||||
from coord.models import Suburb as OldSuburb
|
from coord.models import Suburb as OldSuburb
|
||||||
from common.models import Suburb as NewSuburb
|
from common.models import Suburb as NewSuburb
|
||||||
|
|
||||||
|
created = 0
|
||||||
|
skipped = 0
|
||||||
|
|
||||||
for old in OldSuburb.objects.all():
|
for old in OldSuburb.objects.all():
|
||||||
NewSuburb.objects.create(
|
|
||||||
id=old.id, # preserve PK
|
obj, was_created = NewSuburb.objects.get_or_create(
|
||||||
name=old.name,
|
id=old.id,
|
||||||
state=old.state,
|
defaults={
|
||||||
postcode=old.postcode,
|
"name": old.name,
|
||||||
distance=old.distance
|
"state": old.state,
|
||||||
|
"postcode": old.postcode,
|
||||||
|
"distance": old.distance,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f"Copied {OldSuburb.objects.count()} suburbs to common_suburb")
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Created: {created}, Skipped: {skipped}")
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import TravellerRoute as OldRoute
|
||||||
|
from traveller.models import TravellerRoute as NewRoute
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldRoute.objects.all():
|
||||||
|
obj, was_created = NewRoute.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"traveller_id": old.traveller_id,
|
||||||
|
"busStop_id": old.busStop_id,
|
||||||
|
"travel_start_date": old.travel_start_date,
|
||||||
|
"travel_end_date": old.travel_end_date,
|
||||||
|
"mon_am": old.mon_am,
|
||||||
|
"mon_pm": old.mon_pm,
|
||||||
|
"tue_am": old.tue_am,
|
||||||
|
"tue_pm": old.tue_pm,
|
||||||
|
"wen_am": old.wen_am,
|
||||||
|
"wen_pm": old.wen_pm,
|
||||||
|
"thu_am": old.thu_am,
|
||||||
|
"thu_pm": old.thu_pm,
|
||||||
|
"fri_am": old.fri_am,
|
||||||
|
"fri_pm": old.fri_pm,
|
||||||
|
"notes": old.notes,
|
||||||
|
"created_on": old.created_on,
|
||||||
|
"last_edit": old.last_edit,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"TravellerRoutes — created: {created}, skipped: {skipped}")
|
||||||
|
print("Routes:", OldRoute.objects.count(), NewRoute.objects.count())
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
from setup_django import *
|
||||||
|
|
||||||
|
from coord.models import Traveller as OldTraveller
|
||||||
|
from traveller.models import Traveller as NewTraveller
|
||||||
|
|
||||||
|
created = skipped = 0
|
||||||
|
|
||||||
|
for old in OldTraveller.objects.all():
|
||||||
|
obj, was_created = NewTraveller.objects.get_or_create(
|
||||||
|
id=old.id,
|
||||||
|
defaults={
|
||||||
|
"school_id": old.school_id,
|
||||||
|
"first_name": old.first_name,
|
||||||
|
"last_name": old.last_name,
|
||||||
|
"dob": old.dob,
|
||||||
|
"year_level": old.year_level,
|
||||||
|
"distance_to_school": old.distance_to_school,
|
||||||
|
"address": old.address,
|
||||||
|
"travel_start_date": old.travel_start_date,
|
||||||
|
"travel_end_date": old.travel_end_date,
|
||||||
|
"eligibility_status": old.eligibility_status,
|
||||||
|
"assessment_date": old.assessment_date,
|
||||||
|
"fee_per_term": old.fee_per_term,
|
||||||
|
"term_1_paid": old.term_1_paid,
|
||||||
|
"term_2_paid": old.term_2_paid,
|
||||||
|
"term_3_paid": old.term_3_paid,
|
||||||
|
"term_4_paid": old.term_4_paid,
|
||||||
|
"application_form_completed": old.application_form_completed,
|
||||||
|
"parent_notified": old.parent_notified,
|
||||||
|
"seat_number": old.seat_number,
|
||||||
|
"is_archived": old.is_archived,
|
||||||
|
"is_active": old.is_active,
|
||||||
|
"notes": old.notes,
|
||||||
|
"shuttle_id": old.shuttle_id,
|
||||||
|
"created_on": old.created_on,
|
||||||
|
"last_edit": old.last_edit,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if was_created:
|
||||||
|
created += 1
|
||||||
|
else:
|
||||||
|
skipped += 1
|
||||||
|
|
||||||
|
print(f"Travellers — created: {created}, skipped: {skipped}")
|
||||||
|
print("Travellers:", OldTraveller.objects.count(), NewTraveller.objects.count())
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import django
|
||||||
|
|
||||||
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.append(BASE_DIR)
|
||||||
|
|
||||||
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "busManager.settings")
|
||||||
|
django.setup()
|
||||||
Reference in New Issue
Block a user