diff --git a/core/models/troggle.py b/core/models/troggle.py index 84f1bc3..947ba21 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -122,6 +122,7 @@ class Person(TroggleModel): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) fullname = models.CharField(max_length=200) + nickname = models.CharField(max_length=200) is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False) mug_shot = models.CharField(max_length=100, blank=True,null=True) blurb = models.TextField(blank=True,null=True) @@ -170,7 +171,7 @@ class PersonExpedition(TroggleModel): """ expedition = models.ForeignKey(Expedition,on_delete=models.CASCADE) person = models.ForeignKey(Person,on_delete=models.CASCADE) - slugfield = models.SlugField(max_length=50,blank=True, null=True) + slugfield = models.SlugField(max_length=50,blank=True, null=True) # 2022 to be used in future is_guest = models.BooleanField(default=False) COMMITTEE_CHOICES = ( diff --git a/core/views/statistics.py b/core/views/statistics.py index 15858d3..2e6684f 100644 --- a/core/views/statistics.py +++ b/core/views/statistics.py @@ -14,6 +14,7 @@ from django.utils import timezone from troggle.core.models.troggle import Expedition, Person, PersonExpedition, DataIssue from troggle.core.models.caves import Cave, LogbookEntry, Entrance from troggle.core.models.survex import SurvexBlock, SurvexStation +from troggle.parsers.people import GetPersonExpeditionNameLookup import troggle.settings as settings @@ -170,3 +171,16 @@ def eastings(request): stations = SurvexStation.objects.all() return render(request,'eastings.html', {'ents': ents, 'stations': stations}) + +def aliases(request, year): + '''Page which displays a list of all the person aliases in a specific year + ''' + if not year: + year = 1998 + expo = Expedition.objects.filter(year=year)[0] # returns a set, even though we know there is only one + personexpeditions = PersonExpedition.objects.filter(expedition=expo) + persons = Person.objects.all() + + aliasdict = GetPersonExpeditionNameLookup(expo) + + return render(request,'aliases.html', {'year': year, 'aliasdict': aliasdict,'personexpeditions': personexpeditions, 'persons': persons}) diff --git a/parsers/people.py b/parsers/people.py index cc061ef..12fba14 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -112,7 +112,7 @@ def load_people_expos(): vfho = True lookupAttribs={'first_name':firstname, 'last_name':(lastname or "")} - nonLookupAttribs={'is_vfho':vfho, 'fullname':fullname} + nonLookupAttribs={'is_vfho':vfho, 'fullname':fullname, 'nickname':nickname} person, created = save_carefully(Person, lookupAttribs, nonLookupAttribs) parse_blurb(personline=personline, header=header, person=person) @@ -131,6 +131,14 @@ def load_people_expos(): # expedition name lookup cached for speed (it's a very big list) # should have a LIST of nicknames, just populate the first entry from folk.csv +def who_is_this(year,possibleid): + expo = Expedition.objects.filter(year=year) + personexpedition = GetPersonExpeditionNameLookup(expo)[possibleid.lower()] + if personexpedition: + return personexpedition.person + else: + return None + # Refactor. The dict GetPersonExpeditionNameLookup(expo) indexes by name and has values of personexpedition # This is convoluted, the whole personexpedition concept is unnecessary. @@ -161,6 +169,19 @@ def GetPersonExpeditionNameLookup(expedition): possnames.append(f[0] + l[0]) # initials e.g. gb or bl possnames.append(f) + # But these aliases do not take advantage of the variations above + if f'{f} {l}' == "Phil Underwood": + possnames.append("Phil Underpants") + if f'{f} {l}' == "Naomi Griffiths": + possnames.append("Naomi Makin") + if f'{f} {l}' == "Cat Hulse": + possnames.append("Catherine Hulse") + possnames.append("Cat Henry") + if f'{f} {l}' == "Jess Stirrups": + possnames.append("Jessica Stirrups") + if f'{f} {l}' == "Nat Dalton": + possnames.append("Nathaniel Dalton") + lim = min(4, len(f)+1) # short form, e.g. Dan for Daniel. May be duplicate, e.g. several Dave if f[:lim] not in short: short[f[:lim]]= personexpedition @@ -173,12 +194,13 @@ def GetPersonExpeditionNameLookup(expedition): if l: # This allows for nickname to be used for short name # eg Phil S is adding Phil Sargent to the list - if str(personexpedition.nickname.lower() + " " + l) not in possnames: - possnames.append(personexpedition.nickname.lower() + " " + l) - if str(personexpedition.nickname.lower() + " " + l[0]) not in possnames: - possnames.append(personexpedition.nickname.lower() + " " + l[0]) - if str(personexpedition.nickname.lower() + l[0]) not in possnames: - possnames.append(personexpedition.nickname.lower() + l[0]) + n = personexpedition.nickname.lower() + if str(n + " " + l) not in possnames: + possnames.append(n + " " + l) + if str(n + " " + l[0]) not in possnames: + possnames.append(n + " " + l[0]) + if str(n + l[0]) not in possnames: + possnames.append(n + l[0]) for possname in possnames: if possname in res: @@ -195,6 +217,10 @@ def GetPersonExpeditionNameLookup(expedition): for shortname in short: res[shortname] = short[shortname] + print(f'{expedition.name}', end= ' ') + for n in res: + print(f'{n},', end= ' ') + print('') Gpersonexpeditionnamelookup[expedition.name] = res return res diff --git a/templates/aliases.html b/templates/aliases.html new file mode 100644 index 0000000..30b4443 --- /dev/null +++ b/templates/aliases.html @@ -0,0 +1,47 @@ +{% extends "base.html" %} +{% block title %}Cave Entrances and other locations in UTM{% endblock %} + +{% block content %} + +

Aliases for people's names in {{year}}

+ + + + +{% for pe in personexpeditions %} + + + + + +{% endfor %} +
Personslugaliases
{{pe.person}}{{pe.slugfield}}{{pe.slugfield}}
+ + + +{% for key, value in aliasdict.items %} + + + + +{% endfor %} +
aliaswho
'{{key}}'{{value}}
+

The aliases below are specified in the folk.csv file. Only one alias is possible in that format. + + +{% for p in persons %} + + + + + + + + + +{% endfor %} +
FirstLastFull nameNicknameexpo firstexpo last
{{p.first_name}}{{p.last_name}}{{p.fullname}}{{p.nickname}}{{p.first.expedition}}{{p.last.expedition}}
+ + + +{% endblock %} \ No newline at end of file diff --git a/urls.py b/urls.py index f46c3c7..59e0bf9 100644 --- a/urls.py +++ b/urls.py @@ -145,11 +145,12 @@ trogglepatterns = [ # System admin and monitoring - path('statistics', statistics.stats, name="stats"), - path('stats', statistics.stats, name="stats"), - path('pathsreport', statistics.pathsreport, name="pathsreport"), - path('dataissues', statistics.dataissues, name="dataissues"), - path('eastings', statistics.eastings, name="eastings"), + path('statistics', statistics.stats, name="stats"), + path('stats', statistics.stats, name="stats"), + path('pathsreport', statistics.pathsreport, name="pathsreport"), + path('dataissues', statistics.dataissues, name="dataissues"), + path('eastings', statistics.eastings, name="eastings"), + path('aliases/',statistics.aliases, name="aliases"), path('troggle', frontpage, name="frontpage"), # control panel. Shows recent actions. path('todo/', todos, name="todos"),