summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2020-08-02 23:53:35 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2020-08-02 23:53:35 +0100
commitd61c2b20c832557b4ce65df53bc94c6c1bd1ef65 (patch)
treee7802f319a2b4547350b43ede3dcd45b6c9166c5 /core
parent3dcc8883cd69d4289bb89f6fa3180d63dea542b9 (diff)
downloadtroggle-d61c2b20c832557b4ce65df53bc94c6c1bd1ef65.tar.gz
troggle-d61c2b20c832557b4ce65df53bc94c6c1bd1ef65.tar.bz2
troggle-d61c2b20c832557b4ce65df53bc94c6c1bd1ef65.zip
Deleted archaisms and new comments
Diffstat (limited to 'core')
-rw-r--r--core/forms.py7
-rw-r--r--core/models.py37
-rw-r--r--core/views_other.py94
3 files changed, 76 insertions, 62 deletions
diff --git a/core/forms.py b/core/forms.py
index 7816014..f86796a 100644
--- a/core/forms.py
+++ b/core/forms.py
@@ -65,7 +65,10 @@ class EntranceForm(ModelForm):
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',))
class EntranceLetterForm(ModelForm):
@@ -153,6 +156,8 @@ def get_name(pe):
return pe.person.first_name
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
# executed when this module is LOADED. Which barfs horribly.
# so all replaced by an __init__ method instead.
diff --git a/core/models.py b/core/models.py
index cd6f1e2..eb8428d 100644
--- a/core/models.py
+++ b/core/models.py
@@ -34,21 +34,21 @@ def get_process_memory():
return usage[2]/1024.0
-def get_related_by_wikilinks(wiki_text):
- found=re.findall(settings.QM_PATTERN,wiki_text)
- res=[]
- for wikilink in found:
- qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
- try:
- cave_slugs = models_caves.CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
- qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
- found_by__date__year = qmdict['year'],
- number = qmdict['number'])
- res.append(qm)
- except QM.DoesNotExist:
- print(('fail on '+str(wikilink)))
+# def get_related_by_wikilinks(wiki_text):
+ # found=re.findall(settings.QM_PATTERN,wiki_text)
+ # res=[]
+ # for wikilink in found:
+ # qmdict={'urlroot':settings.URL_ROOT,'cave':wikilink[2],'year':wikilink[1],'number':wikilink[3]}
+ # try:
+ # cave_slugs = models_caves.CaveSlug.objects.filter(cave__kataster_number = qmdict['cave'])
+ # qm=QM.objects.get(found_by__cave_slug__in = cave_slugs,
+ # found_by__date__year = qmdict['year'],
+ # number = qmdict['number'])
+ # res.append(qm)
+ # except QM.DoesNotExist:
+ # print(('fail on '+str(wikilink)))
- return res
+ # return res
try:
logging.basicConfig(level=logging.DEBUG,
@@ -72,6 +72,15 @@ class TroggleModel(models.Model):
abstract = True
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)
parser = models.CharField(max_length=50, blank=True, null=True)
message = models.CharField(max_length=400, blank=True, null=True)
diff --git a/core/views_other.py b/core/views_other.py
index 10c1ec7..cc8fe3a 100644
--- a/core/views_other.py
+++ b/core/views_other.py
@@ -128,62 +128,62 @@ def ajax_QM_number(request):
return HttpResponse(res)
-def logbook_entry_suggestions(request):
- """
- Generates a html box with suggestions about what to do with QMs
- 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=re.compile(unwiki_QM_pattern)
- #wikilink_QM_pattern=settings.QM_PATTERN
+# def logbook_entry_suggestions(request):
+ # """
+ # Generates a html box with suggestions about what to do with QMs
+ # 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=re.compile(unwiki_QM_pattern)
+ # #wikilink_QM_pattern=settings.QM_PATTERN
- slug=request.POST['slug']
- date=request.POST['date']
- lbo=LogbookEntry.objects.get(slug=slug, date=date)
+ # slug=request.POST['slug']
+ # date=request.POST['date']
+ # lbo=LogbookEntry.objects.get(slug=slug, date=date)
- #unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text)
- unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)]
+ # #unwiki_QMs=re.findall(unwiki_QM_pattern,lbo.text)
+ # unwiki_QMs=[m.groupdict() for m in unwiki_QM_pattern.finditer(lbo.text)]
- print(unwiki_QMs)
- for qm in unwiki_QMs:
- #try:
- if len(qm['year'])==2:
- if int(qm['year'])<50:
- qm['year']='20'+qm['year']
- else:
- qm['year']='19'+qm['year']
-
- if lbo.date.year!=int(qm['year']):
- try:
- lbo=LogbookEntry.objects.get(date__year=qm['year'],title__icontains="placeholder for QMs in")
- except:
- print(("failed to get placeholder for year "+str(qm['year'])))
+ # print(unwiki_QMs)
+ # for qm in unwiki_QMs:
+ # #try:
+ # if len(qm['year'])==2:
+ # if int(qm['year'])<50:
+ # qm['year']='20'+qm['year']
+ # else:
+ # qm['year']='19'+qm['year']
+
+ # if lbo.date.year!=int(qm['year']):
+ # try:
+ # lbo=LogbookEntry.objects.get(date__year=qm['year'],title__icontains="placeholder for QMs in")
+ # except:
+ # print(("failed to get placeholder for year "+str(qm['year'])))
- temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade'])
- temp_QM.grade=qm['grade']
- qm['wikilink']=temp_QM.wiki_link()
- #except:
- #print 'failed'
+ # temp_QM=QM(found_by=lbo,number=qm['number'],grade=qm['grade'])
+ # temp_QM.grade=qm['grade']
+ # qm['wikilink']=temp_QM.wiki_link()
+ # #except:
+ # #print 'failed'
- print(unwiki_QMs)
+ # print(unwiki_QMs)
- #wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text)
- attached_QMs=lbo.QMs_found.all()
- unmentioned_attached_QMs=''#not implemented, fill this in by subtracting wiklink_QMs from attached_QMs
+ # #wikilink_QMs=re.findall(wikilink_QM_pattern,lbo.text)
+ # attached_QMs=lbo.QMs_found.all()
+ # 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.
- #for qm in wikilink_QMs:
- #Try to look up the QM.
+ # #Find unattached_QMs. We only look at the QMs with a proper wiki link.
+ # #for qm in wikilink_QMs:
+ # #Try to look up the QM.
- print('got 208')
- any_suggestions=True
- print('got 210')
- return render(request,'suggestions.html',
- {
- 'unwiki_QMs':unwiki_QMs,
- 'any_suggestions':any_suggestions
- })
+ # print('got 208')
+ # any_suggestions=True
+ # print('got 210')
+ # return render(request,'suggestions.html',
+ # {
+ # 'unwiki_QMs':unwiki_QMs,
+ # 'any_suggestions':any_suggestions
+ # })
print(" - newFile() is next in troggle/core/views_other.py")