forked from expo/troggle
archeology on the logbook entry editing forms
This commit is contained in:
@@ -93,14 +93,14 @@ class EntranceForm(ModelForm):
|
||||
return self.cleaned_data
|
||||
|
||||
|
||||
# This next is called from the templates/edit_cave2.html template.
|
||||
# This next line 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 Deep magic. https://docs.djangoproject.com/en/2.2/topics/forms/modelforms/
|
||||
CaveAndEntranceFormSet = modelformset_factory(CaveAndEntrance, exclude=('cave',))
|
||||
|
||||
class EntranceLetterForm(ModelForm):
|
||||
'''Can't see what this does at all
|
||||
'''Can't see what this does at all. called twice from views.caves
|
||||
'''
|
||||
class Meta:
|
||||
model = CaveAndEntrance
|
||||
@@ -148,37 +148,35 @@ def get_name(pe):
|
||||
class UploadFileForm(forms.Form):
|
||||
"""Only called by views.others.newFile() which seems to be only about logbook files.
|
||||
"""
|
||||
title = forms.CharField(max_length=50)
|
||||
file = forms.FileField()
|
||||
#html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
||||
html = forms.CharField(widget=forms.Textarea(attrs={"cols":80, "rows":20}))
|
||||
lon_utm = forms.FloatField(required=False)
|
||||
lat_utm = forms.FloatField(required=False)
|
||||
slug = forms.CharField(max_length=50)
|
||||
date = forms.DateField(required=False)
|
||||
survey_point = forms.CharField()
|
||||
|
||||
# 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.
|
||||
# so all put in an __init__ method instead pending deletion or rewriting
|
||||
def __init__(self):
|
||||
title = forms.CharField(max_length=50)
|
||||
file = forms.FileField()
|
||||
#html = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
|
||||
html = forms.CharField(widget=forms.Textarea(attrs={"cols":80, "rows":20}))
|
||||
lon_utm = forms.FloatField(required=False)
|
||||
lat_utm = forms.FloatField(required=False)
|
||||
slug = forms.CharField(max_length=50)
|
||||
date = forms.DateField(required=False)
|
||||
|
||||
#This next line is the one that causes django.setup() to BARF LOUDLY
|
||||
caves = [cave.slug for cave in Cave.objects.all()]
|
||||
#caves.sort() # sort needs rewriting for python3
|
||||
caves = ["-----"] + caves
|
||||
cave = forms.ChoiceField([(c, c) for c in caves], required=False)
|
||||
|
||||
|
||||
entrance = forms.ChoiceField([("-----", "Please select a cave"), ], required=False)
|
||||
qm = forms.ChoiceField([("-----", "Please select a cave"), ], required=False)
|
||||
|
||||
expeditions = [e.year for e in Expedition.objects.all()]
|
||||
expeditions.sort()
|
||||
expeditions = ["-----"] + expeditions
|
||||
expedition = forms.ChoiceField([(e, e) for e in expeditions], required=False)
|
||||
|
||||
qm = forms.ChoiceField([("-----", "Please select a cave"), ], required=False)
|
||||
logbookentry = forms.ChoiceField([("-----", "Please select an expedition"), ], required=False)
|
||||
|
||||
person = forms.ChoiceField([("-----", "Please select an expedition"), ], required=False)
|
||||
|
||||
survey_point = forms.CharField()
|
||||
|
||||
|
||||
|
||||
@@ -23,15 +23,24 @@ download all QMs (not working)
|
||||
|
||||
todo = '''Delete the newfile & TripForm code once we have a proper file-upload system working.
|
||||
meanwhile keep it as an example to consider.
|
||||
|
||||
Check that the logbookdownloader works by testing with a round trip.
|
||||
|
||||
Use it to convert all older logbooks into the 2005-variant of HTML then we can
|
||||
get rid of the parsers for older formats. There are no images stored in the database,
|
||||
so this is only a tool for a first pass, to be followed by extensive hand-editing!
|
||||
When we have done all the old logbooks, delete this function and the two templates.
|
||||
|
||||
But how does this interact with troggle/logbooksdump.py ?S
|
||||
'''
|
||||
|
||||
def todos(request, module):
|
||||
'''produces todo text from module
|
||||
We should automate this to find all those strings automatically
|
||||
'''
|
||||
from troggle.core.TESTS.tests import todo as tests
|
||||
from troggle.core.views.logbooks import todo as viewlogbooks
|
||||
from troggle.core.forms import todo as forms
|
||||
print(f'TODO - {tests}')
|
||||
tododict = {'views/other': todo,
|
||||
'tests': tests,
|
||||
'views/logbooks': viewlogbooks,
|
||||
@@ -85,6 +94,12 @@ def controlpanel(request):
|
||||
|
||||
|
||||
def downloadlogbook(request,year=None,extension=None,queryset=None):
|
||||
'''Constructs, from the database, a complete HTML (or TXT) formatted logbook - but TEXT ONLY
|
||||
for the current year. Formats available are HTML2005 or 2008text
|
||||
|
||||
There are no images stored in the database, so this is only a tool for a first pass, tobe followed by
|
||||
extensive hand-editing.
|
||||
'''
|
||||
|
||||
if year:
|
||||
current_expedition=Expedition.objects.get(year=year)
|
||||
@@ -108,11 +123,14 @@ def downloadlogbook(request,year=None,extension=None,queryset=None):
|
||||
elif extension == 'html':
|
||||
response = HttpResponse(content_type='text/html')
|
||||
style='2005'
|
||||
else:
|
||||
response = HttpResponse(content_type='text/html')
|
||||
style='2005'
|
||||
|
||||
template='logbook'+style+'style.'+extension
|
||||
response['Content-Disposition'] = 'attachment; filename='+filename+'.'+extension
|
||||
t=loader.get_template(template)
|
||||
c=Context({'logbook_entries':logbook_entries})
|
||||
c={'logbook_entries':logbook_entries}
|
||||
response.write(t.render(c))
|
||||
return response
|
||||
|
||||
@@ -153,7 +171,12 @@ def ajax_QM_number(request):
|
||||
|
||||
@login_required_if_public
|
||||
def newfile(request, pslug = None):
|
||||
''' not known quite what this was for or where it fits in - original 2006 troggle idea never finished?
|
||||
'''
|
||||
If not POST, it goes straight to UploadFileForm using the editfile.html template which is about re-submitting
|
||||
a LBE aka TripReport
|
||||
|
||||
If it is POST, then it is a new LBE so an HTML formatted version of it is produced, using template.render()
|
||||
and a format 'dataformat/logbookentry.html' which is then put in expoweb/years<year>/autologbook/<LBEnamedfile>
|
||||
'''
|
||||
if pslug:
|
||||
previousfile = LogbookEntry.objects.get(slug = pslug, date = previousdate, expedition = expedition)
|
||||
@@ -174,10 +197,10 @@ def newfile(request, pslug = None):
|
||||
delLogbookEntry(previouslbe)
|
||||
f = open(filename, "w")
|
||||
template = loader.get_template('dataformat/logbookentry.html')
|
||||
context = Context({'trip': tripForm.cleaned_data,
|
||||
context = {'trip': tripForm.cleaned_data,
|
||||
'persons': personTripFormSet.cleaned_data,
|
||||
'date': dateStr,
|
||||
'expeditionyear': expeditionyear})
|
||||
'expeditionyear': expeditionyear}
|
||||
f.write(template.render(context))
|
||||
f.close()
|
||||
print(logbookparsers.parseAutoLogBookEntry(filename))
|
||||
|
||||
Reference in New Issue
Block a user