2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

Deleted archaisms and new comments

This commit is contained in:
Philip Sargent 2020-08-02 23:53:35 +01:00
parent 3dcc8883cd
commit d61c2b20c8
6 changed files with 82 additions and 70 deletions

View File

@ -65,7 +65,10 @@ class EntranceForm(ModelForm):
return self.cleaned_data return self.cleaned_data
# This next is called from the templates/edit_cave2.html template.
# This is sufficeint to create an entire entry for for the cave fields automatically
# http://localhost:8000/cave/new/
# using django built-in stuff:
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave',)) CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave',))
class EntranceLetterForm(ModelForm): class EntranceLetterForm(ModelForm):
@ -153,6 +156,8 @@ def get_name(pe):
return pe.person.first_name return pe.person.first_name
class UploadFileForm(forms.Form): class UploadFileForm(forms.Form):
"""Only called by views_others.newFile() whhich seems to be only about logbook files.
"""
# Because this has EXECUTABLE statements in its signature (the fields) they get # Because this has EXECUTABLE statements in its signature (the fields) they get
# executed when this module is LOADED. Which barfs horribly. # executed when this module is LOADED. Which barfs horribly.
# so all replaced by an __init__ method instead. # so all replaced by an __init__ method instead.

View File

@ -34,21 +34,21 @@ def get_process_memory():
return usage[2]/1024.0 return usage[2]/1024.0
def get_related_by_wikilinks(wiki_text): # def get_related_by_wikilinks(wiki_text):
found=re.findall(settings.QM_PATTERN,wiki_text) # found=re.findall(settings.QM_PATTERN,wiki_text)
res=[] # res=[]
for wikilink in found: # for wikilink in found:
qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]} # qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
try: # try:
cave_slugs = models_caves.CaveSlug.objects.filter(cave__kataster_number = qmdict['cave']) # cave_slugs = models_caves.CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
qm=QM.objects.get(found_by__cave_slug__in = cave_slugs, # qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
found_by__date__year = qmdict['year'], # found_by__date__year = qmdict['year'],
number = qmdict['number']) # number = qmdict['number'])
res.append(qm) # res.append(qm)
except QM.DoesNotExist: # except QM.DoesNotExist:
print(('fail on '+str(wikilink))) # print(('fail on '+str(wikilink)))
return res # return res
try: try:
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
@ -72,6 +72,15 @@ class TroggleModel(models.Model):
abstract = True abstract = True
class DataIssue(TroggleModel): class DataIssue(TroggleModel):
"""When importing cave data any validation problems produce a message which is
recorded as a DataIssue. The django admin system automatically prodiuces a page listing
these at /admin/core/dataissue/
This is a use of the NOTIFICATION pattern:
https://martinfowler.com/eaaDev/Notification.html
And we need to use it to replace all assertions in the code too:
https://martinfowler.com/articles/replaceThrowWithNotification.html
"""
date = models.DateTimeField(auto_now_add=True, blank=True) date = models.DateTimeField(auto_now_add=True, blank=True)
parser = models.CharField(max_length=50, blank=True, null=True) parser = models.CharField(max_length=50, blank=True, null=True)
message = models.CharField(max_length=400, blank=True, null=True) message = models.CharField(max_length=400, blank=True, null=True)

View File

