From 03a5f5989e74ba50ff63ba599f98cd36dc0fa5d0 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 30 Apr 2021 00:24:36 +0100 Subject: [PATCH] chipping away bug in personexpedition, remove role --- core/TESTS/tests_caves.py | 13 +++++++++++ core/models/caves.py | 4 ++++ core/models/survex.py | 38 +++++++++++++++++++-------------- core/models/troggle.py | 15 +++++++++---- core/views/logbooks.py | 7 +++++- parsers/survex.py | 8 ++++++- templates/manywallets.html | 2 -- templates/personexpedition.html | 27 +++++++++++++++-------- urls.py | 2 +- 9 files changed, 82 insertions(+), 34 deletions(-) diff --git a/core/TESTS/tests_caves.py b/core/TESTS/tests_caves.py index 0ff0f12..8a08c71 100644 --- a/core/TESTS/tests_caves.py +++ b/core/TESTS/tests_caves.py @@ -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. diff --git a/core/models/caves.py b/core/models/caves.py index b3b3a59..259854d 100644 --- a/core/models/caves.py +++ b/core/models/caves.py @@ -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 diff --git a/core/models/survex.py b/core/models/survex.py index b30f231..9d2b17e 100644 --- a/core/models/survex.py +++ b/core/models/survex.py @@ -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) diff --git a/core/models/troggle.py b/core/models/troggle.py index 10c982c..f9558ff 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -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: diff --git a/core/views/logbooks.py b/core/views/logbooks.py index 82dbf61..3181a33 100644 --- a/core/views/logbooks.py +++ b/core/views/logbooks.py @@ -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}) diff --git a/parsers/survex.py b/parsers/survex.py index ea1e061..569a4b4 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -26,6 +26,11 @@ It does also NOT scan the Loser repo for all the svx files - though it should ! todo = '''Also walk the entire tree in the :loser: repo looking for unconnected survex files - add them to the system so that they can be reported-on - produce a parser report and create a troggle report page (some are OK, e.g. futility series replaced by ARGE survey in 115) + +- If you look at e.g. http://expo.survex.com/survexfile/161#T_caves-1623/161/lhr/alllhr + you will see than have the team members are recognised by this parser, but not recognised by the + wider troggle system (the name is not a hyperlink) - apparently randomly. + GetPersonExpeditionNameLookup() needs to be fixed. ''' survexblockroot = None ROOTBLOCK = "rootblock" @@ -201,7 +206,8 @@ class LoadingSurvex(): personexpedition = survexblock.expedition and GetPersonExpeditionNameLookup(survexblock.expedition).get(tm.lower()) if (personexpedition, tm) not in teammembers: teammembers.append((personexpedition, tm)) - personrole = SurvexPersonRole(survexblock=survexblock, nrole=mteammember.group(1).lower(), personexpedition=personexpedition, personname=tm) + personrole = SurvexPersonRole(survexblock=survexblock, personexpedition=personexpedition, personname=tm) +# personrole = SurvexPersonRole(survexblock=survexblock, nrole=mteammember.group(1).lower(), personexpedition=personexpedition, personname=tm) personrole.save() personrole.expeditionday = survexblock.expeditionday if personexpedition: diff --git a/templates/manywallets.html b/templates/manywallets.html index d841398..4c08c51 100644 --- a/templates/manywallets.html +++ b/templates/manywallets.html @@ -1,7 +1,5 @@ {% extends "base.html" %} -{% load survex_markup %} - {% block title %}All Survey scans folders (wallets){% endblock %} {% block content %} diff --git a/templates/personexpedition.html b/templates/personexpedition.html index fd52fe1..323a30f 100644 --- a/templates/personexpedition.html +++ b/templates/personexpedition.html @@ -1,7 +1,11 @@ {% extends "base.html" %} {% load wiki_markup %} {% block title %}Person {{personexpedition.person|wiki_to_html_short}} for {{personexpedition.expedition}}{% endblock %} - + {% block content %}

@@ -25,25 +29,28 @@

Table of all trips and surveys aligned by date

- + + {% for persondate in personchronology %} {% if persondate.1 %} - + {% else %} {% endif %} {% if persondate.2 %} - + {%comment%} + {%endcomment%} @@ -60,7 +67,9 @@ e.g. see Wookey 1999 where there are 3 eiscream survex blocks on 5th August. it duplicates the entry but gets it wrong. The length from the first block is displayed twice but there should be 3 rows: eiscream, eiscream2, eiscream3.

Fortunately it is just this display on this page which is wrong: no bad calculations get into the database. -

The interaction of django database query idioms with django HTML templating language is a bit impenetrable here.
+

The interaction of django database query idioms with django HTML templating language is a bit impenetrable here. +I blame Aaron Curtis who was too fond of being clever with the Django templating system +instead or writing it in python anyone could understand.
- The template is in troggle/templates/personexpedition.html
- The code is in function personexpedition() which calls diff --git a/urls.py b/urls.py index 351c4ae..14aa34a 100644 --- a/urls.py +++ b/urls.py @@ -172,7 +172,7 @@ trogglepatterns = [ re_path(r'^photos/(?P.*)$', mediapage, {'doc_root': settings.PHOTOS_ROOT}, name="mediapage"), # photo galleries re_path(r'^site_media/(?P.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # MEDIA_ROOT: CSS and JS re_path(r'^static/(?P.*)$', mediapage, {'doc_root': settings.MEDIA_ROOT}, name="mediapage"), # STATIC is in MEDIA now! - re_path(r'^javascript/(?P.*)$', mediapage, {'doc_root': settings.JSLIB_ROOT}, name="mediapage"), # JSLIB_URL + path('javascript/', mediapage, {'doc_root': settings.JSLIB_ROOT}, name="mediapage"), # JSLIB_URL re_path(r'^expowebcache/3d/(?P.*)$', mediapage, {'doc_root': settings.THREEDCACHEDIR}, name="mediapage"), re_path(r'^/loser/(?P.*)$', mediapage, {'doc_root': settings.SURVEX_DATA}, name="mediapage"), # Oddly not working !?

DateTripsSurveys
DateTripsSurveys
{{persondate.0}}{{persondate.1.logbook_entry.title|safe}}{{persondate.1.place|safe}} {{persondate.1.logbook_entry.place|safe}} {{persondate.2.name}} - {% for survexpersonrole in persondate.2.survexpersonrole_set.all %} - {{survexpersonrole.nrole}} - {% endfor %} - + {% for survexpersonrole in persondate.2.survexpersonrole_set.all %} + {{survexpersonrole.nrole}} + {% endfor %} + {{persondate.2.legslength|stringformat:".1f"}} m