Adding docstrings, deleting unused code

This commit is contained in:
Philip Sargent 2022-12-23 23:32:59 +00:00
parent 0e29cdd48c
commit 5bbb363f12
4 changed files with 32 additions and 39 deletions

View File

@ -5,7 +5,7 @@
{"model": "core.personexpedition", "pk": 681, "fields":
{"new_since_parsing": false, "non_public": false,
"expedition": 44,
"person": 250, "slugfield": null, "is_guest": false, "expo_committee_position": null,
"person": 250, "slugfield": null, "is_guest": false,
"nickname": "Mike"}},
{"model": "core.person", "pk": 250, "fields":

View File

@ -109,6 +109,8 @@ class SurvexBlockLookUpManager(models.Manager):
return block
class SurvexBlock(models.Model):
"""One begin..end block within a survex file. The basic elemt of a survey trip.
"""
objects = SurvexBlockLookUpManager()
name = models.CharField(max_length=100)
title = models.CharField(max_length=200)
@ -141,15 +143,6 @@ class SurvexBlock(models.Model):
def isSurvexBlock(self): # Function used in templates
return True
def GetPersonroles(self):
'''
But apparently never used !?
'''
res = [ ]
for personrole in self.survexpersonrole_set.order_by('personexpedition'):
res.append({'person':personrole.personexpedition.person, 'expeditionyear':personrole.personexpedition.expedition.year})
return res
def DayIndex(self):
return list(self.expeditionday.survexblock_set.all()).index(self)
@ -181,6 +174,8 @@ class Wallet(models.Model):
return urljoin(settings.URL_ROOT, reverse('singlewallet', kwargs={"path":re.sub("#", "%23", self.walletname)}))
def get_json(self):
"""Read the JSON file for the wallet and do stuff
"""
#jsonfile = Path(self.fpath, 'contents.json')
# Get from git repo instead
@ -246,6 +241,8 @@ class Wallet(models.Model):
# Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it
def date(self):
"""Reads all the JSON data just to get the JSNON date.
"""
if self.walletdate:
return self.walletdate
if not self.get_json():
@ -319,6 +316,8 @@ class Wallet(models.Model):
return result
def get_ticks(self):
"""Reads all the JSON data and sets the colour of the completion tick for each condition
"""
ticks = {}
waldata = self.get_json()
if not waldata:
@ -438,6 +437,8 @@ class Wallet(models.Model):
return "[" + str(self.walletname) + " (Wallet)]"
class SingleScan(models.Model):
"""A single file holding an image. Could be raw notes, an elevation plot or whatever
"""
ffile = models.CharField(max_length=200)
name = models.CharField(max_length=200)
wallet = models.ForeignKey("Wallet", null=True,on_delete=models.SET_NULL)
@ -449,9 +450,11 @@ class SingleScan(models.Model):
return urljoin(settings.URL_ROOT, reverse('scansingle', kwargs={"path":re.sub("#", "%23", self.wallet.walletname), "file":self.name}))
def __str__(self):
return "Survey Scan Image: " + str(self.name) + " in " + str(self.wallet)
return "Scan Image: " + str(self.name) + " in " + str(self.wallet)
class DrawingFile(models.Model):
"""A file holding a Therion (several types) or a Tunnel drawing
"""
dwgpath = models.CharField(max_length=200)
dwgname = models.CharField(max_length=200)
dwgwallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files

View File

@ -30,9 +30,9 @@ the django Object Relational Mapping (ORM).
There are more subclasses define in models_caves.py models_survex.py etc.
"""
#This class is for adding fields and methods which all of our models will have.
class TroggleModel(models.Model):
"""This class is for adding fields and methods which all of our models will have.
"""
new_since_parsing = models.BooleanField(default=False, editable=False)
non_public = models.BooleanField(default=False)
def object_name(self):
@ -98,14 +98,20 @@ class Expedition(TroggleModel):
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):
"""Exists only so that we can get all logbook trips on this day
"""
expedition = models.ForeignKey("Expedition",on_delete=models.CASCADE)
date = models.DateField()
@ -113,6 +119,8 @@ class ExpeditionDay(TroggleModel):
ordering = ('date',)
def GetPersonTrip(self, personexpedition):
"""returns all logbook trips for this expediton
"""
personexpeditions = self.persontrip_set.filter(expeditionday=self)
return personexpeditions and personexpeditions[0] or None
@ -144,6 +152,8 @@ class Person(TroggleModel):
def notability(self):
"""This is actually recency: all recent cavers, weighted by number of expos
"""
notability = Decimal(0)
max_expo_val = 0
@ -156,6 +166,8 @@ class Person(TroggleModel):
return notability
def bisnotable(self):
"""Boolean: is this person notable?
"""
return self.notability() > Decimal(1)/Decimal(3)
def surveyedleglength(self):
@ -174,31 +186,7 @@ class PersonExpedition(TroggleModel):
slugfield = models.SlugField(max_length=50,blank=True, null=True) # 2022 to be used in future
is_guest = models.BooleanField(default=False)
COMMITTEE_CHOICES = (
('leader','Expo leader'),
('medical','Expo medical officer'),
('treasurer','Expo treasurer'),
('sponsorship','Expo sponsorship coordinator'),
('research','Expo research coordinator'),
)
expo_committee_position = models.CharField(blank=True,null=True,choices=COMMITTEE_CHOICES,max_length=200)
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'):
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:
ordering = ('-expedition',)
@ -219,6 +207,8 @@ class PersonExpedition(TroggleModel):
return urljoin(settings.URL_ROOT, reverse('personexpedition',kwargs={'first_name':self.person.first_name,'last_name':self.person.last_name,'year':self.expedition.year}))
def surveyedleglength(self):
"""Survey length for this person on all survex trips on this expedition
"""
survexblocks = [personrole.survexblock for personrole in self.survexpersonrole_set.all() ]
return sum([survexblock.legslength for survexblock in set(survexblocks)])

View File

@ -66,8 +66,8 @@ LOGBOOK_PARSER_SETTINGS = {
"1997": ("log.htm", "parser_html_01"),
"1996": ("log.htm", "parser_html_01"),
"1995": ("log.htm", "parser_html_01"),
"1994": ("log.htm", "parser_html_01"),
"1993": ("log.htm", "parser_html_01"),
"1994": ("logbook.html", "parser_html"),
"1993": ("logbook.html", "parser_html"),
"1992": ("logbook.html", "parser_html"),
"1991": ("logbook.html", "parser_html"),
"1990": ("logbook.html", "parser_html"),