summaryrefslogtreecommitdiffstats
path: root/core/views/cave_kataster.py
blob: dc06ea616d9cc5c7bff6c8a62ae4ed2f744c59c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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,
         },
    )    
    
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?
SURVEX_DATA = REPOS_ROOT_PATH / "loser"
EXPOWEB = REPOS_ROOT_PATH / "expoweb"
CAVEDESCRIPTIONS = EXPOWEB / "cave_data"
ENTRANCEDESCRIPTIONS = EXPOWEB / "entrance_data"
    
"""