diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/utils.py | 16 | ||||
-rw-r--r-- | core/views/uploads.py | 7 |
2 files changed, 18 insertions, 5 deletions
diff --git a/core/utils.py b/core/utils.py index daf48b3..fd85af6 100644 --- a/core/utils.py +++ b/core/utils.py @@ -6,11 +6,14 @@ import random import resource import string import subprocess +from datetime import datetime, timezone from decimal import getcontext from pathlib import Path +from django.contrib.auth.models import User + from troggle.core.models.troggle import Expedition getcontext().prec = 2 # use 2 significant figures for decimal calculations @@ -89,9 +92,18 @@ def alphabet_suffix(n): def current_expo(): expos = Expedition.objects.all().order_by('-year') if expos: - return expos[0].year + 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() + return year else: - return settings.EPOCH.year + return settings.EPOCH.year # this is 1970 def only_commit(fname, message): """Only used to commit a survex file edited and saved in view/survex.py""" diff --git a/core/views/uploads.py b/core/views/uploads.py index dd5d25d..7265fff 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -1,5 +1,5 @@ import subprocess -from datetime import datetime +from datetime import datetime, timezone from pathlib import Path from django import forms @@ -166,7 +166,7 @@ def logbookedit(request, year=None, slug=None): try: expo = Expedition.objects.get(year=year) except: - year = current_expo() + year = current_expo() # creates new Expedition object if needed return year def new_entry_form(): @@ -608,7 +608,8 @@ def photoupload(request, folder=None): Pending generic file renaming capability more generally. """ - year = settings.PHOTOS_YEAR + year = current_expo() + # year = settings.PHOTOS_YEAR filesaved = False actual_saved = [] |