Skip to content

Commit

Permalink
Some hateful code to deal with a hateful problem
Browse files Browse the repository at this point in the history
  • Loading branch information
jellybob committed May 25, 2024
1 parent 13f5191 commit fcfe28b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions apps/volunteer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,36 @@ def init_workshop_shifts():
# late to do anything about that right now.
role = Role.query.filter_by(name="Workshop Steward").first()

venues = {}
with db.session.no_autoflush:
for proposal in proposals:
# Because VolunteerVenues are complete distinct from Venues, despite being the same physical location.
#
# Also you can end up with multiple new venues with the same name all trying to insert at once and then
# breaking unless you keep track of which ones you already inserted. This all sucks.
if proposal.scheduled_venue.name in venues:
venue = venues[proposal.scheduled_venue.name]
else:
venue = VolunteerVenue.query.filter_by(name=proposal.scheduled_venue.name).first()
if venue is None:
location = to_shape(proposal.scheduled_venue.location)
mapref = f"https://map.emfcamp.org/#20.82/{location.y}/{location.x}"
venue = VolunteerVenue(name=proposal.scheduled_venue.name, mapref=mapref)
db.session.add(venue)
venues[proposal.scheduled_venue.name] = venue

shift = Shift.query.filter_by(proposal=proposal, role=role).first()
if shift is None:
shift = Shift(proposal=proposal, role=role)

# Because VolunteerVenues are complete distinct from Venues, despite being the same physical location.
venue = VolunteerVenue.query.filter_by(name=proposal.scheduled_venue.name).first()
if venue is None:
location = to_shape(proposal.scheduled_venue.location)
mapref = f"https://map.emfcamp.org/#20.82/{location.y}/{location.x}"
venue = VolunteerVenue(name=proposal.scheduled_venue.name, mapref=mapref)
shift = Shift(proposal=proposal, role=role, venue=venue)

shift.start = proposal.scheduled_time - time_before_start
shift.end = proposal.scheduled_time + time_after_start
shift.venue = venue
shift.min_needed = 1
shift.max_needed = 1
db.session.add(shift)

db.session.commit()

db.session.commit()
return redirect(url_for(".schedule"))

Expand Down

0 comments on commit fcfe28b

Please sign in to comment.