summaryrefslogtreecommitdiffstats
path: root/core/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'core/utils.py')
-rw-r--r--core/utils.py33
1 files changed, 26 insertions, 7 deletions
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 = "<a href='index.html'>index</a><br><a href='mission.html'>mission</a><br><a href='logbook.html'>logbook</a><br>"
+ 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"<html><head><title>{ff}</title></head><body><h1>{ff}</h1>{t}</body></html>")
+
+
+
+
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: