mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
fixing Sunday display on calendar
This commit is contained in:
parent
7d98980121
commit
3742e0f367
@ -33,6 +33,7 @@ todo='''
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
class CaveSlug(models.Model):
|
class CaveSlug(models.Model):
|
||||||
|
"""Moved here to avoid nasty cyclic import error"""
|
||||||
cave = models.ForeignKey('Cave',on_delete=models.CASCADE)
|
cave = models.ForeignKey('Cave',on_delete=models.CASCADE)
|
||||||
slug = models.SlugField(max_length=50, unique = True)
|
slug = models.SlugField(max_length=50, unique = True)
|
||||||
primary = models.BooleanField(default=False)
|
primary = models.BooleanField(default=False)
|
||||||
@ -41,7 +42,6 @@ class LogbookEntry(TroggleModel):
|
|||||||
"""Single parsed entry from Logbook
|
"""Single parsed entry from Logbook
|
||||||
"""
|
"""
|
||||||
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.ld()
|
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.ld()
|
||||||
# expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)#MJG wants to KILL THIS (redundant information)
|
|
||||||
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.SET_NULL) # yes this is double-
|
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.SET_NULL) # yes this is double-
|
||||||
title = models.CharField(max_length=200)
|
title = models.CharField(max_length=200)
|
||||||
cave_slug = models.SlugField(max_length=50, blank=True, null=True)
|
cave_slug = models.SlugField(max_length=50, blank=True, null=True)
|
||||||
@ -77,9 +77,16 @@ class LogbookEntry(TroggleModel):
|
|||||||
def DayIndex(self):
|
def DayIndex(self):
|
||||||
"""This is used to set different colours for the different trips on
|
"""This is used to set different colours for the different trips on
|
||||||
the calendar view of the expedition"""
|
the calendar view of the expedition"""
|
||||||
index = list(LogbookEntry.objects.filter(date=self.date)).index(self)
|
mx = 10
|
||||||
if index not in range(0,10):
|
todays = list(LogbookEntry.objects.filter(date=self.date))
|
||||||
print(f"Unexpected LogbookEntry DayIndex '{index}' {self}")
|
if self in todays:
|
||||||
|
index = todays.index(self)
|
||||||
|
else:
|
||||||
|
print(f"DayIndex: Synchronization error. Restart server. {self}")
|
||||||
|
index = 0
|
||||||
|
|
||||||
|
if index not in range(0, mx):
|
||||||
|
print(f"DayIndex: More than {mx-1} LogbookEntry items on one day '{index}' {self}")
|
||||||
index = 0
|
index = 0
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
@ -148,10 +148,11 @@ class SurvexBlock(models.Model):
|
|||||||
def DayIndex(self):
|
def DayIndex(self):
|
||||||
"""This is used to set different colours for the different trips on
|
"""This is used to set different colours for the different trips on
|
||||||
the calendar view of the expedition"""
|
the calendar view of the expedition"""
|
||||||
|
mx = 10
|
||||||
index = list(SurvexBlock.objects.filter(date=self.date)).index(self)
|
index = list(SurvexBlock.objects.filter(date=self.date)).index(self)
|
||||||
if index not in range(0,10):
|
if index not in range(0, mx):
|
||||||
print(f"Unexpected SurvexBlock DayIndex '{index}' {self}")
|
print(f"DayIndex: More than {mx-1} SurvexBlock items on one day '{index}' {self}")
|
||||||
index = 10
|
index = 0
|
||||||
#return list(self.survexblock_set.all()).index(self)
|
#return list(self.survexblock_set.all()).index(self)
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ class DataIssue(TroggleModel):
|
|||||||
|
|
||||||
We have replaced all assertions in the code with messages and local fix-ups or skips:
|
We have replaced all assertions in the code with messages and local fix-ups or skips:
|
||||||
https://martinfowler.com/articles/replaceThrowWithNotification.html
|
https://martinfowler.com/articles/replaceThrowWithNotification.html
|
||||||
|
|
||||||
|
See also the use of stash_data_issue() & store_data_issues() in parsers/survex.py which defer writing to the database until the end of the import.
|
||||||
"""
|
"""
|
||||||
date = models.DateTimeField(auto_now_add=True, blank=True)
|
date = models.DateTimeField(auto_now_add=True, blank=True)
|
||||||
parser = models.CharField(max_length=50, blank=True, null=True)
|
parser = models.CharField(max_length=50, blank=True, null=True)
|
||||||
@ -81,34 +83,9 @@ class Expedition(TroggleModel):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
|
return urljoin(settings.URL_ROOT, reverse('expedition', args=[self.year]))
|
||||||
|
|
||||||
# construction function. should be moved out
|
|
||||||
# def get_expedition_day(self, date):
|
|
||||||
# expeditiondays = self.expeditionday_set.filter(date=date)
|
|
||||||
# if expeditiondays:
|
|
||||||
# if len(expeditiondays) == 1:
|
|
||||||
# return expeditiondays[0]
|
|
||||||
# else:
|
|
||||||
# message =f'! - More than one expeditionday for the same date: {date} .\n - This should never happen. \n - Restart mysql and run reset to clean database.'
|
|
||||||
# DataIssue.objects.create(parser='expedition', message=message)
|
|
||||||
# return expeditiondays[0]
|
|
||||||
# res = ExpeditionDay(expedition=self, date=date)
|
|
||||||
# res.save()
|
|
||||||
# return res
|
|
||||||
|
|
||||||
# def day_min(self):
|
|
||||||
# """First day of expedition
|
|
||||||
# """
|
|
||||||
# res = self.expeditionday_set.all()
|
|
||||||
# return res and res[0] or None
|
|
||||||
|
|
||||||
# def day_max(self):
|
|
||||||
# """last day of expedition
|
|
||||||
# """
|
|
||||||
# res = self.expeditionday_set.all()
|
|
||||||
# return res and res[len(res) - 1] or None
|
|
||||||
|
|
||||||
class ExpeditionDay(TroggleModel):
|
class ExpeditionDay(TroggleModel):
|
||||||
"""Exists only on Expedition now. Removed from logbookentry, persontrip, survex stuff etc.
|
"""Exists only on Expedition now. Removed links from logbookentry, persontrip, survex stuff etc.
|
||||||
"""
|
"""
|
||||||
expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
|
expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
|
||||||
date = models.DateField()
|
date = models.DateField()
|
||||||
@ -116,11 +93,11 @@ class ExpeditionDay(TroggleModel):
|
|||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('date',)
|
ordering = ('date',)
|
||||||
|
|
||||||
def GetPersonTrip(self, personexpedition):
|
# def GetPersonTrip(self, personexpedition):
|
||||||
"""returns all logbook trips for this expeditonday
|
# """returns all logbook trips for this expeditonday
|
||||||
"""
|
# """
|
||||||
personexpeditions = self.persontrip_set.filter(expeditionday=self)
|
# personexpeditions = self.persontrip_set.filter(expeditionday=self)
|
||||||
return personexpeditions and personexpeditions[0] or None
|
# return personexpeditions and personexpeditions[0] or None
|
||||||
|
|
||||||
class Person(TroggleModel):
|
class Person(TroggleModel):
|
||||||
"""single Person, can go on many years
|
"""single Person, can go on many years
|
||||||
@ -182,7 +159,7 @@ class PersonExpedition(TroggleModel):
|
|||||||
slugfield = models.SlugField(max_length=50,blank=True, null=True) # 2022 to be used in future
|
slugfield = models.SlugField(max_length=50,blank=True, null=True) # 2022 to be used in future
|
||||||
|
|
||||||
is_guest = models.BooleanField(default=False)
|
is_guest = models.BooleanField(default=False)
|
||||||
nickname = models.CharField(max_length=100,blank=True, null=True)
|
nickname = models.CharField(max_length=100,blank=True, null=True) # removbe this
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('-expedition',)
|
ordering = ('-expedition',)
|
||||||
@ -208,11 +185,4 @@ class PersonExpedition(TroggleModel):
|
|||||||
survexblocks = [personrole.survexblock for personrole in self.survexpersonrole_set.all() ]
|
survexblocks = [personrole.survexblock for personrole in self.survexpersonrole_set.all() ]
|
||||||
return sum([survexblock.legslength for survexblock in set(survexblocks)])
|
return sum([survexblock.legslength for survexblock in set(survexblocks)])
|
||||||
|
|
||||||
# would prefer to return actual person trips so we could link to first and last ones
|
|
||||||
# def day_min(self):
|
|
||||||
# res = self.persontrip_set.aggregate(day_min=Min("expeditionday__date"))
|
|
||||||
# return res["day_min"]
|
|
||||||
|
|
||||||
# def day_max(self):
|
|
||||||
# res = self.persontrip_set.all().aggregate(day_max=models.Max("expeditionday__date"))
|
|
||||||
# return res["day_max"]
|
|
@ -58,22 +58,32 @@ def notablepersons(request):
|
|||||||
def expedition(request, expeditionname):
|
def expedition(request, expeditionname):
|
||||||
'''Returns a rendered page for one expedition, specified by the year e.g. '2019'.
|
'''Returns a rendered page for one expedition, specified by the year e.g. '2019'.
|
||||||
If page caching is enabled, it caches the dictionaries used to render the template page.
|
If page caching is enabled, it caches the dictionaries used to render the template page.
|
||||||
|
|
||||||
|
This is not as difficult to understand as it looks. Yes there are many levels of indirection, with multiple trees being traversed at the same time. And the Django special syntax
|
||||||
|
makes this hard for normal Python programmers.
|
||||||
|
|
||||||
|
Remember that 'personexpedition__expedition' is interpreted by Django to mean the
|
||||||
|
'expedition' object which is connected by a foreign key to the 'personexpedition'
|
||||||
|
object, which is a field of the PersonTrip object:
|
||||||
|
PersonTrip.objects.filter(personexpedition__expedition=expo)
|
||||||
|
|
||||||
|
Queries are not evaluated to hit the database until a result is actually used. Django
|
||||||
|
does lazy evaluation.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
try:
|
||||||
|
expo = Expedition.objects.get(year=int(expeditionname))
|
||||||
|
except:
|
||||||
|
message = f'Expedition not found - database apparently empty, you probably need to do a full re-import of all data.'
|
||||||
|
return render(request, 'errors/generic.html', {'message': message})
|
||||||
|
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
if "reload" in request.GET:
|
|
||||||
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
|
||||||
# Need to delete the existing entries or we get duplication
|
|
||||||
# Need to delete both in the Django ORM and in our own object-store.
|
|
||||||
entries = this_expedition.logbookentry_set.all()
|
|
||||||
for entry in entries:
|
|
||||||
#print(f'! - delete entry: "{entry}"')
|
|
||||||
entry.delete()
|
|
||||||
entries = this_expedition.logbookentry_set.all()
|
|
||||||
import_logbook(year=this_expedition.year)
|
|
||||||
logged_in = True
|
logged_in = True
|
||||||
|
if "reload" in request.GET:
|
||||||
|
expo.logbookentry_set.all().delete()
|
||||||
|
import_logbook(year=expo.year)
|
||||||
else:
|
else:
|
||||||
logged_in = False
|
logged_in = False
|
||||||
|
|
||||||
|
|
||||||
ts = TROG['pagecache']['expedition'] # not much use unless single user!
|
ts = TROG['pagecache']['expedition'] # not much use unless single user!
|
||||||
if settings.CACHEDPAGES:
|
if settings.CACHEDPAGES:
|
||||||
@ -83,33 +93,41 @@ def expedition(request, expeditionname):
|
|||||||
#print('! - expo {expeditionanme} using cached page')
|
#print('! - expo {expeditionanme} using cached page')
|
||||||
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in })
|
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in })
|
||||||
|
|
||||||
try:
|
expeditions = Expedition.objects.all() # top menu only, evaluated only when template renders
|
||||||
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
|
||||||
except:
|
entries = expo.logbookentry_set.all()
|
||||||
message = f'Expedition not found - database apparently empty, you probably need to do a full re-import of all data.'
|
blocks = expo.survexblock_set.all()
|
||||||
return render(request, 'errors/generic.html', {'message': message})
|
dateditems = list(entries) + list(blocks) # evaluates the Django query and hits db
|
||||||
|
|
||||||
expeditions = Expedition.objects.all()
|
|
||||||
personexpeditiondays = [ ]
|
|
||||||
dateditems = list(this_expedition.logbookentry_set.all()) + list(this_expedition.survexblock_set.all())
|
|
||||||
dates = sorted(set([item.date for item in dateditems]))
|
dates = sorted(set([item.date for item in dateditems]))
|
||||||
for personexpedition in this_expedition.personexpedition_set.all():
|
|
||||||
|
allpersontrips = PersonTrip.objects.filter(personexpedition__expedition=expo)
|
||||||
|
|
||||||
|
|
||||||
|
personexpeditiondays = [ ]
|
||||||
|
for personexpedition in expo.personexpedition_set.all():
|
||||||
|
expotrips = allpersontrips.filter(personexpedition=personexpedition) # lazy
|
||||||
|
expoblocks = blocks.filter(survexpersonrole__personexpedition=personexpedition)
|
||||||
|
|
||||||
prow = [ ]
|
prow = [ ]
|
||||||
|
|
||||||
for date in dates:
|
for date in dates:
|
||||||
pcell = { "persontrips": PersonTrip.objects.filter(personexpedition=personexpedition,
|
personentries = expotrips.filter(logbook_entry__date=date) # lazy
|
||||||
logbook_entry__date=date) }
|
personblocks = set(expoblocks.filter(date = date)) # not lazy
|
||||||
pcell["survexblocks"] = set(SurvexBlock.objects.filter(survexpersonrole__personexpedition=personexpedition,
|
pcell = {}
|
||||||
date = date))
|
pcell["personentries"] = personentries
|
||||||
|
pcell["survexblocks"] = personblocks
|
||||||
|
if issunday := (date.weekday() == 6): # WALRUS
|
||||||
|
pcell["sunday"] = issunday
|
||||||
prow.append(pcell)
|
prow.append(pcell)
|
||||||
personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow})
|
personexpeditiondays.append({"personexpedition":personexpedition, "personrow":prow})
|
||||||
|
|
||||||
|
|
||||||
ts[expeditionname] = {'expedition': this_expedition, 'expeditions':expeditions,
|
ts[expeditionname] = {'expedition': expo,
|
||||||
|
'expeditions':expeditions,
|
||||||
'personexpeditiondays':personexpeditiondays, 'settings':settings,
|
'personexpeditiondays':personexpeditiondays, 'settings':settings,
|
||||||
'dateditems': dateditems, 'dates':dates}
|
'dateditems': dateditems, 'dates':dates}
|
||||||
TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname]
|
TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname]
|
||||||
nexpos = len( TROG['pagecache']['expedition'])
|
|
||||||
#print(f'! - expo {expeditionname} pre-render N expos:{nexpos}')
|
|
||||||
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in } )
|
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in } )
|
||||||
|
|
||||||
class Expeditions_tsvListView(ListView):
|
class Expeditions_tsvListView(ListView):
|
||||||
|
@ -55,12 +55,19 @@ table.expeditionpersonlist td.persondayactivity
|
|||||||
width:4em;
|
width:4em;
|
||||||
font-size:70%;
|
font-size:70%;
|
||||||
padding:0 0 0 0;
|
padding:0 0 0 0;
|
||||||
|
background-color:#ddd;
|
||||||
}
|
}
|
||||||
|
|
||||||
table.expeditionpersonlist td.persondayactivity-nothing
|
table.expeditionpersonlist td.persondayactivity-nothing
|
||||||
{
|
{
|
||||||
background-color:#bbb;
|
background-color:#bbb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.expeditionpersonlist td.persondayactivity-sunday
|
||||||
|
{
|
||||||
|
background-color:#aad;
|
||||||
|
}
|
||||||
|
|
||||||
table.expeditionpersonlist a
|
table.expeditionpersonlist a
|
||||||
{
|
{
|
||||||
text-decoration:none;
|
text-decoration:none;
|
||||||
|
@ -60,7 +60,9 @@ def stash_data_issue(parser=None, message=None, url=None, sb=None):
|
|||||||
dataissues.append((parser, message, url, sb))
|
dataissues.append((parser, message, url, sb))
|
||||||
|
|
||||||
def store_data_issues():
|
def store_data_issues():
|
||||||
"""Take the stash and store it permanently in the database instead"""
|
"""Take the stash and store it permanently in the database instead
|
||||||
|
|
||||||
|
use BULK creation here !"""
|
||||||
global dataissues
|
global dataissues
|
||||||
print(f" - Storing {len(dataissues)} Data Issues into database")
|
print(f" - Storing {len(dataissues)} Data Issues into database")
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<p><b>At a single glance:</b> The table shows all expo cavers and their recorded trips.
|
<p><b>At a single glance:</b> The table shows all expo cavers and their recorded trips.
|
||||||
The columns are the date in the month (July or August), with a
|
The columns are the date in the month (July, August or September), Sundays in blue, with a
|
||||||
"<b>T</b>" for a logbook entry, and
|
"<b>T</b>" for a logbook entry, and
|
||||||
an "<b>S</b>" for a survey trip. The colours are the same for people on the same trip. </p>
|
an "<b>S</b>" for a survey trip. The colours of the "<b>T</b>" and "<b>S</b>" are the same for people on the same trip. </p>
|
||||||
<!-- Colours are set in trog3.css and there can be 3 trips a day of each type-->
|
<!-- Colours are set in trog3.css and there can be 10 trips a day of each type-->
|
||||||
|
|
||||||
<table class="expeditionpersonlist">
|
<table class="expeditionpersonlist">
|
||||||
<tr>
|
<tr>
|
||||||
@ -44,21 +44,25 @@ an "<b>S</b>" for a survey trip. The colours are the same for people on the sam
|
|||||||
{% for personexpeditionday in personexpeditiondays %}
|
{% for personexpeditionday in personexpeditiondays %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="{{ personexpeditionday.personexpedition.get_absolute_url }}">{{personexpeditionday.personexpedition.person|safe}}</a></td>
|
<td><a href="{{ personexpeditionday.personexpedition.get_absolute_url }}">{{personexpeditionday.personexpedition.person|safe}}</a></td>
|
||||||
{% for persondayactivities in personexpeditionday.personrow %}
|
{% for activities in personexpeditionday.personrow %}
|
||||||
|
|
||||||
{% if persondayactivities.persontrips or persondayactivities.survexblocks %}
|
{% if activities.personentries or activities.survexblocks %}
|
||||||
<td class="persondayactivity">
|
<td class="persondayactivity">
|
||||||
{% for persontrip in persondayactivities.persontrips %}
|
{% for personentry in activities.personentries %}
|
||||||
<a href="{{persontrip.logbook_entry.get_absolute_url}}" class="dayindexlog-{{persontrip.logbook_entry.DayIndex}}">T</a>
|
<a href="{{personentry.logbook_entry.get_absolute_url}}" class="dayindexlog-{{personentry.logbook_entry.DayIndex}}">T</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<br/>
|
<br/>
|
||||||
{% for survexblock in persondayactivities.survexblocks %}
|
{% for survexblock in activities.survexblocks %}
|
||||||
<a href="{% url "svx" survexblock.survexfile.path %}" class="dayindexsurvex-{{survexblock.DayIndex}}">S</a>
|
<a href="{% url "svx" survexblock.survexfile.path %}" class="dayindexsurvex-{{survexblock.DayIndex}}">S</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td class="persondayactivity-nothing">
|
{% if activities.sunday %}
|
||||||
</td>
|
<td class="persondayactivity-sunday">
|
||||||
|
{% else %}
|
||||||
|
<td class="persondayactivity-nothing">
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
Loading…
Reference in New Issue
Block a user