From 7368942488de79ae96d3c8cc3d8f80732636f7b5 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 30 Apr 2021 23:21:38 +0100 Subject: [PATCH] remove unused templatetags code --- core/forms.py | 4 +- core/middleware.py | 6 +- core/templatetags/csrffaker.py | 10 -- core/templatetags/survex_markup.py | 63 ---------- core/templatetags/wiki_markup.py | 189 ----------------------------- core/unused.py | 130 -------------------- core/views/other.py | 67 +--------- 7 files changed, 7 insertions(+), 462 deletions(-) delete mode 100644 core/templatetags/csrffaker.py delete mode 100644 core/templatetags/survex_markup.py delete mode 100644 core/templatetags/wiki_markup.py delete mode 100644 core/unused.py diff --git a/core/forms.py b/core/forms.py index 2781c67..896a655 100644 --- a/core/forms.py +++ b/core/forms.py @@ -15,9 +15,7 @@ from troggle.core.models.caves import Cave, LogbookEntry, QM, Entrance, CaveAndE Some are not used and need renovating or destroying. ''' -todo = '''Remove UploadFileForm - replace by Simple variant -Re engineer Simple upload to not use a Django form object - +todo = '''Re-enable TinyMCE ''' class CaveForm(ModelForm): diff --git a/core/middleware.py b/core/middleware.py index 91e64ec..e87662e 100644 --- a/core/middleware.py +++ b/core/middleware.py @@ -2,9 +2,11 @@ from django.conf import settings from django import http from django.urls import reverse, resolve,Resolver404 """Non-standard django middleware is loaded from this file. -It needs re-writing to be compatible with Django v2.0+ -""" +""" +todo = '''SmartAppendSlashMiddleware(object) Not Working. +It needs re-writing to be compatible with Django v2.0 and later +''' class SmartAppendSlashMiddleware(object): """ "SmartAppendSlash" middleware for taking care of URL rewriting. diff --git a/core/templatetags/csrffaker.py b/core/templatetags/csrffaker.py deleted file mode 100644 index 6186369..0000000 --- a/core/templatetags/csrffaker.py +++ /dev/null @@ -1,10 +0,0 @@ -import django -from django import template - -register = template.Library() -# if django.VERSION[0] >=1 and django.VERSION[1] > 1: - # pass -# else: - - # @register.simple_tag - # def csrf_token(): return "" diff --git a/core/templatetags/survex_markup.py b/core/templatetags/survex_markup.py deleted file mode 100644 index 35b2670..0000000 --- a/core/templatetags/survex_markup.py +++ /dev/null @@ -1,63 +0,0 @@ -from django import template -from django.utils.html import conditional_escape -from django.template.defaultfilters import stringfilter -from django.utils.safestring import mark_safe -import re - -register = template.Library() -'''Now entirely defunct. - -Simple use in svxfile.html produced a textarea, double-spacing and no colouring. -so this would take some work, and we are better off not using it but getting -syntax colouring to work with CodeMirror instead. PPhilip S. 28 March 2021. - -The only template which used it, survexblock.html, has been removed as unnecessary. - -''' -# seems to add extra lines between the commented lines, which isn't so great. - - - -regexes = [] -regexes.append((re.compile(r"(;.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\n')) -regexes.append((re.compile(r"^(\s*)(\*include)(\s+)([^\s]*)(.svx)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4\5')) -regexes.append((re.compile(r"^(\s*)(\*include)(\s+)([^\s]*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*team\s+(?:notes|tape|insts|pics))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*(?:begin|end|copyright|date|entrance|equate|export|fix|prefix|require|SOLVE|title|truncate))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*calibrate\s+(?:TAPE|COMPASS|CLINO|COUNTER|DEPTH|DECLINATION|X|Y|Z)+)(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*data\s+(?:DEFAULT|NORMAL|DIVING|CARTESIAN|TOPOFIL|CYLPOLAR|NOSURVEY|passage)(?:\s+station|\s+from|\s+to|\s+FROMDEPTH|\s+TODEPTH|\s+DEPTHCHANGE|\s+newline|\s+direction|\s+tape|\s+compass|\s+clino|\s+northing|\s+easting|\s+altitude|\s+length|\s+bearing|\s+gradient|\s+ignoreall|\sleft|\sright|\sup|\sdown)*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2')) -regexes.append((re.compile(r"^(\s*)(\*default\s+(?:CALIBRATE|DATA|UNITS)+)(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*flags\s+(?:DUPLICATE|SPLAY|SURFACE|not DUPLICATE|not SPLAY|not SURFACE))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*infer\s+(?:plumbs|equates|exports))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*instrument\s+(?:compass|clino|tape))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*instrument\s+(?:compass|clino|tape))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*sd\s+(?:TAPE|COMPASS|CLINO|COUNTER|DEPTH|DECLINATION|DX|DY|DZ))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*set\s+(?:BLANK|COMMENT|DECIMAL|EOL|KEYWORD|MINUS|NAMES|OMIT|PLUS|ROOT|SEPARATOR))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(\s*)(\*units\s+(?:TAPE|LENGTH|COMPASS|BEARING|CLINO|GRADIENT|COUNTER|DEPTH|DECLINATION|X|Y|Z))(\s+)(.*)$", re.IGNORECASE|re.MULTILINE), - r'\1\2\3\4')) -regexes.append((re.compile(r"^(.*)$", re.IGNORECASE|re.MULTILINE), - r'
\1 
\n')) - -@register.filter() -@stringfilter -def survex_to_html(value, autoescape=None): - if autoescape: - value = conditional_escape(value) - for regex, sub in regexes: - print(sub) - value = regex.sub(sub, value) - return mark_safe(value) \ No newline at end of file diff --git a/core/templatetags/wiki_markup.py b/core/templatetags/wiki_markup.py deleted file mode 100644 index f1ab69d..0000000 --- a/core/templatetags/wiki_markup.py +++ /dev/null @@ -1,189 +0,0 @@ -from django import template -from django.utils.html import conditional_escape -from django.template.defaultfilters import stringfilter -from django.utils.safestring import mark_safe -from django.conf import settings -from troggle.core.models.caves import LogbookEntry, QM, Cave -import re, urllib.parse - -'''Originally for the wiki format entries, later re-used simply to clean up HTML escape chars. -Now entirely defunct. - -''' -todo = '''Checked. Not used anywhere anymore. Replaced by standard Django template filters. -''' -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 - mstar = re.match(l + "\*(.*)", line) - if mstar: - listdepth.append("\*") - return ("\n" + t, l) - if prev == "#": - t, l = wiki_list(line, listdepth) - return ("\n" + t, l) - return (line, listdepth) - -@register.filter() -@stringfilter -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 = "" - for paragraph in re.split("\n\s*?\n", value, re.DOTALL): - outValue += "

" - outValue += wiki_to_html_short(paragraph, autoescape) - outValue += "

\n" - return mark_safe(outValue) - -@register.filter() -@stringfilter -def wiki_to_html_short(value, autoescape=None): - """ - I suspect this is only used for HTML escapes. And we should be using the standard Django - filter |safe https://docs.djangoproject.com/en/dev/ref/templates/builtins/#safe - - - 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) - #deescape doubly escaped characters - value = re.sub("&(.*?);", r"&\1;", value, re.DOTALL) - #italics and bold - value = re.sub("''''([^']+)''''", r"\1", value, re.DOTALL) - value = re.sub("'b''([^']+)'''", r"\1", value, re.DOTALL) - value = re.sub("''([^']+)''", r"\1", value, re.DOTALL) - - #make headers - def headerrepl(matchobj): - number=len(matchobj.groups()[0]) - num=str(number) - if number>1: - return ''+matchobj.groups()[1]+'' - else: - print('morethanone') - return matchobj.group() - value = re.sub(r"(?m)^(=+)([^=]+)(=+)$",headerrepl,value) - - #make qm links. this takes a little doing - qmMatchPattern=settings.QM_PATTERN - def qmrepl(matchobj): - """ - A function for replacing wikicode qm links with html qm links. - Given a matchobj matching a wikilink in the format - [[QM:C204-1999-24]] - If the QM does not exist, the function will return a link for creating it. - """ - qmdict={'urlroot':settings.URL_ROOT,'cave':matchobj.groups()[2],'year':matchobj.groups()[1],'number':matchobj.groups()[3]} - try: - qm=QM.objects.get(found_by__cave__kataster_number = qmdict['cave'], - found_by__date__year = qmdict['year'], - number = qmdict['number']) - return r'%s' % (qm.get_absolute_url(), qm.code, str(qm)) - except QM.DoesNotExist: #bother aaron to make him clean up the below code - AC - try: - placeholder=LogbookEntry.objects.get(date__year=qmdict['year'],cave__kataster_number=qmdict['cave'], title__icontains='placeholder') - except LogbookEntry.DoesNotExist: - placeholder=LogbookEntry( - date='01-01'+qmdict['year'], - cave=Cave.objects.get(kataster_number=qmdict['cave']), - title='placeholder' - ) - qm=QM(found_by = placeholder, number = qmdict['number']) - return r'%s' % (qm.get_absolute_url(), qm.code, str(qm)) - - value = re.sub(qmMatchPattern,qmrepl, value, re.DOTALL) - - #make photo links for [[photo:filename]] or [[photo:filename linktext]], and - #insert photos for [[display:left photo:filename]] - photoLinkPattern="\[\[\s*photo:(?P[^\s]+)\s*(?P.*)\]\]" - photoSrcPattern="\[\[\s*display:(?P