mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
current year auto
This commit is contained in:
parent
7325d934f9
commit
b3490aa52d
@ -6,11 +6,14 @@ import random
|
|||||||
import resource
|
import resource
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from datetime import datetime, timezone
|
||||||
|
|
||||||
from decimal import getcontext
|
from decimal import getcontext
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
from troggle.core.models.troggle import Expedition
|
from troggle.core.models.troggle import Expedition
|
||||||
|
|
||||||
getcontext().prec = 2 # use 2 significant figures for decimal calculations
|
getcontext().prec = 2 # use 2 significant figures for decimal calculations
|
||||||
@ -89,9 +92,18 @@ def alphabet_suffix(n):
|
|||||||
def current_expo():
|
def current_expo():
|
||||||
expos = Expedition.objects.all().order_by('-year')
|
expos = Expedition.objects.all().order_by('-year')
|
||||||
if expos:
|
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:
|
else:
|
||||||
return settings.EPOCH.year
|
return settings.EPOCH.year # this is 1970
|
||||||
|
|
||||||
def only_commit(fname, message):
|
def only_commit(fname, message):
|
||||||
"""Only used to commit a survex file edited and saved in view/survex.py"""
|
"""Only used to commit a survex file edited and saved in view/survex.py"""
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
@ -166,7 +166,7 @@ def logbookedit(request, year=None, slug=None):
|
|||||||
try:
|
try:
|
||||||
expo = Expedition.objects.get(year=year)
|
expo = Expedition.objects.get(year=year)
|
||||||
except:
|
except:
|
||||||
year = current_expo()
|
year = current_expo() # creates new Expedition object if needed
|
||||||
return year
|
return year
|
||||||
|
|
||||||
def new_entry_form():
|
def new_entry_form():
|
||||||
@ -608,7 +608,8 @@ def photoupload(request, folder=None):
|
|||||||
|
|
||||||
Pending generic file renaming capability more generally.
|
Pending generic file renaming capability more generally.
|
||||||
"""
|
"""
|
||||||
year = settings.PHOTOS_YEAR
|
year = current_expo()
|
||||||
|
# year = settings.PHOTOS_YEAR
|
||||||
filesaved = False
|
filesaved = False
|
||||||
actual_saved = []
|
actual_saved = []
|
||||||
|
|
||||||
|
@ -672,7 +672,7 @@ def LoadLogbooks():
|
|||||||
message = " ! - No expeditions found. Attempting to 'people' first"
|
message = " ! - No expeditions found. Attempting to 'people' first"
|
||||||
DataIssue.objects.create(parser="logbooks", message=message)
|
DataIssue.objects.create(parser="logbooks", message=message)
|
||||||
print(message)
|
print(message)
|
||||||
load_people_expos()
|
load_people_expos() # by loading the folk list
|
||||||
expos = Expedition.objects.all()
|
expos = Expedition.objects.all()
|
||||||
if len(expos) <= 1:
|
if len(expos) <= 1:
|
||||||
message = " ! - No expeditions found, even after attempting to load 'people'. Abort."
|
message = " ! - No expeditions found, even after attempting to load 'people'. Abort."
|
||||||
|
@ -89,6 +89,13 @@ def load_people_expos():
|
|||||||
"""This is where the folk.csv file is parsed to read people's names.
|
"""This is where the folk.csv file is parsed to read people's names.
|
||||||
Which it gets wrong for people like Lydia-Clare Leather and various 'von' and 'de' middle 'names'
|
Which it gets wrong for people like Lydia-Clare Leather and various 'von' and 'de' middle 'names'
|
||||||
and McLean and Mclean and McAdam - interaction with the url parser in urls.py too
|
and McLean and Mclean and McAdam - interaction with the url parser in urls.py too
|
||||||
|
|
||||||
|
This is ALSO where all the Expedition objects get created. So this is the point at which troggle
|
||||||
|
gets told what expeditions exist.
|
||||||
|
|
||||||
|
Given that we need to do stuff for the coming expo, well before we update the folk list,
|
||||||
|
the Expedition object for the coming expo is created elsewhere - in addition to
|
||||||
|
those created here, if it does not exist.
|
||||||
"""
|
"""
|
||||||
DataIssue.objects.filter(parser="people").delete()
|
DataIssue.objects.filter(parser="people").delete()
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
<a href="/survexfilewild/2023">Wild Survex(2023)</a> |
|
<a href="/survexfilewild/2023">Wild Survex(2023)</a> |
|
||||||
<a href="/wallets/year/2023">Wallets(2023)</a> |
|
<a href="/wallets/year/2023">Wallets(2023)</a> |
|
||||||
<a href="{% url "expedition" 2023 %}">Expo(2023)</a> |
|
<a href="{% url "expedition" 2023 %}">Expo(2023)</a> |
|
||||||
<a href="{% url "controlpanel" %}">Control panel</a> |
|
<a href="{% url "controlpanel" %}">Control panel</a> | {{ user.current_year }} |
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user