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() diff --git a/models/cfp.py b/models/cfp.py index fd1644232..abd92ec15 100644 --- a/models/cfp.py +++ b/models/cfp.py @@ -799,22 +799,11 @@ def slug(self): @property def latlon(self): - if self.scheduled_venue and self.scheduled_venue.location: - loc = to_shape(self.scheduled_venue.location) - return (loc.y, loc.x) - return None + return self.scheduled_venue.latlon if self.scheduled_venue else None @property def map_link(self) -> Optional[str]: - latlon = self.latlon - if latlon: - return "https://map.emfcamp.org/#18.5/%s/%s/m=%s,%s" % ( - latlon[0], - latlon[1], - latlon[0], - latlon[1], - ) - return None + return self.scheduled_venue.map_link if self.scheduled_venue else None @property def display_title(self) -> str: @@ -1183,6 +1172,27 @@ def emf_venue_names_by_type(cls): def get_by_name(cls, name): return cls.query.filter_by(name=name).one() + @property + def latlon(self): + if self.location: + loc = to_shape(self.location) + return (loc.y, loc.x) + if self.village and self.village.latlon: + return self.village.latlon + return None + + @property + def map_link(self) -> Optional[str]: + latlon = self.latlon + if latlon: + return "https://map.emfcamp.org/#18.5/%s/%s/m=%s,%s" % ( + latlon[0], + latlon[1], + latlon[0], + latlon[1], + ) + return None + # TODO: change the relationships on User and Proposal to 1-to-1 db.Index(