mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-25 16:51:54 +00:00
Make robust against duplicate objects
This commit is contained in:
parent
3c78ab79ca
commit
7d4ca5dae2
@ -311,11 +311,22 @@ class Entrance(TroggleModel):
|
||||
def __str__(self):
|
||||
return str(self.slug)
|
||||
|
||||
def single(self, station):
|
||||
try:
|
||||
single = SurvexStation.objects.get(name = station)
|
||||
return single
|
||||
except:
|
||||
stations = SurvexStation.objects.filter(name = station)
|
||||
print(f" # MULTIPLE stations found with same name '{station}' in Entrance {self}:")
|
||||
for s in stations:
|
||||
print(f" # {s.id=} - {s.name} {s.latlong()}") # .id is Django internal field, not one of ours
|
||||
return stations[0]
|
||||
|
||||
def exact_location(self):
|
||||
return SurvexStation.objects.get(name = self.exact_station)
|
||||
return self.single(self.exact_station)
|
||||
|
||||
def other_location(self):
|
||||
return SurvexStation.objects.get(name = self.other_station)
|
||||
return self.single(self.other_station)
|
||||
|
||||
def find_location(self):
|
||||
r = {"": "To be entered ", "?": "To be confirmed:", "S": "", "L": "Lost:", "R": "Refindable:"}[self.findability]
|
||||
@ -376,7 +387,7 @@ class Entrance(TroggleModel):
|
||||
return f[1]
|
||||
|
||||
def tag(self):
|
||||
return SurvexStation.objects.get(name = self.tag_station)
|
||||
return self.single(self.tag_station)
|
||||
|
||||
def needs_surface_work(self):
|
||||
return self.findability != "S" or not self.has_photo or self.marking != "T"
|
||||
|
Loading…
Reference in New Issue
Block a user