mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
First attempts at reforming the FirstnameSurname parsing
This commit is contained in:
parent
a67a97b9fc
commit
904b6309cf
@ -1,3 +1,5 @@
|
||||
import re
|
||||
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import render
|
||||
from django.views.generic.list import ListView
|
||||
@ -151,6 +153,35 @@ class QMs_jsonListView(ListView):
|
||||
template_name = "core/QMs_json_list.html"
|
||||
model = QM
|
||||
|
||||
rx_person = re.compile(r"(?i)^(([A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*)([a-z\-\']*[^a-zA-Z]*[\-]*[A-Z]*[a-zA-Z\-&;]*)$")
|
||||
rx_simple_person = re.compile(r"^([A-Z][a-z]*)[ ]*([A-Z][a-z]*)$")
|
||||
|
||||
def better_person(request, name=""):
|
||||
"""Attempting to replace the name parser in urls.py with a more complex but
|
||||
more understandable one in the body of the code.
|
||||
Unfortuantely the get_absolute_url Django funny is making life very difficult.
|
||||
This is in models/troggle.py PersonExpedition and Person
|
||||
We need a defined slug for a person, however complicated their name, before we can progress further, if we
|
||||
insist on using get_absolute_url().
|
||||
|
||||
Probably simpler and clearer to maintainers NOT to use ANY get_absolute_url() in the templates.
|
||||
"""
|
||||
names = rx_simple_person.match(name.strip(" /"))
|
||||
if names:
|
||||
first_name = names.group(1)
|
||||
last_name = names.group(2)
|
||||
else:
|
||||
message = f"Name not recognised '{name}' - possibly French? (See our <a href=\"/handbook/troggle/namesredesign.html\">Proposal to fix this</a>)"
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
try:
|
||||
this_person = Person.objects.get(first_name=first_name, last_name=last_name)
|
||||
except:
|
||||
message = f"Person not found {name} => '{first_name} {last_name}' - possibly Scottish? (See our <a href=\"/handbook/troggle/namesredesign.html\">Proposal to fix this</a>)"
|
||||
return render(request, "errors/generic.html", {"message": message})
|
||||
|
||||
return render(request, "person.html", {"person": this_person})
|
||||
|
||||
def person(
|
||||
request,
|
||||
first_name="",
|
||||
|
3
urls.py
3
urls.py
@ -121,7 +121,8 @@ trogglepatterns = [
|
||||
path('accounts/login/', expologin, name='expologin'), # same as in django.contrib.auth.urls
|
||||
#re_path(r'^accounts/', include('django.contrib.auth.urls')), # see site-packages\registration\auth_urls_classes.py
|
||||
|
||||
# Persons - nasty surname recognition logic fails for 19 people!
|
||||
# Persons - nasty surname recognition logic fails for 19 people! See also Wallets by person below.
|
||||
# path('person/<str:name>', person, name="person"), # This is much more complex than it looks..
|
||||
re_path(r'^person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[\-]*[A-Z]*[a-zA-Z\-&;]*)/?', person, name="person"),
|
||||
re_path(r'^personexpedition/(?P<first_name>[A-Z]*[a-z&;]*)[^a-zA-Z]*(?P<last_name>[A-Z]*[a-zA-Z&;]*)/(?P<year>\d+)/?$', personexpedition, name="personexpedition"),
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user