new slug-based identifiers

This commit is contained in:
Philip Sargent 2023-10-01 16:21:23 +03:00
parent 9458aad028
commit 99566fe519

View File

@ -8,6 +8,8 @@ from datetime import date
# re-run it every time you edit the folk.csv file to add someone you have forgotten
# it needs to be run on the server too as the file produced is ignored by git
# updated to use slugs to recognise people instead of FirstnameSurname
headcount = 0
pics = 0
allyears = 0
@ -20,6 +22,19 @@ headcounts_byyear = [0]*(len(lines[0].split(","))-5)
yearnow = date.today().year
slug_cache = {}
def troggle_slugify(longname):
"""Uniqueness enforcement too. Yes we have had two "Dave Johnson"s
This function copied instact from troggle/parsers/people/py
"""
slug = longname.strip().lower().replace(" ","-")
if len(slug) > 40: # slugfield is 50 chars
slug = slug[:40]
if slug in slug_cache:
slug_cache[slug] += 1
slug = f"{slug}_{slug_cache[slug]}"
slug_cache[slug] = 1
return slug
for r in lines[1:]:
n +=1
@ -52,6 +67,10 @@ for r in lines[1:]:
nameurl = nameurl.replace(';', '%3B')
nameurl = re.sub('<[^>]*>','',nameurl)
nameurl = re.sub('\([^\)]*\)','',nameurl) # mostly not needed, but is for Wookey
# new url using slug
nameurl = re.sub('\([^\)]*\)','',name)
nameurl = troggle_slugify(nameurl)
namelink= "<a href='/person/" + nameurl + "'>" + namevis + "</a>"
output += namelink
#output += name.replace('""', '"')