2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 16:17:09 +00:00

chipping away bug in personexpedition, remove role

This commit is contained in:
Philip Sargent
2021-04-30 00:24:36 +01:00
parent e5cf1b5289
commit 03a5f5989e
9 changed files with 82 additions and 34 deletions

View File

@@ -58,6 +58,19 @@ class FixtureTests(TestCase):
self.assertIsNotNone(phmatch, "In fixture-loaded cave, failed to find expected text: '" + ph +"'")
def test_page_personexpedition(self):
response = self.client.get('/personexpedition/MichaelSargent/2019')
content = response.content.decode()
# with open('testresponse.html','w') as tr:
# tr.writelines(content)
self.assertEqual(response.status_code, 200)
for ph in [ r'Michael Sargent',
r'Table of all trips and surveys aligned by date' ]:
phmatch = re.search(ph, content)
self.assertIsNotNone(phmatch, "Failed to find expected text: '" + ph +"'")
# Need to add a fixture so that this actually has a logbook entry and a trip/svx in it.
class FixturePageTests(TestCase):
'''Currently nothing that runs troggle works - all do 404. Must be something in a template rendering crash?
ordinary pages are OK, and expopages and expofiles are OK, even though they come through troggle.

View File

@@ -432,6 +432,10 @@ class LogbookEntry(TroggleModel):
# #return super(LogbookEntry, self).__init__(*args, **kwargs) # works in py3.5
# #return TroggleModel.__init__(*args, **kwargs) # fails in py3.5, runtime fail in 3.8
def cave(self): # Why didn't he just make this a foreign key to Cave ? Replaces __egtattrribute__ sillyness.
c = CaveSlug.objects.get(slug=self.cave_slug, primary=True).cave
return c
def isLogbookEntry(self): # Function used in templates
return True

View File

@@ -134,12 +134,18 @@ class SurvexBlock(models.Model):
return True
def GetPersonroles(self):
'''To do: excise the 'role' bit of this while retaining personrole
which is used in some later logic
But apparently never used !?
'''
res = [ ]
for personrole in self.survexpersonrole_set.order_by('personexpedition'):
if res and res[-1]['person'] == personrole.personexpedition.person:
res[-1]['roles'] += ", " + str(personrole.nrole)
else:
res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year, 'roles':str(personrole.nrole)})
# if res and res[-1]['person'] == personrole.personexpedition.person:
# res[-1]['roles'] += ", " + str(personrole.nrole)
# else:
# res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year, 'roles':str(personrole.nrole)})
res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year})
return res
def DayIndex(self):
@@ -147,21 +153,21 @@ class SurvexBlock(models.Model):
#
# member of a SurvexBlock
#
ROLE_CHOICES = (
('insts','Instruments'),
('dog','Other'),
('notes','Notes'),
('pics','Pictures'),
('tape','Tape measure'),
('useless','Useless'),
('helper','Helper'),
('disto','Disto'),
('consultant','Consultant'),
)
# ROLE_CHOICES = (
# ('insts','Instruments'),
# ('dog','Other'),
# ('notes','Notes'),
# ('pics','Pictures'),
# ('tape','Tape measure'),
# ('useless','Useless'),
# ('helper','Helper'),
# ('disto','Disto'),
# ('consultant','Consultant'),
# )
class SurvexPersonRole(models.Model):
survexblock = models.ForeignKey('SurvexBlock',on_delete=models.CASCADE)
nrole = models.CharField(choices=ROLE_CHOICES, max_length=200, blank=True, null=True)
# nrole = models.CharField(choices=ROLE_CHOICES, max_length=200, blank=True, null=True)
# increasing levels of precision
personname = models.CharField(max_length=100)
person = models.ForeignKey('Person', blank=True, null=True,on_delete=models.SET_NULL)

View File

@@ -184,12 +184,19 @@ class PersonExpedition(TroggleModel):
nickname = models.CharField(max_length=100,blank=True, null=True)
def GetPersonroles(self):
'''To do: excise the 'role' bit of this while retaining personrole
which is used in some later logic
But apparently never used !?
'''
res = [ ]
for personrole in self.personrole_set.order_by('survexblock'):
if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
res[-1]['roles'] += ", " + str(personrole.role)
else:
res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath})
# if res and res[-1]['survexpath'] == personrole.survexblock.survexpath:
# res[-1]['roles'] += ", " + str(personrole.role)
# else:
# res.append({'date':personrole.survexblock.date, 'survexpath':personrole.survexblock.survexpath, 'roles':str(personrole.role)})
return res
class Meta:

View File

@@ -141,8 +141,11 @@ def person(request, first_name='', last_name='', ):
def get_person_chronology(personexpedition):
'''Horrible bug here whern there is more than one survex block per day, it duplicates the entry but gets it wrong
'''Horrible bug here when there is more than one survex block per day, it duplicates the entry but gets it wrong
Fortunately this is just the display on this page which is wroing, no bad calculations get into the database.
This is just a nasty convoluted way of trying the make the template do more work than it is sensible to ask it to do.
Rewrite more simply with the login in the python, not in Django template language (you bastard Curtis).
'''
res = { }
for persontrip in personexpedition.persontrip_set.all():
@@ -171,6 +174,8 @@ def personexpedition(request, first_name='', last_name='', year=''):
this_expedition = Expedition.objects.get(year=year)
personexpedition = person.personexpedition_set.get(expedition=this_expedition)
personchronology = get_person_chronology(personexpedition)
#for pc in personchronology:
#print(pc)
return render(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology})