diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/forms.py | 20 | ||||
-rw-r--r-- | core/models/caves.py | 36 | ||||
-rw-r--r-- | core/views/caves.py | 6 | ||||
-rw-r--r-- | core/views/survex.py | 22 |
4 files changed, 30 insertions, 54 deletions
diff --git a/core/forms.py b/core/forms.py index d1156cb..3127bb1 100644 --- a/core/forms.py +++ b/core/forms.py @@ -25,7 +25,7 @@ todo = """ class CaveForm(ModelForm): """Only those fields for which we want to override defaults are listed here - the other fields are present on the form, but use the default presentation style + the other fields of the class Cave are present on the form, but use the default presentation style """ official_name = forms.CharField(required=False, widget=forms.TextInput(attrs={"size": "45"})) @@ -74,19 +74,11 @@ class CaveForm(ModelForm): model = Cave exclude = ("filename",) - field_order = ['area', 'unofficial_number', 'kataster_number', 'official_name', 'underground_description', 'explorers', 'equipment', 'survey', 'kataster_status', 'underground_centre_line', 'notes', 'references', 'description_file', 'survex_file', 'url', 'length', 'depth', 'extent'] - - def get_area(self): - for a in self.cleaned_data["area"]: - if a.kat_area(): - return a.kat_area() - + field_order = ['unofficial_number', 'kataster_number', 'official_name', 'underground_description', 'explorers', 'equipment', 'survey', 'kataster_status', 'kataster_code','underground_centre_line', 'notes', 'references', 'description_file', 'survex_file', 'areacode', 'url', 'length', 'depth', 'extent'] + def clean_cave_slug(self): if self.cleaned_data["cave_slug"] == "": - myArea = "" - for a in self.cleaned_data["area"]: - if a.kat_area(): - myArea = a.kat_area() + myArea = self.cleaned_data["areacode"] if self.data["kataster_number"]: cave_slug = f"{myArea}-{self.cleaned_data['kataster_number']}" else: @@ -112,8 +104,8 @@ class CaveForm(ModelForm): ) # if self.cleaned_data.get("kataster_number") != "" and self.cleaned_data.get("official_name") == "": # self._errors["official_name"] = self.error_class(["This field is required when there is a kataster number."]) - if cleaned_data.get("area") == []: - self._errors["area"] = self.error_class(["This field is required."]) + if cleaned_data.get("url") == []: + self._errors["url"] = self.error_class(["This field is required."]) if cleaned_data.get("url") and cleaned_data.get("url").startswith("/"): self._errors["url"] = self.error_class(["This field cannot start with a /."]) return cleaned_data diff --git a/core/models/caves.py b/core/models/caves.py index 0ede2b1..ea6fe9a 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -65,7 +65,7 @@ class CaveAndEntrance(models.Model): class Cave(TroggleModel): # too much here perhaps, areacode = models.CharField(max_length=4, blank=True, null=True) # could use models.IntegerChoices - subarea = models.CharField(max_length=10, blank=True, null=True) # 9, 8c etc. + subarea = models.CharField(max_length=25, blank=True, null=True) # 9, 8c etc. depth = models.CharField(max_length=100, blank=True, null=True) description_file = models.CharField(max_length=200, blank=True, null=True) entrances = models.ManyToManyField("Entrance", through="CaveAndEntrance") @@ -89,34 +89,12 @@ class Cave(TroggleModel): # class Meta: # unique_together = (("area", "kataster_number"), ("area", "unofficial_number")) - # FIXME Kataster Areas and CUCC defined sub areas need seperating # href = models.CharField(max_length=100) class Meta: ordering = ("kataster_code", "unofficial_number") - def hassurvey(self): - """This is almost certainly a fossil - needs checking... - """ - if not self.underground_centre_line: - return "No" - if ( - self.survey.find("<img") > -1 - or self.survey.find("<a") > -1 - or self.survey.find("<IMG") > -1 - or self.survey.find("<A") > -1 - ): - return "Yes" - return "Missing" - - def hassurveydata(self): - if not self.underground_centre_line: - return "No" - if self.survex_filcavee: - return "Yes" - return "Missing" - def slug(self): primarySlugs = self.caveslug_set.filter(primary=True) if primarySlugs: @@ -135,8 +113,8 @@ class Cave(TroggleModel): else: return self.unofficial_number - def reference(self): - return f"{self.kat_area()}-{self.number()}" + def reference(self): # tidy this up, no longer used? + return f"{self.areacode}-{self.number()}" def get_absolute_url(self): if self.kataster_number: @@ -148,7 +126,10 @@ class Cave(TroggleModel): return Path(settings.URL_ROOT) / self.url # not good Django style.. NEEDS actual URL def url_parent(self): - return self.url.rsplit("/", 1)[0] + if self.url: + return self.url.rsplit("/", 1)[0] + else: + return "NO cave.url" def __str__(self, sep=": "): return str(self.slug()) @@ -174,9 +155,6 @@ class Cave(TroggleModel): qms = self.get_open_QMs() | self.get_ticked_QMs() # set union operation return qms # a QuerySet - def kat_area(self): - return self.areacode - def entrances(self): return CaveAndEntrance.objects.filter(cave=self) diff --git a/core/views/caves.py b/core/views/caves.py index 250ae0e..8727c03 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -353,7 +353,7 @@ def cavepage(request, karea=None, subpath=None, slug=None): def edit_cave(request, path="", slug=None): """This is the form that edits all the cave data and writes out an XML file in the :expoweb: repo folder The format for the file being saved is in templates/dataformat/cave.xml - Warning. This uses Django deep magic. + Warning. This uses Django deep magic in the CaveForm processing. It saves the data into into the database and into the html file, which it then commits to git. """ @@ -372,9 +372,9 @@ def edit_cave(request, path="", slug=None): # print(f'! POST is valid. {cave}') cave = form.save(commit=False) if not cave.filename: - cave.filename = form.get_area() + "-" + cave.number() + ".html" + cave.filename = cave.areacode + "-" + cave.number() + ".html" if not cave.url: - cave.url = form.get_area() + "/" + cave.number() + ".html" + cave.url = cave.areacode + "/" + cave.number() cave.save() form.save_m2m() if slug is None: diff --git a/core/views/survex.py b/core/views/survex.py index b00aed0..4ed8138 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -557,7 +557,8 @@ def get_survexareapath(area): # direct local non-database browsing through the svx file repositories # every time the page is viewed! Should cache this. def survexcaveslist(request): - """This reads the entire list of caves in the Loser repo directory and produces a complete report. + """NEEDS REWRITING COMPLETELY + This reads the entire list of caves in the Loser repo directory and produces a complete report. It can find caves which have not yet been properly registered in the system by Databasereset.py because someone may have uploaded the survex files with git without doing the rest of the integration process. @@ -566,6 +567,8 @@ def survexcaveslist(request): what is already in the db, and just construct: onefilecaves, multifilecaves, subdircaves. It uses very impenetrable code in identifycavedircontents() + + It is MISSING some caves, e.g. "LA34" should appear twice, as 1623 and 1626. """ # TO DO - filter out the non-public caves from display UNLESS LOGGED IN # This is very impenetrable code, original from Aaron Curtis I think. @@ -692,11 +695,11 @@ def check_cave_registered(areacode, survex_cave): A serious bodge. """ try: - cave = Cave.objects.get(kataster_number=survex_cave) + cave = Cave.objects.get(areacode=areacode, kataster_number=survex_cave) return str(cave) except MultipleObjectsReturned: - caves = Cave.objects.filter(kataster_number=survex_cave) + caves = Cave.objects.filter(areacode=areacode, kataster_number=survex_cave) for c in caves: if str(c) == areacode + "-" + survex_cave: return str(c) # just get the first that matches @@ -706,11 +709,14 @@ def check_cave_registered(areacode, survex_cave): pass try: - cave = Cave.objects.get(unofficial_number=survex_cave) # should be unique! - if cave.kataster_number: - return str(cave) - else: - return None + cave = Cave.objects.get(areacode=areacode, unofficial_number=survex_cave) # Not unique, e.g. LA34 + return str(cave) + except MultipleObjectsReturned: + caves = Cave.objects.filter(areacode=areacode,unofficial_number=survex_cave) + for c in caves: + if str(c) == areacode + "-" + survex_cave: + return str(c) # just get the first that matches + return None # many returned but none in correct area except ObjectDoesNotExist: pass |