From 427afa9ebd6f8712f5e993d8faad5fb6feca298d Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Wed, 22 Jul 2020 22:14:35 +0100 Subject: [PATCH] Removing foissil: subcave and flatpages-redirects --- core/TESTS/tests.py | 2 +- core/models_survex.py | 9 ++-- core/views_survex.py | 2 +- flatpages/admin.py | 6 +-- flatpages/models.py | 16 +++---- flatpages/views.py | 24 +++++----- parsers/imports.py | 7 +-- parsers/subcaves.py | 102 +++++++++++++++++++++--------------------- 8 files changed, 85 insertions(+), 83 deletions(-) diff --git a/core/TESTS/tests.py b/core/TESTS/tests.py index a0517db..446bd69 100644 --- a/core/TESTS/tests.py +++ b/core/TESTS/tests.py @@ -59,7 +59,7 @@ class SimpleTest(SimpleTestCase): def test_import_parses_mix(self): from troggle.parsers.logbooks import GetCaveLookup import troggle.settings - import troggle.flatpages.models + #import troggle.flatpages.models import troggle.logbooksdump import troggle.parsers.caves import troggle.parsers.people diff --git a/core/models_survex.py b/core/models_survex.py index 7d3562d..1330f75 100644 --- a/core/models_survex.py +++ b/core/models_survex.py @@ -141,10 +141,11 @@ class SurvexBlock(models.Model): def DayIndex(self): return list(self.expeditionday.survexblock_set.all()).index(self) -class SurvexTitle(models.Model): - survexblock = models.ForeignKey('SurvexBlock',null=True, on_delete=models.SET_NULL) - title = models.CharField(max_length=200) # needed by svxcavesingle.html template - cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL) +# Fossil. No code uses this. +# class SurvexTitle(models.Model): + # survexblock = models.ForeignKey('SurvexBlock',null=True, on_delete=models.SET_NULL) + # title = models.CharField(max_length=200) # needed by svxcavesingle.html template + # cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL) # # member of a SurvexBlock diff --git a/core/views_survex.py b/core/views_survex.py index 76e79dc..79817c9 100644 --- a/core/views_survex.py +++ b/core/views_survex.py @@ -14,7 +14,7 @@ from django.http import HttpResponse, Http404 import troggle.settings as settings import parsers.survex from troggle.core.models import Expedition, Person, PersonExpedition -from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexFile, SurvexDirectory #, SurvexTitle +from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexFile, SurvexDirectory from troggle.core.models_caves import Cave, PersonTrip, LogbookEntry from troggle.parsers.people import GetPersonExpeditionNameLookup diff --git a/flatpages/admin.py b/flatpages/admin.py index 2bb1f84..ddb9ab2 100644 --- a/flatpages/admin.py +++ b/flatpages/admin.py @@ -1,5 +1,5 @@ -from troggle.flatpages.models import Redirect, EntranceRedirect +#from troggle.flatpages.models import Redirect, EntranceRedirect from django.contrib import admin -admin.site.register(Redirect) -admin.site.register(EntranceRedirect) +# admin.site.register(Redirect) +# admin.site.register(EntranceRedirect) diff --git a/flatpages/models.py b/flatpages/models.py index 7808f09..08d769a 100644 --- a/flatpages/models.py +++ b/flatpages/models.py @@ -1,12 +1,12 @@ from django.db import models from troggle.core.models_caves import Cave, Entrance -class Redirect(models.Model): - originalURL = models.CharField(max_length=200, unique=True) - newURL = models.CharField(max_length=200) +# class Redirect(models.Model): + # originalURL = models.CharField(max_length=200, unique=True) + # newURL = models.CharField(max_length=200) -class EntranceRedirect(models.Model): - originalURL = models.CharField(max_length=200) - entrance = models.ForeignKey(Entrance,on_delete=models.CASCADE) - def __str__(self): - return self.entrance.slug +# class EntranceRedirect(models.Model): + # originalURL = models.CharField(max_length=200) + # entrance = models.ForeignKey(Entrance,on_delete=models.CASCADE) + # def __str__(self): + # return self.entrance.slug diff --git a/flatpages/views.py b/flatpages/views.py index 32ab802..8194b37 100644 --- a/flatpages/views.py +++ b/flatpages/views.py @@ -8,19 +8,19 @@ from django.template import Context, loader import django.forms as forms from troggle.helper import login_required_if_public -from troggle.flatpages.models import Redirect, EntranceRedirect +#from troggle.flatpages.models import Redirect, EntranceRedirect from troggle.core.models_caves import Cave import troggle.core.views_caves import troggle.settings as settings def flatpage(request, path): #print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path))) - try: - r = Redirect.objects.get(originalURL = path) - #print(" - FLATPAGES REDIRECT the file: {} as: {}".format(path,r)) - return HttpResponseRedirect(r.newURL) # Redirect after POST - except Redirect.DoesNotExist: - pass + # try: + # r = Redirect.objects.get(originalURL = path) + # #print(" - FLATPAGES REDIRECT the file: {} as: {}".format(path,r)) + # return HttpResponseRedirect(r.newURL) # Redirect after POST + # except Redirect.DoesNotExist: + # pass try: r = Cave.objects.get(url = path) @@ -36,11 +36,11 @@ def flatpage(request, path): return troggle.core.views_caves.caveSlug(request, c.slug()) pass - try: - r = EntranceRedirect.objects.get(originalURL = path) - return troggle.core.views_caves.entranceSlug(request, r.entrance.slug()) - except EntranceRedirect.DoesNotExist: - pass + # try: + # r = EntranceRedirect.objects.get(originalURL = path) + # return troggle.core.views_caves.entranceSlug(request, r.entrance.slug()) + # except EntranceRedirect.DoesNotExist: + # pass if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated(): diff --git a/parsers/imports.py b/parsers/imports.py index 8d13e86..7c83d90 100644 --- a/parsers/imports.py +++ b/parsers/imports.py @@ -57,7 +57,8 @@ def import_drawingsfiles(): print("-- Importing Drawings files") troggle.parsers.surveys.LoadDrawingFiles() -def import_subcaves(): - print("-- Interpreting SubCaves from CaveDescriptions") - troggle.parsers.subcaves.importAllSubcaves() +# Fossil. +# def import_subcaves(): + # print("-- Interpreting SubCaves from CaveDescriptions") + # troggle.parsers.subcaves.importAllSubcaves() diff --git a/parsers/subcaves.py b/parsers/subcaves.py index ef1a0c2..89aa9b6 100644 --- a/parsers/subcaves.py +++ b/parsers/subcaves.py @@ -1,60 +1,60 @@ -''' -This module is the part of troggle that parses descriptions of cave parts (subcaves) from the legacy html files and saves them in the troggle database as instances of the model Subcave. Unfortunately, this parser can not be very flexible because the legacy format is poorly structured. -''' -import sys -import os -import re -import logging +# ''' +# This module is the part of troggle that parses descriptions of cave parts (subcaves) from the legacy html files and saves them in the troggle database as instances of the model Subcave. Unfortunately, this parser can not be very flexible because the legacy format is poorly structured. +# ''' +# import sys +# import os +# import re +# import logging -from django.conf import settings +# from django.conf import settings -from troggle.core.models_caves import Cave, NewSubCave -from utils import save_carefully +# from troggle.core.models_caves import Cave, NewSubCave +# from utils import save_carefully -def getLinksInCaveDescription(cave): - ''' - Returns all HTML tags from a given cave as a list of tuples - in the format ('filename.html','Description') - ''' - pattern='(.*?)' - if cave.underground_description: - return re.findall(pattern,cave.underground_description) - else: - return [] +# def getLinksInCaveDescription(cave): + # ''' + # Returns all HTML tags from a given cave as a list of tuples + # in the format ('filename.html','Description') + # ''' + # pattern='(.*?)' + # if cave.underground_description: + # return re.findall(pattern,cave.underground_description) + # else: + # return [] -def importSubcaves(cave): - for link in getLinksInCaveDescription(cave): - try: - subcaveFilePath=os.path.join( - settings.EXPOWEB, - os.path.dirname(cave.description_file), - link[0]) - subcaveFile=open(subcaveFilePath,'rb') - description=subcaveFile.read() # decode('iso-8859-1').encode('utf-8') +# def importSubcaves(cave): + # for link in getLinksInCaveDescription(cave): + # try: + # subcaveFilePath=os.path.join( + # settings.EXPOWEB, + # os.path.dirname(cave.description_file), + # link[0]) + # subcaveFile=open(subcaveFilePath,'rb') + # description=subcaveFile.read() # decode('iso-8859-1').encode('utf-8') - #lookupAttribs={'title':link[1], 'cave':cave} - #nonLookupAttribs={'description':description} - lookupAttribs={} - nonLookupAttribs={} - newSubcave=save_carefully(NewSubCave,lookupAttribs=lookupAttribs,nonLookupAttribs=nonLookupAttribs) + # #lookupAttribs={'title':link[1], 'cave':cave} + # #nonLookupAttribs={'description':description} + # lookupAttribs={} + # nonLookupAttribs={} + # newSubcave=save_carefully(NewSubCave,lookupAttribs=lookupAttribs,nonLookupAttribs=nonLookupAttribs) - logging.info("Added " + str(newSubcave) + " to " + str(cave)) - except IOError: - logging.info("Subcave import couldn't open "+subcaveFilePath) + # logging.info("Added " + str(newSubcave) + " to " + str(cave)) + # except IOError: + # logging.info("Subcave import couldn't open "+subcaveFilePath) -def getLinksInSubcaveDescription(subcave): - pattern='(.*?)' - if subcave.description: - return re.findall(pattern,subcave.description) - else: - return [] +# def getLinksInSubcaveDescription(subcave): + # pattern='(.*?)' + # if subcave.description: + # return re.findall(pattern,subcave.description) + # else: + # return [] -def getLinksInAllSubcaves(): - bigList=[] - for subcave in NewSubCave.objects.all(): - bigList+=getLinksInSubcaveDescription(subcave) - return bigList +# def getLinksInAllSubcaves(): + # bigList=[] + # for subcave in NewSubCave.objects.all(): + # bigList+=getLinksInSubcaveDescription(subcave) + # return bigList -def importAllSubcaves(): - for cave in Cave.objects.all(): - importSubcaves(cave) +# def importAllSubcaves(): + # for cave in Cave.objects.all(): + # importSubcaves(cave)