diff --git a/apps/villages/admin.py b/apps/villages/admin.py index 728c57c73..18ff38722 100644 --- a/apps/villages/admin.py +++ b/apps/villages/admin.py @@ -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() diff --git a/apps/villages/views.py b/apps/villages/views.py index 975dac64f..80270a37a 100644 --- a/apps/villages/views.py +++ b/apps/villages/views.py @@ -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()