summaryrefslogtreecommitdiffstats
path: root/core/views/other.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-01-30 19:04:36 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2023-01-30 19:04:36 +0000
commit7808005498b06d11775e83a614657fd6cbb476b8 (patch)
tree3c7b0bcb4518ba39548804082c2505949121354f /core/views/other.py
parentd06dd3d16678c3e222a261a12bcf2f147b3fe5f9 (diff)
downloadtroggle-7808005498b06d11775e83a614657fd6cbb476b8.tar.gz
troggle-7808005498b06d11775e83a614657fd6cbb476b8.tar.bz2
troggle-7808005498b06d11775e83a614657fd6cbb476b8.zip
ran 'black' to reformat all the core files
Diffstat (limited to 'core/views/other.py')
-rw-r--r--core/views/other.py243
1 files changed, 134 insertions, 109 deletions
diff --git a/core/views/other.py b/core/views/other.py
index 11a9b8d..bad5f75 100644
--- a/core/views/other.py
+++ b/core/views/other.py
@@ -13,34 +13,41 @@ from django.template import Context, loader
from django.urls import reverse
from troggle.core.models.caves import Cave
-from troggle.core.models.logbooks import QM, LogbookEntry #, PersonLogEntry
+from troggle.core.models.logbooks import QM, LogbookEntry # , PersonLogEntry
from troggle.core.models.survex import DrawingFile
+
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
from troggle.core.models.troggle import Expedition, Person, PersonExpedition
-from troggle.parsers.imports import (import_caves, import_drawingsfiles,
- import_logbooks, import_people,
- import_QMs, import_survex,
- import_surveyscans)
+from troggle.parsers.imports import (
+ import_caves,
+ import_drawingsfiles,
+ import_logbooks,
+ import_people,
+ import_QMs,
+ import_survex,
+ import_surveyscans,
+)
from .auth import login_required_if_public
-'''Utility functions and code to serve the control panel and individual user's
+"""Utility functions and code to serve the control panel and individual user's
progress and task list (deprecated as we do not have individual user login).
-'''
+"""
-todo = '''
+todo = """
- 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.
OR invent a new format, e.g. using <article> and <section>?, which is better!
-'''
+"""
+
-def todos(request, module):
- '''produces todo text from module
+def todos(request, module):
+ """produces todo text from module
We could automate this to find all those strings automatically
- '''
+ """
from troggle.core.forms import todo as forms
from troggle.core.middleware import todo as middleware
from troggle.core.models.caves import todo as modelcaves
@@ -53,164 +60,182 @@ def todos(request, module):
from troggle.parsers.drawings import todo as parsersdrawings
from troggle.parsers.logbooks import todo as parserslogbooks
from troggle.parsers.survex import todo as parserssurvex
- tododict = {'views/other': todo,
- 'tests': tests,
- 'views/logbooks': viewlogbooks,
- 'views/survex': viewsurvex,
- 'views/caves': viewcaves,
- 'views/drawings': viewdrawings,
- 'parsers/caves': parserscaves,
- 'parsers/logbooks': parserslogbooks,
- 'parsers/drawings': parsersdrawings,
- 'parsers/survex': parserssurvex,
- 'core/models/caves': modelcaves,
- 'core/middleware': middleware,
- 'core/forms': forms}
- return render(request,'core/todos.html', {'tododict': tododict})
-
-def troggle404(request): # cannot get this to work. Handler404 in urls.py not right syntax
- '''Custom 404 page to be used even when Debug=True
+
+ tododict = {
+ "views/other": todo,
+ "tests": tests,
+ "views/logbooks": viewlogbooks,
+ "views/survex": viewsurvex,
+ "views/caves": viewcaves,
+ "views/drawings": viewdrawings,
+ "parsers/caves": parserscaves,
+ "parsers/logbooks": parserslogbooks,
+ "parsers/drawings": parsersdrawings,
+ "parsers/survex": parserssurvex,
+ "core/models/caves": modelcaves,
+ "core/middleware": middleware,
+ "core/forms": forms,
+ }
+ return render(request, "core/todos.html", {"tododict": tododict})
+
+
+def troggle404(request): # cannot get this to work. Handler404 in urls.py not right syntax
+ """Custom 404 page to be used even when Debug=True
https://blog.juanwolf.fr/posts/programming/how-to-create-404-page-django/
- '''
+ """
context = RequestContext(request)
- #context['caves'] = Cave.objects.all()
- return render(request, ('errors/generic.html', context.flatten()))
+ # context['caves'] = Cave.objects.all()
+ return render(request, ("errors/generic.html", context.flatten()))
-def frontpage(request):
- '''never seen in common practice. Logon should redirect here when this is more useful'''
+
+def frontpage(request):
+ """never seen in common practice. Logon should redirect here when this is more useful"""
# the messages system does a popup on this page if there is a recent message, e.g. from the admin site actions.
- # via django.contrib.messages.middleware.MessageMiddleware
+ # via django.contrib.messages.middleware.MessageMiddleware
# this is set in the templates.
if request.user.is_authenticated:
- return render(request,'tasks.html')
+ return render(request, "tasks.html")
- expeditions = Expedition.objects.order_by("-year")
+ expeditions = Expedition.objects.order_by("-year")
logbookentry = LogbookEntry
cave = Cave
- #from django.contrib.admin.templatetags import log
- return render(request,'frontpage.html', locals())
+ # from django.contrib.admin.templatetags import log
+ return render(request, "frontpage.html", locals())
@login_required_if_public
def controlpanel(request):
- '''Admin requires expoadmin user logged on
+ """Admin requires expoadmin user logged on
Mostly disabled apart from logbook export
DANGEROUS, these import functions kill the ground under your feet !
- '''
- jobs_completed=[]
-
+ """
+ jobs_completed = []
+
def process_imports():
- '''databaseReset.py
- jq.enq("reinit",reinit_db)
- jq.enq("caves",import_caves)
- jq.enq("people",import_people)
- jq.enq("scans",import_surveyscans)
- jq.enq("logbooks",import_logbooks)
- jq.enq("QMs",import_QMs)
- jq.enq("drawings",import_drawingsfiles)
- jq.enq("survex",import_survex)
- '''
+ """databaseReset.py
+ jq.enq("reinit",reinit_db)
+ jq.enq("caves",import_caves)
+ jq.enq("people",import_people)
+ jq.enq("scans",import_surveyscans)
+ jq.enq("logbooks",import_logbooks)
+ jq.enq("QMs",import_QMs)
+ jq.enq("drawings",import_drawingsfiles)
+ jq.enq("survex",import_survex)
+ """
if request.POST.get("import_caves", False):
import_caves()
- jobs_completed.append('Caves')
+ jobs_completed.append("Caves")
if request.POST.get("import_people", False):
import_people()
- jobs_completed.append('People')
+ jobs_completed.append("People")
if request.POST.get("import_surveyscans", False):
import_surveyscans()
- jobs_completed.append('Scans')
+ jobs_completed.append("Scans")
if request.POST.get("import_logbooks", False):
import_logbooks()
- jobs_completed.append('Logbooks')
+ jobs_completed.append("Logbooks")
if request.POST.get("import_QMs", False):
import_QMs()
- jobs_completed.append('QMs')
+ jobs_completed.append("QMs")
if request.POST.get("import_drawingsfiles", False):
import_drawingsfiles()
- jobs_completed.append('Drawings')
+ jobs_completed.append("Drawings")
if request.POST.get("import_survex", False):
import_survex()
- jobs_completed.append('Survex')
-
+ jobs_completed.append("Survex")
+
print("", flush=True)
- if not request.user.is_superuser: # expoadmin is both .is_staff and ._is_superuser
- return render(request,'controlPanel.html', {'error': 'You are logged in, but not logged in as "expoadmin". \nLogout and login again to contnue.'})
+ if not request.user.is_superuser: # expoadmin is both .is_staff and ._is_superuser
+ return render(
+ request,
+ "controlPanel.html",
+ {"error": 'You are logged in, but not logged in as "expoadmin". \nLogout and login again to contnue.'},
+ )
else:
- if request.method=='POST':
- #reinit_db()
+ if request.method == "POST":
+ # reinit_db()
process_imports()
- return render(request,'controlPanel.html', {'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed})
+ return render(
+ request,
+ "controlPanel.html",
+ {"expeditions": Expedition.objects.all(), "jobs_completed": jobs_completed},
+ )
else:
- return render(request,'controlPanel.html', {'expeditions':Expedition.objects.all(),'jobs_completed':jobs_completed})
-
+ return render(
+ request,
+ "controlPanel.html",
+ {"expeditions": Expedition.objects.all(), "jobs_completed": jobs_completed},
+ )
-def exportlogbook(request,year=None,extension=None):
- '''Constructs, from the database, a complete HTML formatted logbook
+def exportlogbook(request, year=None, extension=None):
+ """Constructs, from the database, a complete HTML formatted logbook
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 in the HTML text of a logbook entry
-
- NEED TO ADD IN THE MATERIAL WHICH IS NOT IN ANY LBE ! e.g. front matter.
-
+
+ NEED TO ADD IN THE MATERIAL WHICH IS NOT IN ANY LBE ! e.g. front matter.
+
This function is the recipient of the POST action os the export form in the control panel
- '''
+ """
+
def lbeKey(lbe):
- """This function goes into a lexicogrpahic sort function
- """
+ """This function goes into a lexicogrpahic sort function"""
return str(lbe.date)
- if not request.method=='POST':
- return render(request,'controlPanel.html', {'expeditions':Expedition.objects.all(),'jobs_completed':""})
+ if not request.method == "POST":
+ return render(request, "controlPanel.html", {"expeditions": Expedition.objects.all(), "jobs_completed": ""})
else:
- print(f'Logbook export {request.POST}')
-
- year = request.POST['year']
- current_expedition=Expedition.objects.get(year=year)
- logbook_entries=LogbookEntry.objects.filter(expedition=current_expedition).order_by('date') # need to be sorted by date!
-
- print(f'Logbook has {len(logbook_entries)} entries in it.')
-
- extension ='html'
- response = HttpResponse(content_type='text/html')
- style='2005'
-
- filename='logbook-new-format.' + extension
- template='logbook'+style+'style.'+ extension
- response['Content-Disposition'] = 'attachment; filename='+filename
- t=loader.get_template(template)
- logbookfile = (t.render({'logbook_entries':logbook_entries}))
+ print(f"Logbook export {request.POST}")
+
+ year = request.POST["year"]
+ current_expedition = Expedition.objects.get(year=year)
+ logbook_entries = LogbookEntry.objects.filter(expedition=current_expedition).order_by(
+ "date"
+ ) # need to be sorted by date!
+
+ print(f"Logbook has {len(logbook_entries)} entries in it.")
+
+ extension = "html"
+ response = HttpResponse(content_type="text/html")
+ style = "2005"
+
+ filename = "logbook-new-format." + extension
+ template = "logbook" + style + "style." + extension
+ response["Content-Disposition"] = "attachment; filename=" + filename
+ t = loader.get_template(template)
+ logbookfile = t.render({"logbook_entries": logbook_entries})
endpath = Path(settings.EXPOWEB, "years", year, "endmatter.html")
endmatter = ""
- if endpath.is_file():
+ if endpath.is_file():
try:
- with open(endpath,"r") as end:
- endmatter = end.read()
+ with open(endpath, "r") as end:
+ endmatter = end.read()
except:
print(" ! Very Bad Error opening " + endpath)
frontpath = Path(settings.EXPOWEB, "years", year, "frontmatter.html")
- if frontpath.is_file():
+ if frontpath.is_file():
try:
- with open(frontpath,"r") as front:
- frontmatter = front.read()
+ with open(frontpath, "r") as front:
+ frontmatter = front.read()
except:
print(" ! Very Bad Error opening " + frontpath)
- logbookfile = re.sub(r"<body>", "<body>\n"+frontmatter+endmatter , logbookfile)
+ logbookfile = re.sub(r"<body>", "<body>\n" + frontmatter + endmatter, logbookfile)
else:
- logbookfile = re.sub(r"<body>", f"<body>\n<h1>Expo {year}</h1>\n"+endmatter, logbookfile)
-
+ logbookfile = re.sub(r"<body>", f"<body>\n<h1>Expo {year}</h1>\n" + endmatter, logbookfile)
dir = Path(settings.EXPOWEB) / "years" / year
filepath = Path(dir, filename)
- with(open(filepath, 'w')) as lb:
+ with (open(filepath, "w")) as lb:
lb.writelines(logbookfile)
- #print(f'Logbook exported to {filepath}')
+ # print(f'Logbook exported to {filepath}')
completed = f'Logbook exported to <a href="/years/{filename}">{filename}</a>'
- return render(request,'controlPanel.html', {'expeditions':Expedition.objects.all(),'jobs_completed':[completed]})
-
+ return render(
+ request, "controlPanel.html", {"expeditions": Expedition.objects.all(), "jobs_completed": [completed]}
+ )