Skip to content

Commit

Permalink
When a village is renamed, rename the corresponding venue; check name…
Browse files Browse the repository at this point in the history
… clashes.
  • Loading branch information
lukegb committed Jun 1, 2024
1 parent 48bb1af commit ffcbc5f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/villages/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def admin_village(village_id):
form = AdminVillageForm()

if form.validate_on_submit():
for venue in village.venues:
if venue.name == village.name:
# Rename a village venue if it exists and has the old name.
venue.name = form.name.data

form.populate_obj(village)
db.session.add(village)
db.session.commit()
Expand Down
10 changes: 10 additions & 0 deletions apps/villages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def edit(year, village_id):

form = VillageForm()
if form.validate_on_submit():
if Village.get_by_name(form.name.data):
# FIXME: this should be a WTForms validation
flash("A village already exists with that name, please choose another")
return redirect(url_for(".register"))

for venue in village.venues:
if venue.name == village.name:
# Rename a village venue if it exists and has the old name.
venue.name = form.name.data

form.populate_obj(village)
form.populate_obj(village.requirements)
db.session.commit()
Expand Down

0 comments on commit ffcbc5f

Please sign in to comment.