@ -128,62 +128,62 @@ def ajax_QM_number(request):
return HttpResponse(res) return HttpResponse(res)
def logbook_entry_suggestions(request): # def logbook_entry_suggestions(request):
""" # """
Generates a html box with suggestions about what to do with QMs # Generates a html box with suggestions about what to do with QMs
in logbook entry text. # in logbook entry text.
""" # """
unwiki_QM_pattern=r"(?P<whole>(?P<explorer_code>[ABC]?)(?P<cave>\d*)-?(?P<year>\d\d\d?\d?)-(?P<number>\d\d)(?P<grade>[ABCDXV]?))" # unwiki_QM_pattern=r"(?P<whole>(?P<explorer_code>[ABC]?)(?P<cave>\d*)-?(?P<year>\d\d\d?\d?)-(?P<number>\d\d)(?P<grade>[ABCDXV]?))"
unwiki_QM_pattern=re.compile(unwiki_QM_pattern) # unwiki_QM_pattern=re.compile(unwiki_QM_pattern)
#wikilink_QM_pattern=settings.QM_PATTERN # #wikilink_QM_pattern=settings.QM_PATTERN
slug=request.POST['slug'] # slug=request.POST['slug']
date=request.POST['date'] # date=request.POST['date']
lbo=LogbookEntry.objects.get(slug=slug, date=date) # lbo=LogbookEntry.objects.get(slug=slug, date=date)
#unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text) # #unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text)
unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)] # unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)]
print(unwiki_QMs) # print(unwiki_QMs)
for qm in unwiki_QMs: # for qm in unwiki_QMs:
#try: # #try:
if len(qm['year'])==2: # if len(qm['year'])==2:
if int(qm['year'])<50: # if int(qm['year'])<50:
qm['year']='20'+qm['year'] # qm['year']='20'+qm['year']
else: # else:
qm['year']='19'+qm['year'] # qm['year']='19'+qm['year']
if lbo.date.year!=int(qm['year']): # if lbo.date.year!=int(qm['year']):
try: # try:
lbo=LogbookEntry.objects.get(date__year=qm['year'],title__icontains="placeholder for QMs in") # lbo=LogbookEntry.objects.get(date__year=qm['year'],title__icontains="placeholder for QMs in")
except: # except:
print(("failed to get placeholder for year "+str(qm['year']))) # print(("failed to get placeholder for year "+str(qm['year'])))
temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade']) # temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade'])
temp_QM.grade=qm['grade'] # temp_QM.grade=qm['grade']
qm['wikilink']=temp_QM.wiki_link() # qm['wikilink']=temp_QM.wiki_link()
#except: # #except:
#print 'failed' # #print 'failed'
print(unwiki_QMs) # print(unwiki_QMs)
#wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text) # #wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text)
attached_QMs=lbo.QMs_found.all() # attached_QMs=lbo.QMs_found.all()
unmentioned_attached_QMs=''#not implemented, fill this in by subtracting wiklink_QMs from attached_QMs # unmentioned_attached_QMs=''#not implemented, fill this in by subtracting wiklink_QMs from attached_QMs
#Find unattached_QMs. We only look at the QMs with a proper wiki link. # #Find unattached_QMs. We only look at the QMs with a proper wiki link.
#for qm in wikilink_QMs: # #for qm in wikilink_QMs:
#Try to look up the QM. # #Try to look up the QM.
print('got 208') # print('got 208')
any_suggestions=True # any_suggestions=True
print('got 210') # print('got 210')
return render(request,'suggestions.html', # return render(request,'suggestions.html',
{ # {
'unwiki_QMs':unwiki_QMs, # 'unwiki_QMs':unwiki_QMs,
'any_suggestions':any_suggestions # 'any_suggestions':any_suggestions
}) # })
print(" - newFile() is next in troggle/core/views_other.py") print(" - newFile() is next in troggle/core/views_other.py")

View File

