Skip to content

Commit

Permalink
If plan has single organisation, set timetable org to that org. However
Browse files Browse the repository at this point in the history
form allows user over ride.

If joint plan then don't default plan select option, up to user to
choose.
  • Loading branch information
ashimali committed Dec 17, 2024
1 parent 2af3e73 commit b9eb9b6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion application/blueprints/timetable/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

from application.blueprints.timetable.forms import EventForm
from application.extensions import db
from application.models import LocalPlan, LocalPlanEventType, LocalPlanTimetable
from application.models import (
LocalPlan,
LocalPlanEventType,
LocalPlanTimetable,
Organisation,
)
from application.utils import login_required

timetable = Blueprint(
Expand All @@ -31,6 +36,14 @@ def add(local_plan_reference):
action_text = "Add"

form = EventForm()
if plan.organisations:
form.organisation.choices = [
(organisation.organisation, organisation.name)
for organisation in Organisation.query.order_by(Organisation.name).all()
]
if plan.organisations and not form.is_submitted():
if len(plan.organisations) == 1:
form.organisation.data = plan.organisations[0].organisation

breadcrumbs = {
"items": [
Expand Down Expand Up @@ -71,6 +84,8 @@ def add(local_plan_reference):
notes=form.notes.data,
)
plan.timetable.append(local_plan_timetable)
if form.organisation.data:
local_plan_timetable.organisation = form.organisation.data
db.session.add(plan)
db.session.add(local_plan_timetable)
db.session.commit()
Expand Down

0 comments on commit b9eb9b6

Please sign in to comment.