from pathlib import Path import django.forms as forms from django.http import HttpResponseRedirect from django.shortcuts import redirect, render import troggle.settings as settings from troggle.core.utils import ( COOKIE_MAX_AGE, WriteAndCommitError, current_expo, get_cookie, git_string, write_and_commit, ) from troggle.core.views.caves import get_cave_from_slug """Forms to handle renaming files and editing contents when a cave is 'katastered', ie.e moves from an informal number, such as 1623-2024-BL-10 to 1623-999 """ def kataster(request, slug): if cave := get_cave_from_slug(slug.lower()): pass elif cave := get_cave_from_slug(slug.upper()): pass else: return HttpResponseRedirect("/caves") cavename = str(cave) + ".html" cave_data = Path( "cave_data", cavename ) if not (settings.EXPOWEB / cave_data).is_file: cave_data = "does not exist" ent_dir = settings.EXPOWEB / "entrance_data" entrance_data = [] for ent in ent_dir.iterdir(): if str(ent.name).startswith(str(cave)): print(ent.name) entrance_data.append("entrance_data/"+ent.name) form = KatasterForm() return render( request, "cave_kataster.html", { "form": form, "cave": cave, "cave_data": cave_data, "entrance_data": entrance_data, "knum": "999", }, ) class KatasterForm(forms.Form): areacode = forms.CharField(label='Full name', max_length=4, widget=forms.TextInput(attrs={'tabindex': 1, 'placeholder': '1623'})) official_name = forms.CharField(label='CUCC name', max_length=160,widget=forms.TextInput(attrs={'tabindex': 2, 'placeholder': '2012-ns-07'})) kataster_number= forms.CharField(max_length=10, widget=forms.TextInput(attrs={'tabindex': 3, 'placeholder': '999'})) """ areacode = models.CharField(max_length=4, blank=True, null=True) # could use models.IntegerChoices entrances = models.ManyToManyField("Entrance", through="CaveAndEntrance") filename = models.CharField(max_length=200) # if a cave is 'pending' this is not set. Otherwise it is. kataster_code = models.CharField(max_length=20, blank=True, null=True) kataster_number = models.CharField(max_length=10, blank=True, null=True) kataster_status = models.TextField(blank=True, null=True) official_name = models.CharField(max_length=160) survex_file = models.CharField(max_length=100, blank=True, null=True) # should be a foreign key? unofficial_number = models.CharField(max_length=60, blank=True, null=True) url = models.CharField(max_length=300, blank=True, null=True, unique = True) SURVEX_DATA = REPOS_ROOT_PATH / "loser" EXPOWEB = REPOS_ROOT_PATH / "expoweb" CAVEDESCRIPTIONS = EXPOWEB / "cave_data" ENTRANCEDESCRIPTIONS = EXPOWEB / "entrance_data" """