@ -85,7 +85,7 @@ def flatpage(request, path):
if m: if m:
preheader, headerattrs, head, postheader, bodyattrs, body, postbody = m.groups() preheader, headerattrs, head, postheader, bodyattrs, body, postbody = m.groups()
else: else:
return HttpResponse(html + "Page could not be split into header and body: parsing failed in flatpages.views.py") return HttpResponse(html + "HTML Parsing failure: Page could not be split into header and body: failed in flatpages.views.py")
m = re.search(rb"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE) m = re.search(rb"<title>(.*)</title>", head, re.DOTALL + re.IGNORECASE)
if m: if m:
title, = m.groups() title, = m.groups()

View File

@ -24,16 +24,12 @@ print(" * importing troggle/localsettings.py")
# - we don't want to have to change the expo system password ! # - we don't want to have to change the expo system password !
#----------------------------------------------------------------- #-----------------------------------------------------------------
SERVERPORT = '3777' SERVERPORT = '8000'
LIBDIR = '/mnt/d/CUCC-Expo/t37/lib/python3.7/' LIBDIR = '/mnt/d/CUCC-Expo/t37/lib/python3.7/'
#LIBDIR = '/mnt/d/CUCC-Expo/deb37/lib/python3.7/'
#LIBDIR = '/mnt/d/CUCC-Expo/t38/lib/python3.8/'
#LIBDIR = '/usr/lib/python3.8/' #LIBDIR = '/usr/lib/python3.8/'
REPOS_ROOT_PATH = '/mnt/d/CUCC-Expo/t37/' REPOS_ROOT_PATH = '/mnt/d/CUCC-Expo/t37/'
#REPOS_ROOT_PATH = '/mnt/d/CUCC-Expo/t38/'
#REPOS_ROOT_PATH = '/mnt/d/CUCC-Expo/deb37/'
#REPOS_ROOT_PATH = '/mnt/d/CUCC-Expo/' #REPOS_ROOT_PATH = '/mnt/d/CUCC-Expo/'
MEDIA_ROOT = REPOS_ROOT_PATH + 'troggle/media/' MEDIA_ROOT = REPOS_ROOT_PATH + 'troggle/media/'
@ -43,7 +39,7 @@ MEDIA_URL = '/site_media/'
#STATIC_ROOT removed after merging content into MEDIA_ROOT. See urls.py & core/views_surveys.py #STATIC_ROOT removed after merging content into MEDIA_ROOT. See urls.py & core/views_surveys.py
PUBLIC_SITE = True PUBLIC_SITE = True
DEBUG = True DEBUG = True # Always keep this, even when on public server. Otherwise NO ERROR MESSAGES !
# executables: # executables:
CAVERN = 'cavern' CAVERN = 'cavern'

View File

@ -6,7 +6,7 @@ from django.contrib import admin
from django.urls import reverse, resolve from django.urls import reverse, resolve
from troggle.core import views_other, views_caves, views_logbooks, views_statistics, views_survex, view_surveys from troggle.core import views_other, views_caves, views_logbooks, views_statistics, views_survex, view_surveys
from troggle.core.views_other import logbook_entry_suggestions #from troggle.core.views_other import logbook_entry_suggestions
from troggle.core.views_caves import ent, prospecting_image from troggle.core.views_caves import ent, prospecting_image
from troggle.core.views_statistics import pathsreport, stats from troggle.core.views_statistics import pathsreport, stats
from flatpages import views as flatviews from flatpages import views as flatviews
@ -39,7 +39,7 @@ actualurlpatterns = [
url(r'^people/?$', views_logbooks.personindex, name="personindex"), url(r'^people/?$', views_logbooks.personindex, name="personindex"),
url(r'^newqmnumber/?$', views_other.ajax_QM_number, ), url(r'^newqmnumber/?$', views_other.ajax_QM_number, ),
url(r'^lbo_suggestions/?$', logbook_entry_suggestions), #broken # url(r'^lbo_suggestions/?$', logbook_entry_suggestions), #broken, removed.
# url(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person), # url(r'^person/(?P<person_id>\d*)/?$', views_logbooks.person),
url(r'^person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[A-Z]*[a-z\-&;]*)/?', views_logbooks.person, name="person"), url(r'^person/(?P<first_name>[A-Z]*[a-z\-\'&;]*)[^a-zA-Z]*(?P<last_name>[a-z\-\']*[^a-zA-Z]*[A-Z]*[a-z\-&;]*)/?', views_logbooks.person, name="person"),
# url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"), # url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"),
@ -96,6 +96,8 @@ actualurlpatterns = [
url(r'^accounts/', include('registration.backends.default.urls')), # needed to log in! url(r'^accounts/', include('registration.backends.default.urls')), # needed to log in!
# url(r'^profiles/', include('profiles.urls')), # not used ? Delete this entire app then. # url(r'^profiles/', include('profiles.urls')), # not used ? Delete this entire app then.
# url(r'^map/', .........), # Intercepted by Apache. Yields OpenStreetMap. Redirects to expoweb/map
url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"), url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"),
url(r'^survexfile/(?P<survex_file>.*?)\.svx$', views_survex.svx, name="svx"), url(r'^survexfile/(?P<survex_file>.*?)\.svx$', views_survex.svx, name="svx"),
url(r'^survexfile/(?P<survex_file>.*?)\.3d$', views_survex.threed, name="threed"), url(r'^survexfile/(?P<survex_file>.*?)\.3d$', views_survex.threed, name="threed"),