From f80e4efed8b6a329a7c92b9e0c68bb12faa9b517 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 16 Dec 2022 19:57:56 +0000 Subject: parse several UK caving blogs per year - working --- core/views/other.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'core/views/other.py') diff --git a/core/views/other.py b/core/views/other.py index 88d0589..b590f21 100644 --- a/core/views/other.py +++ b/core/views/other.py @@ -27,11 +27,9 @@ Also has code to download a logbook in a choice of formats (why?!) ''' todo = ''' -- 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! +- Use logbookdownloader to convert all older logbooks into the 2005-variant of HTML then we can + get rid of the parsers for older formats. When we have done all the old logbooks, delete this function and the two templates. @@ -152,7 +150,7 @@ def exportlogbook(request,year=None,extension=None): for the current year. Formats available are HTML2005 (others old & broken or not written yet) There are no images stored in the database, so this is only a tool for a first pass, to be followed by - hand-editing. However links to images work int he HTML text of a logbook entry + hand-editing. However links to images work in the HTML text of a logbook entry NEED TO ADD IN THE MATERIAL WHICH IS NOT IN ANY LBE ! e.g. front matter. @@ -183,6 +181,18 @@ def exportlogbook(request,year=None,extension=None): response['Content-Disposition'] = 'attachment; filename='+filename t=loader.get_template(template) logbookfile = (t.render({'logbook_entries':logbook_entries})) + + frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html") + if frontpath.is_file(): + try: + with open(frontpath,"r") as front: + frontmatter = front.read() + except: + print(" ! Very Bad Error opening " + frontpath) + logbookfile = re.sub(r"", "\n"+frontmatter , logbookfile) + else: + logbookfile = re.sub(r"", f"\n

Expo {year}

\n", logbookfile) + dir = Path(settings.EXPOWEB) / "years" / year filepath = Path(dir, filename) -- cgit v1.2.3