Add date of update to the generated html file

This commit is contained in:
Philip Sargent 2022-10-12 22:09:58 +03:00
parent 52c0ab213a
commit b81b4ef2ef
4 changed files with 17 additions and 10 deletions

View File

@ -5,6 +5,7 @@ import re
import json import json
import subprocess import subprocess
import operator import operator
from datetime import datetime, timezone
from collections import defaultdict from collections import defaultdict
from pathlib import Path from pathlib import Path
@ -235,8 +236,9 @@ class Cave(TroggleModel):
filepath = os.path.join(settings.CAVEDESCRIPTIONS, self.filename) filepath = os.path.join(settings.CAVEDESCRIPTIONS, self.filename)
t = loader.get_template('dataformat/cave.xml') t = loader.get_template('dataformat/cave.xml')
#c = Context({'cave': self}) now = datetime.now(timezone.utc)
c = dict({'cave': self}) print(now)
c = dict({'cave': self, 'date': now})
u = t.render(c) u = t.render(c)
writetrogglefile(filepath, u) writetrogglefile(filepath, u)
return return
@ -245,8 +247,8 @@ class Cave(TroggleModel):
filepath = Path(os.path.join(settings.CAVEDESCRIPTIONS, self.filename)) filepath = Path(os.path.join(settings.CAVEDESCRIPTIONS, self.filename))
t = loader.get_template('dataformat/cave.xml') t = loader.get_template('dataformat/cave.xml')
#c = Context({'cave': self}) now = datetime.now(timezone.utc)
c = dict({'cave': self}) c = dict({'cave': self, 'date': now})
content = t.render(c) content = t.render(c)
return (filepath, content, "utf8") return (filepath, content, "utf8")
@ -422,7 +424,8 @@ class Entrance(TroggleModel):
filepath = Path(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename)) filepath = Path(os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename))
t = loader.get_template('dataformat/entrance.xml') t = loader.get_template('dataformat/entrance.xml')
c = dict({'entrance': self}) now = datetime.now(timezone.utc)
c = dict({'entrance': self, 'date': now})
content = t.render(c) content = t.render(c)
return (filepath, content, "utf8") return (filepath, content, "utf8")
@ -430,7 +433,8 @@ class Entrance(TroggleModel):
filepath = os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename) filepath = os.path.join(settings.ENTRANCEDESCRIPTIONS, self.filename)
t = loader.get_template('dataformat/entrance.xml') t = loader.get_template('dataformat/entrance.xml')
c = dict({'entrance': self}) now = datetime.now(timezone.utc)
c = dict({'entrance': self, 'date': now})
u = t.render(c) u = t.render(c)
writetrogglefile(filepath, u) writetrogglefile(filepath, u)
return return

View File

@ -301,6 +301,7 @@ def caveEntrance(request, slug):
def edit_cave(request, path = "", slug=None): def edit_cave(request, path = "", slug=None):
'''This is the form that edits all the cave data and writes out an XML file in the :expoweb: repo folder '''This is the form that edits all the cave data and writes out an XML file in the :expoweb: repo folder
The format for the file being saved is in templates/dataformat/cave.xml The format for the file being saved is in templates/dataformat/cave.xml
Warning. This uses Django deep magic.
It does save the data into into the database directly, not by parsing the file. It does save the data into into the database directly, not by parsing the file.
''' '''
@ -343,6 +344,7 @@ def edit_cave(request, path = "", slug=None):
ceinst.save() ceinst.save()
try: try:
cave_file = cave.file_output() cave_file = cave.file_output()
print(cave_file)
write_and_commit([cave_file], "Online edit of %s" % cave) write_and_commit([cave_file], "Online edit of %s" % cave)
# leave other exceptions unhandled so that they bubble up to user interface # leave other exceptions unhandled so that they bubble up to user interface
except PermissionError: except PermissionError:
@ -373,6 +375,7 @@ def edit_entrance(request, path = "", caveslug=None, slug=None):
'''This is the form that edits the entrance data for a single entrance and writes out '''This is the form that edits the entrance data for a single entrance and writes out
an XML file in the :expoweb: repo folder an XML file in the :expoweb: repo folder
The format for the file being saved is in templates/dataformat/entrance.xml The format for the file being saved is in templates/dataformat/entrance.xml
Warning. This uses Django deep magic.
It does save the data into into the database directly, not by parsing the file. It does save the data into into the database directly, not by parsing the file.
''' '''

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<!-- This file is generated by troggle using the form documented at /handbook/survey/caveentry.html --> <!-- This file is generated by troggle on {{date}} UTC using the form documented at /handbook/survey/caveentry.html -->
<!-- Only put one cave in this file --> <!-- Only put one cave in this file -->
<!-- If you edit this 1623-nnn.html file by hand, make sure you update the database by doing a full data import --> <!-- If you edit this 1623-nnn.html file by hand, make sure you update the database by doing a full data import -->
<!-- ALTERNATIVELY you can download an example template from expoweb/templates/cave_data.html --> <!-- ALTERNATIVELY you can download an example template from expoweb/templates/cave_data.html -->
@ -8,7 +8,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head> </head>
<body> <body>
<b>This file is generated by troggle</b> using the form documented at /handbook/survey/caveentry.html <b>This file is generated by troggle</b> on {{date}} UTC using the form documented at /handbook/survey/caveentry.html
<br> <br>
<cave> <cave>

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<!-- Only put one entrance in this file --> <!-- Only put one entrance in this file -->
<!-- This file is generated by troggle using the form documented at handbook/survey/ententry.html --> <!-- This file is generated by troggle on {{date}} UTC using the form documented at handbook/survey/ententry.html -->
<!-- If you edit this file by hand, make sure you update the database by doing a full data import --> <!-- If you edit this file by hand, make sure you update the database by doing a full data import -->
<!-- See http://expo.survex.com/handbook/survey/caveentryfields.html for current details on filling in this form --> <!-- See http://expo.survex.com/handbook/survey/caveentryfields.html for current details on filling in this form -->
@ -12,7 +12,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head> </head>
<body> <body>
<b>This file is generated by troggle </b>using the form documented at handbook/survey/ententry.html <b>This file is generated by troggle</b> on {{date}} UTC using the form documented at handbook/survey/ententry.html
<br> <br>
<entrance> <entrance>
<non_public>{{ entrance.non_public }}</non_public>{% for slug in entrance.entranceslug_set.all %} <non_public>{{ entrance.non_public }}</non_public>{% for slug in entrance.entranceslug_set.all %}