forked from expo/troggle
make ?reload private and clean old error msgs
This commit is contained in:
@@ -6,20 +6,29 @@ from django.conf import settings
|
||||
from troggle.core.models.caves import LogbookEntry, QM, Cave
|
||||
import re, urllib.parse
|
||||
|
||||
register = template.Library()
|
||||
'''Several templates are still (2021) using these wiki filters extensively to process data extracted from the database,
|
||||
and to restructure values into valid URLs to go elsewhere in the system, even where these are not actually 'wiki'. See
|
||||
the regexes at the end of this file.
|
||||
So the data in the database needs to be checked that there is no wiki-format content before these are deleted, and the
|
||||
filter functions of these regexes needs to be explored in practice.
|
||||
'''Several templates are still (2021) using these filters extensively to process data
|
||||
extracted from the database, and to restructure values into valid URLs to go elsewhere in the
|
||||
system, even where these are not actually 'wiki'. See the regexes at the end of this file.
|
||||
|
||||
'''
|
||||
todo = '''The data in the database and all input files
|
||||
needs to be checked that there is no wiki-format content before all the functions in this
|
||||
file are deleted, and the filter functions of these regexes and functions, particularly
|
||||
wiki_to_html() which is used dozens of times in the templates, needs to be explored in
|
||||
practice before being renamed more appropriately.
|
||||
'''
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter()
|
||||
def plusone(n):
|
||||
'''used in templates/svxcaveseveral.html and templates/svxcavessingle.html for formatting
|
||||
'''
|
||||
return n + 1
|
||||
|
||||
|
||||
def wiki_list(line, listdepth):
|
||||
'''Does not seem to be used anywhere except photoSrcRepl() below'''
|
||||
l = ""
|
||||
for d in listdepth:
|
||||
l += d
|
||||
@@ -50,6 +59,9 @@ def wiki_to_html(value, autoescape=None):
|
||||
"""
|
||||
This is the tag which turns wiki syntax into html. It is intended for long pieces of wiki.
|
||||
Hence it splits the wiki into HTML paragraphs based on double line feeds.
|
||||
|
||||
But it is used as a filter when rendering many, many fields, e.g.
|
||||
epersonexpedition.person|wiki_to_html_short in presonexpedition.html
|
||||
"""
|
||||
#find paragraphs
|
||||
outValue = ""
|
||||
@@ -65,6 +77,10 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
"""
|
||||
This is the tag which turns wiki syntax into html. It is intended for short pieces of wiki.
|
||||
Hence it is not split the wiki into paragraphs using where it finds double line feeds.
|
||||
|
||||
But it is used as a filter when rendering many, many fields, e.g.
|
||||
entrance.entrance_description|wiki_to_html in extrance.html
|
||||
|
||||
"""
|
||||
if autoescape:
|
||||
value = conditional_escape(value)
|
||||
@@ -120,6 +136,7 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
photoLinkPattern="\[\[\s*photo:(?P<photoName>[^\s]+)\s*(?P<linkText>.*)\]\]"
|
||||
photoSrcPattern="\[\[\s*display:(?P<style>[^\s]+) photo:(?P<photoName>[^\s]+)\s*\]\]"
|
||||
def photoLinkRepl(matchobj):
|
||||
'''Does not seem to be used anywhere except photoSrcRepl() below'''
|
||||
matchdict=matchobj.groupdict()
|
||||
try:
|
||||
linkText=matchdict['linkText']
|
||||
@@ -136,6 +153,7 @@ def wiki_to_html_short(value, autoescape=None):
|
||||
return res
|
||||
|
||||
def photoSrcRepl(matchobj):
|
||||
'''Does not seem to be used anywhere'''
|
||||
matchdict=matchobj.groupdict()
|
||||
style=matchdict['style']
|
||||
try:
|
||||
|
||||
@@ -57,9 +57,22 @@ def expedition(request, expeditionname):
|
||||
By specifying a '0' for the expected number of entries in the logbook cache, this forces the parser to
|
||||
re-parse the original logbook HTML file.
|
||||
'''
|
||||
if "reload" in request.GET:
|
||||
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
||||
LoadLogbookForExpedition(this_expedition, 0) # 0 means re-parse
|
||||
if request.user.is_authenticated:
|
||||
if "reload" in request.GET:
|
||||
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
||||
# Need to delete the exisitng entries or we get duplicaiton
|
||||
entries = this_expedition.logbookentry_set.all()
|
||||
print(f'! - expo {expeditionname} {len(entries)} entries')
|
||||
for entry in entries:
|
||||
print(f'! - delete entry: "{entry}"')
|
||||
entry.delete()
|
||||
entries = this_expedition.logbookentry_set.all()
|
||||
print(f'! - expo {expeditionname} {len(entries)} entries')
|
||||
LoadLogbookForExpedition(this_expedition, 0) # 0 means re-parse
|
||||
logged_in = True
|
||||
else:
|
||||
logged_in = False
|
||||
|
||||
|
||||
ts = TROG['pagecache']['expedition']
|
||||
if settings.CACHEDPAGES:
|
||||
@@ -67,7 +80,7 @@ def expedition(request, expeditionname):
|
||||
#print(f'! - expo {expeditionname} CACHEDPAGES {nexpos} expo pages in cache.')
|
||||
if expeditionname in ts:
|
||||
#print('! - expo {expeditionanme} using cached page')
|
||||
return render(request,'expedition.html', ts[expeditionname] )
|
||||
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in })
|
||||
|
||||
this_expedition = Expedition.objects.get(year=int(expeditionname))
|
||||
|
||||
@@ -88,11 +101,11 @@ def expedition(request, expeditionname):
|
||||
|
||||
ts[expeditionname] = {'expedition': this_expedition, 'expeditions':expeditions,
|
||||
'personexpeditiondays':personexpeditiondays, 'settings':settings,
|
||||
'dateditems': dateditems }
|
||||
'dateditems': dateditems}
|
||||
TROG['pagecache']['expedition'][expeditionname] = ts[expeditionname]
|
||||
nexpos = len( TROG['pagecache']['expedition'])
|
||||
#print(f'! - expo {expeditionname} pre-render N expos:{nexpos}')
|
||||
return render(request,'expedition.html', ts[expeditionname] )
|
||||
return render(request,'expedition.html', { **ts[expeditionname], 'logged_in' : logged_in } )
|
||||
|
||||
|
||||
# def get_absolute_url(self): # seems to have come seriously adrift. This should be in a class?!
|
||||
|
||||
@@ -41,11 +41,15 @@ def todos(request, module):
|
||||
'''
|
||||
from troggle.core.TESTS.tests import todo as tests
|
||||
from troggle.core.views.logbooks import todo as viewlogbooks
|
||||
from troggle.parsers.logbooks import todo as parserslogbooks
|
||||
from troggle.core.forms import todo as forms
|
||||
from troggle.core.templatetags.wiki_markup import todo as wiki
|
||||
tododict = {'views/other': todo,
|
||||
'tests': tests,
|
||||
'views/logbooks': viewlogbooks,
|
||||
'core/forms': forms}
|
||||
'parsers/logbooks': parserslogbooks,
|
||||
'core/forms': forms,
|
||||
'core/templatetags/wiki_markup': wiki}
|
||||
return render(request,'core/todos.html', {'tododict': tododict})
|
||||
|
||||
def troggle404(request): # cannot get this to work. Handler404 in urls.py not right syntax
|
||||
@@ -215,25 +219,25 @@ def newfile(request, pslug = None):
|
||||
return render(request, 'editfile.html', {'fileForm': fileform, })
|
||||
|
||||
@login_required_if_public
|
||||
def simpleupload(request):
|
||||
print(f'! - FORM simpleupload - start')
|
||||
def scanupload(request, year='2050'):
|
||||
print(f'! - FORM scanupload - start')
|
||||
if request.method == 'POST':
|
||||
form = SimpleUploadFileForm(request.POST,request.FILES)
|
||||
if form.is_valid():
|
||||
#form.save() # comment out so nothing saved in MEDIA_ROOT/fileuploads
|
||||
f = request.FILES["simplefile"]
|
||||
w = request.POST["title"]
|
||||
print(f'! - FORM simpleupload uploaded {f.name}')
|
||||
fs = FileSystemStorage(os.path.join(settings.SURVEY_SCANS, '2021', w))
|
||||
print(f'! - FORM scanupload uploaded {f.name}')
|
||||
fs = FileSystemStorage(os.path.join(settings.SURVEY_SCANS, year, w))
|
||||
|
||||
actual_saved = fs.save(f.name, content=f) # name may chnage to avoid clash
|
||||
# INSERT check if name is chnaged, to allow user to abort and rename - or lets do a chaecjk anyway.
|
||||
# INSERT check if name is changed, to allow user to abort and rename - or lets do a chaecjk anyway.
|
||||
|
||||
print(f'! - FORM simpleupload {actual_saved}')
|
||||
print(f'! - FORM scanupload {actual_saved}')
|
||||
|
||||
form = SimpleUploadFileForm()
|
||||
return render(request, 'simpleupload.html', {'form': form,'filesaved': True, 'actual_saved': actual_saved})
|
||||
return render(request, 'scanuploadform.html', {'form': form,'filesaved': True, 'actual_saved': actual_saved})
|
||||
else:
|
||||
form = SimpleUploadFileForm()
|
||||
return render(request, 'simpleupload.html', {'form':form,})
|
||||
return render(request, 'scanuploadform.html', {'form':form,})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user