summaryrefslogtreecommitdiffstats
path: root/core/utils.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2024-03-14 19:53:01 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2024-03-14 19:53:01 +0000
commitb3490aa52d0a7f36bb2675ee8fb5825550684e97 (patch)
tree7b3516688612d9546a58079f1b581a125a855003 /core/utils.py
parent7325d934f985407ad121e967600f0d5aed08e8b3 (diff)
downloadtroggle-b3490aa52d0a7f36bb2675ee8fb5825550684e97.tar.gz
troggle-b3490aa52d0a7f36bb2675ee8fb5825550684e97.tar.bz2
troggle-b3490aa52d0a7f36bb2675ee8fb5825550684e97.zip
current year auto
Diffstat (limited to 'core/utils.py')
-rw-r--r--core/utils.py16
1 files changed, 14 insertions, 2 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"""