diff --git a/core/utils.py b/core/utils.py index 04bc6e2..052e9b8 100644 --- a/core/utils.py +++ b/core/utils.py @@ -89,18 +89,37 @@ def alphabet_suffix(n): suffix = "_X_" + random.choice(string.ascii_lowercase) + random.choice(string.ascii_lowercase) return suffix +def make_new_expo(year): + coUniqueAttribs = {"year": year} + otherAttribs = {"name": f"CUCC expo {year}"} + e = Expedition.objects.create(**otherAttribs, **coUniqueAttribs) + u = User.objects.get(username='expo') + u.current_year = year + u.save() + +def make_new_expo_dir(year): + t = "index
mission
logbook
" + year_dir = Path(settings.EXPOWEB, 'years', year) + if not year_dir.is_dir(): + year_dir.mkdir(parents=True, exist_ok=True) + for ff in ["index","logbook", "mission"]: + p = Path(year_dir, ff+".html") + if not p.is_file(): + p.write_text(f"{ff}

{ff}

{t}") + + + + def current_expo(): expos = Expedition.objects.all().order_by('-year') if expos: year = str(datetime.now(timezone.utc).year) last_expo = expos[0].year - if last_expo != year: # create the expo object for the coming year, after Dec.31st - coUniqueAttribs = {"year": year} - otherAttribs = {"name": f"CUCC expo {year}"} - e = Expedition.objects.create(**otherAttribs, **coUniqueAttribs) - u = User.objects.get(username='expo') - u.current_year = year - u.save() + make_new_expo_dir(year) + if last_expo != year: # coming year, after Dec.31st + make_new_expo(year) + make_new_expo_dir(year) + # print(f"---{year}---") return year else: diff --git a/core/views/caves.py b/core/views/caves.py index d71749c..1e9106c 100644 --- a/core/views/caves.py +++ b/core/views/caves.py @@ -19,6 +19,7 @@ from troggle.core.models.caves import Cave, CaveAndEntrance, Entrance, GetCaveLo from troggle.core.models.logbooks import CaveSlug, QM from troggle.core.models.wallets import Wallet from troggle.core.utils import write_and_commit +from troggle.core.utils import current_expo from troggle.core.views import expo from troggle.settings import CAVEDESCRIPTIONS, ENTRANCEDESCRIPTIONS from troggle.parsers.caves import read_cave, read_entrance @@ -152,7 +153,7 @@ def caveindex(request): "caves1627": caves1627, "caves1624": caves1624, "notablecaves": getnotablecaves(), - "cavepage": True}, + "cavepage": True, "year": current_expo()}, ) def entranceindex(request): @@ -177,7 +178,7 @@ def cave3d(request, cave_id=""): except Cave.MultipleObjectsReturned: # should really produce a better error message. This is a failure of ambiguous aliases probably. caves = Cave.objects.filter(url=kpath) - return render(request, "svxcaveseveral.html", {"settings": settings, "caves": caves}) + return render(request, "svxcaveseveral.html", {"settings": settings, "caves": caves, "year": current_expo()}) else: return file3d(request, cave, cave_id) @@ -296,7 +297,8 @@ def rendercave(request, cave, slug, cave_id=""): "cave_id": cave_id, "svxstem": str(svxstem), "svx3d": svx3d, - "wallets": wallets, + "wallets": wallets, + "year": current_expo() } # Do not catch any exceptions here: propagate up to caller @@ -460,7 +462,7 @@ def edit_cave(request, path="", slug=None): { "form": form, "cave": cave, - "message": message, + "message": message, "year": current_expo(), #"caveAndEntranceFormSet": ceFormSet, "path": path + "/", # used for saving images if attached }, @@ -652,7 +654,7 @@ def edit_entrance(request, path="", caveslug=None, entslug=None): return render( request, "editentrance.html", - { + { "year": current_expo(), "entform": entform, "cave": cave, "ent": entrance, @@ -670,7 +672,7 @@ def ent(request, cave_id, ent_letter): return render( request, "entrance.html", - { + { "year": current_expo(), "cave": cave, "entrance": cave_and_ent.entrance, "letter": cave_and_ent.entranceletter, @@ -683,7 +685,7 @@ def cave_debug(request): return render( request, "cave_debug.html", - {"ents": ents, "caves": caves}, + {"ents": ents, "caves": caves, "year": current_expo()}, ) def caveslist(request): @@ -692,7 +694,7 @@ def caveslist(request): return render( request, "caveslist.html", - {"caves": caves}, + {"caves": caves, "year": current_expo()}, ) def get_entrances(request, caveslug): try: @@ -700,7 +702,7 @@ def get_entrances(request, caveslug): except: return render(request, "errors/badslug.html", {"badslug": f"{caveslug} - from get_entrances()"}) return render( - request, "options.html", {"items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]} + request, "options.html", {"year": current_expo(), "items": [(e.entrance.slug(), e.entrance.slug()) for e in cave.entrances()]} ) @@ -717,9 +719,9 @@ def caveQMs(request, slug, open=False): if cave.non_public and settings.PUBLIC_SITE and not request.user.is_authenticated: return render(request, "nonpublic.html", {"instance": cave}) elif open: - return render(request, "cave_open_qms.html", {"cave": cave}) + return render(request, "cave_open_qms.html", {"cave": cave, "year": current_expo()}) else: - return render(request, "cave_qms.html", {"cave": cave}) + return render(request, "cave_qms.html", {"cave": cave, "year": current_expo()}) def qm(request, cave_id, qm_id, year, grade=None, blockname=None): @@ -780,7 +782,7 @@ def qm(request, cave_id, qm_id, year, grade=None, blockname=None): qm, f"{qmslug=}:{cave_id=} {year=} {qm_id=} {blockname=} {qm.expoyear=} {qm.completion_description=}", ) - return render(request, "qm.html", {"qm": qm}) + return render(request, "qm.html", {"qm": qm, "year": current_expo()}) else: # raise return render( diff --git a/core/views/logbooks.py b/core/views/logbooks.py index d9ae442..4579e6e 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -9,7 +9,7 @@ from troggle.core.models.logbooks import LogbookEntry, PersonLogEntry, QM from troggle.core.models.survex import SurvexBlock, SurvexFile from troggle.core.models.troggle import Expedition, Person from troggle.core.models.wallets import Wallet -from troggle.core.utils import TROG +from troggle.core.utils import TROG, current_expo from troggle.parsers.imports import import_logbook @@ -118,6 +118,7 @@ def expedition(request, expeditionname): personexpodays.append({"personexpedition": personexpedition, "personrow": prow}) ts[expeditionname] = { + "year": int(expeditionname), "expedition": expo, "expeditions": expeditions, "personexpodays": personexpodays, diff --git a/core/views/scans.py b/core/views/scans.py index 2714716..f24b972 100644 --- a/core/views/scans.py +++ b/core/views/scans.py @@ -14,6 +14,7 @@ from troggle.core.views.expo import getmimetype from troggle.parsers.caves import add_cave_to_pending_list from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.survex import set_walletdate +from troggle.core.utils import current_expo """ @@ -255,7 +256,7 @@ def walletslistperson(request, slug): request, "personwallets.html", {"manywallets": manywallets, "settings": settings, "person": p, "expeditions": expeditions, - "length_ug": length_ug} + "length_ug": length_ug, "year": current_expo()} ) @@ -330,7 +331,7 @@ def cavewallets(request, caveid): request, "cavewallets.html", {"manywallets": manywallets, "settings": settings, "cave": cave, "expeditions": expeditions, - "length_ug": length_ug} + "length_ug": length_ug, "year": current_expo()} ) @@ -340,10 +341,10 @@ def oldwallet(request, path): print(f"! - oldwallet path:{path}") try: wallet = Wallet.objects.get(walletname=urlunquote(path)) - return render(request, "wallet_old.html", {"wallet": wallet, "settings": settings}) + return render(request, "wallet_old.html", {"wallet": wallet, "settings": settings, "year": current_expo()}) except: message = f"Scan folder error or not found '{path}' ." - return render(request, "errors/generic.html", {"message": message}) + return render(request, "errors/generic.html", {"message": message,"year": current_expo()}) def scansingle(request, path, file): @@ -377,5 +378,5 @@ def allscans(request): # manywallets = Wallet.objects.all().prefetch_related('singlescan') fails as the link is defined on 'singlescan' not on 'wallet' expeditions = Expedition.objects.all() return render( - request, "walletsall.html", {"manywallets": manywallets, "settings": settings, "expeditions": expeditions} + request, "walletsall.html", {"manywallets": manywallets, "settings": settings, "expeditions": expeditions, "year": current_expo()} ) diff --git a/core/views/statistics.py b/core/views/statistics.py index 49e8674..e344ed2 100644 --- a/core/views/statistics.py +++ b/core/views/statistics.py @@ -11,6 +11,7 @@ from troggle.core.models.survex import SurvexStation, SurvexPersonRole from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition from troggle.core.models.wallets import Wallet from troggle.parsers.people import GetPersonExpeditionNameLookup, foreign_friends +from troggle.core.utils import current_expo # from django.views.generic.list import ListView """Very simple report pages summarizing data about the whole set of expeditions and of @@ -65,13 +66,15 @@ def svxfilewild(request, year=None): for w in wallets: for sb in w.survexblock_set.all(): walletslength += sb.legslength - - return render(request, "survexfilewild.html", + if not year: + year = current_expo() + return render(request, "survexfilewild.html", {"addupsurvexlength": addupsurvexlength / 1000, "legsbyexpo": legsbyexpo, "nsurvexlegs": addupsurvexlegs, "walletslength": walletslength, "wildlength": wildlength, + "year":year, "svxwild": svxwild} ) @@ -97,7 +100,7 @@ def therionissues(request): for line in therionlog: line = line.replace("! Un-parsed image filename:", "") newlog.append(line) - return render(request, "therionreport.html", {"therionlog": newlog}) + return render(request, "therionreport.html", {"therionlog": newlog, "year": current_expo()}) def surveximport(request): @@ -110,7 +113,7 @@ def surveximport(request): contents = f.read() else: print(f"{logpath} NOT FOUND {len(contents)}") - return render(request, "survexreport.html", {"log": contents}) + return render(request, "survexreport.html", {"log": contents, "year": current_expo()}) def survexdebug(request): @@ -123,7 +126,7 @@ def survexdebug(request): contents = f.read() else: print(f"{logpath} NOT FOUND {len(contents)}") - return render(request, "survexdebug.html", {"log": contents}) + return render(request, "survexdebug.html", {"log": contents, "year": current_expo()}) def pathsreport(request): @@ -227,7 +230,7 @@ def pathsreport(request): return render( request, "pathsreport.html", - {"pathsdict": pathsdict, "bycodeslist": bycodeslist2, "bypathslist": bypathslist, "ncodes": ncodes}, + {"pathsdict": pathsdict, "bycodeslist": bycodeslist2, "bypathslist": bypathslist, "ncodes": ncodes, "year": current_expo()}, ) @@ -258,7 +261,7 @@ def stats(request): renderDict = { **statsDict, - **{"addupsurvexlength": addupsurvexlength / 1000, "legsbyexpo": legsbyexpo, "nsurvexlegs": addupsurvexlegs}, + **{"addupsurvexlength": addupsurvexlength / 1000, "legsbyexpo": legsbyexpo, "nsurvexlegs": addupsurvexlegs, "year": current_expo()}, } # new syntax return render(request, "statistics.html", renderDict) @@ -272,7 +275,7 @@ def dataissues(request): dilist = list(DataIssue.objects.all()) dilist.sort(key=myFunc) - return render(request, "dataissues.html", {"didict": dilist}) + return render(request, "dataissues.html", {"didict": dilist, "year": current_expo()}) def stations(request): @@ -313,7 +316,7 @@ def stations(request): stations = SurvexStation.objects.all() # NB these are NOT all the stations in troggle_import_root.pos - return render(request, "stations.html", {"ents": ents, "gpsents": gpsents, "stations": stations}) + return render(request, "stations.html", {"ents": ents, "gpsents": gpsents, "stations": stations, "year": current_expo()}) def aliases(request, year): diff --git a/core/views/survex.py b/core/views/survex.py index 0437d12..b24b51b 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -20,7 +20,7 @@ from troggle.core.models.logbooks import LogbookEntry from troggle.core.models.caves import Cave, GetCaveLookup from troggle.core.models.survex import SurvexFile, SurvexBlock #, SurvexDirectory from troggle.core.models.wallets import Wallet -from troggle.core.utils import only_commit +from troggle.core.utils import only_commit, current_expo from troggle.parsers.survex import parse_one_file """Everything that views survexfiles @@ -389,6 +389,7 @@ def svx(request, survex_file): events = events_on_dates(svxblocks) vmap = { + "year": current_expo(), "settings": settings, "warning": warning, "has_3d": has_3d, @@ -640,7 +641,8 @@ def survexcaveslist(request): "settings": settings, "onefilecaves": onefilecaves, "multifilecaves": multifilecaves, - "subdircaves": subdircaves, + "subdircaves": subdircaves, + "year": current_expo(), }, ) @@ -654,7 +656,7 @@ def survexdir(request): f.pathbad = True if Path(settings.SURVEX_DATA, f"{f.path}.svx").is_file(): f.pathbad = False - return render(request, "survexdir.html", {"survexfiles": survexfiles, "caves": caves}) + return render(request, "survexdir.html", {"survexfiles": survexfiles, "caves": caves, "year": current_expo()}) def get_primaries(cave): sds = [] @@ -674,7 +676,7 @@ def survexcavesingle(request, cave_shortname): cave = Gcavelookup[cave_shortname] # print(f"survexcavesingle {cave_shortname=} => {cave=}") cave.sds = get_primaries(cave) - return render(request, "svxcaves.html", {"settings": settings, "caves": [cave]}) + return render(request, "svxcaves.html", {"settings": settings, "caves": [cave], "year": current_expo()}) else: caves = Cave.objects.filter(kataster_number=cave_shortname) if len(caves) > 0: @@ -682,9 +684,9 @@ def survexcavesingle(request, cave_shortname): for cave in caves: cave.sds = get_primaries(cave) # print(f"many {cave=} => {cave.sds=}") - return render(request, "svxcaves.html", {"settings": settings, "caves": caves}) + return render(request, "svxcaves.html", {"settings": settings, "caves": caves, "year": current_expo()}) else: - return render(request, "errors/svxcaves404.html", {"settings": settings, "cave": cave_shortname}) + return render(request, "errors/svxcaves404.html", {"settings": settings, "cave": cave_shortname, "year": current_expo()}) def check_cave_registered(areacode, survex_cave): """Checks whether a cave has been properly registered when it is found in the Loser repo diff --git a/index.html b/index.html new file mode 100644 index 0000000..e69de29