2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

Removing foissil: subcave and flatpages-redirects

This commit is contained in:
Philip Sargent 2020-07-22 22:14:35 +01:00
parent 190514597b
commit 427afa9ebd
8 changed files with 85 additions and 83 deletions

View File

@ -59,7 +59,7 @@ class SimpleTest(SimpleTestCase):
def test_import_parses_mix(self): def test_import_parses_mix(self):
from troggle.parsers.logbooks import GetCaveLookup from troggle.parsers.logbooks import GetCaveLookup
import troggle.settings import troggle.settings
import troggle.flatpages.models #import troggle.flatpages.models
import troggle.logbooksdump import troggle.logbooksdump
import troggle.parsers.caves import troggle.parsers.caves
import troggle.parsers.people import troggle.parsers.people

View File

@ -141,10 +141,11 @@ class SurvexBlock(models.Model):
def DayIndex(self): def DayIndex(self):
return list(self.expeditionday.survexblock_set.all()).index(self) return list(self.expeditionday.survexblock_set.all()).index(self)
class SurvexTitle(models.Model): # Fossil. No code uses this.
survexblock = models.ForeignKey('SurvexBlock',null=True, on_delete=models.SET_NULL) # class SurvexTitle(models.Model):
title = models.CharField(max_length=200) # needed by svxcavesingle.html template # survexblock = models.ForeignKey('SurvexBlock',null=True, on_delete=models.SET_NULL)
cave = models.ForeignKey('Cave', blank=True, 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 # member of a SurvexBlock

View File

@ -14,7 +14,7 @@ from django.http import HttpResponse, Http404
import troggle.settings as settings import troggle.settings as settings
import parsers.survex import parsers.survex
from troggle.core.models import Expedition, Person, PersonExpedition 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.core.models_caves import Cave, PersonTrip, LogbookEntry
from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.people import GetPersonExpeditionNameLookup

View File

@ -1,5 +1,5 @@
from troggle.flatpages.models import Redirect, EntranceRedirect #from troggle.flatpages.models import Redirect, EntranceRedirect
from django.contrib import admin from django.contrib import admin
admin.site.register(Redirect) # admin.site.register(Redirect)
admin.site.register(EntranceRedirect) # admin.site.register(EntranceRedirect)

View File

@ -1,12 +1,12 @@
from django.db import models from django.db import models
from troggle.core.models_caves import Cave, Entrance from troggle.core.models_caves import Cave, Entrance
class Redirect(models.Model): # class Redirect(models.Model):
originalURL = models.CharField(max_length=200, unique=True) # originalURL = models.CharField(max_length=200, unique=True)
newURL = models.CharField(max_length=200) # newURL = models.CharField(max_length=200)
class EntranceRedirect(models.Model): # class EntranceRedirect(models.Model):
originalURL = models.CharField(max_length=200) # originalURL = models.CharField(max_length=200)
entrance = models.ForeignKey(Entrance,on_delete=models.CASCADE) # entrance = models.ForeignKey(Entrance,on_delete=models.CASCADE)
def __str__(self): # def __str__(self):
return self.entrance.slug # return self.entrance.slug

View File

@ -8,19 +8,19 @@ from django.template import Context, loader
import django.forms as forms import django.forms as forms
from troggle.helper import login_required_if_public 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 from troggle.core.models_caves import Cave
import troggle.core.views_caves import troggle.core.views_caves
import troggle.settings as settings import troggle.settings as settings
def flatpage(request, path): def flatpage(request, path):
#print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path))) #print(" - FLATPAGES delivering the file: {} as MIME type: {}".format(path,getmimetype(path)))
try: # try:
r = Redirect.objects.get(originalURL = path) # r = Redirect.objects.get(originalURL = path)
#print(" - FLATPAGES REDIRECT the file: {} as: {}".format(path,r)) # #print(" - FLATPAGES REDIRECT the file: {} as: {}".format(path,r))
return HttpResponseRedirect(r.newURL) # Redirect after POST # return HttpResponseRedirect(r.newURL) # Redirect after POST
except Redirect.DoesNotExist: # except Redirect.DoesNotExist:
pass # pass
try: try:
r = Cave.objects.get(url = path) r = Cave.objects.get(url = path)
@ -36,11 +36,11 @@ def flatpage(request, path):
return troggle.core.views_caves.caveSlug(request, c.slug()) return troggle.core.views_caves.caveSlug(request, c.slug())
pass pass
try: # try:
r = EntranceRedirect.objects.get(originalURL = path) # r = EntranceRedirect.objects.get(originalURL = path)
return troggle.core.views_caves.entranceSlug(request, r.entrance.slug()) # return troggle.core.views_caves.entranceSlug(request, r.entrance.slug())
except EntranceRedirect.DoesNotExist: # except EntranceRedirect.DoesNotExist:
pass # pass
if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated(): if path.startswith("noinfo") and settings.PUBLIC_SITE and not request.user.is_authenticated():

View File

@ -57,7 +57,8 @@ def import_drawingsfiles():
print("-- Importing Drawings files") print("-- Importing Drawings files")
troggle.parsers.surveys.LoadDrawingFiles() troggle.parsers.surveys.LoadDrawingFiles()
def import_subcaves(): # Fossil.
print("-- Interpreting SubCaves from CaveDescriptions") # def import_subcaves():
troggle.parsers.subcaves.importAllSubcaves() # print("-- Interpreting SubCaves from CaveDescriptions")
# troggle.parsers.subcaves.importAllSubcaves()

View File

@ -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. # 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 sys
import os # import os
import re # import re
import logging # import logging
from django.conf import settings # from django.conf import settings
from troggle.core.models_caves import Cave, NewSubCave # from troggle.core.models_caves import Cave, NewSubCave
from utils import save_carefully # from utils import save_carefully
def getLinksInCaveDescription(cave): # def getLinksInCaveDescription(cave):
''' # '''
Returns all HTML <a href> tags from a given cave as a list of tuples # Returns all HTML <a href> tags from a given cave as a list of tuples
in the format ('filename.html','Description') # in the format ('filename.html','Description')
''' # '''
pattern='<a href=\"(.*?)\">(.*?)</a>' # pattern='<a href=\"(.*?)\">(.*?)</a>'
if cave.underground_description: # if cave.underground_description:
return re.findall(pattern,cave.underground_description) # return re.findall(pattern,cave.underground_description)
else: # else:
return [] # return []
def importSubcaves(cave): # def importSubcaves(cave):
for link in getLinksInCaveDescription(cave): # for link in getLinksInCaveDescription(cave):
try: # try:
subcaveFilePath=os.path.join( # subcaveFilePath=os.path.join(
settings.EXPOWEB, # settings.EXPOWEB,
os.path.dirname(cave.description_file), # os.path.dirname(cave.description_file),
link[0]) # link[0])
subcaveFile=open(subcaveFilePath,'rb') # subcaveFile=open(subcaveFilePath,'rb')
description=subcaveFile.read() # decode('iso-8859-1').encode('utf-8') # description=subcaveFile.read() # decode('iso-8859-1').encode('utf-8')
#lookupAttribs={'title':link[1], 'cave':cave} # #lookupAttribs={'title':link[1], 'cave':cave}
#nonLookupAttribs={'description':description} # #nonLookupAttribs={'description':description}
lookupAttribs={} # lookupAttribs={}
nonLookupAttribs={} # nonLookupAttribs={}
newSubcave=save_carefully(NewSubCave,lookupAttribs=lookupAttribs,nonLookupAttribs=nonLookupAttribs) # newSubcave=save_carefully(NewSubCave,lookupAttribs=lookupAttribs,nonLookupAttribs=nonLookupAttribs)
logging.info("Added " + str(newSubcave) + " to " + str(cave)) # logging.info("Added " + str(newSubcave) + " to " + str(cave))
except IOError: # except IOError:
logging.info("Subcave import couldn't open "+subcaveFilePath) # logging.info("Subcave import couldn't open "+subcaveFilePath)
def getLinksInSubcaveDescription(subcave): # def getLinksInSubcaveDescription(subcave):
pattern='<a href=\"(.*?)\">(.*?)</a>' # pattern='<a href=\"(.*?)\">(.*?)</a>'
if subcave.description: # if subcave.description:
return re.findall(pattern,subcave.description) # return re.findall(pattern,subcave.description)
else: # else:
return [] # return []
def getLinksInAllSubcaves(): # def getLinksInAllSubcaves():
bigList=[] # bigList=[]
for subcave in NewSubCave.objects.all(): # for subcave in NewSubCave.objects.all():
bigList+=getLinksInSubcaveDescription(subcave) # bigList+=getLinksInSubcaveDescription(subcave)
return bigList # return bigList
def importAllSubcaves(): # def importAllSubcaves():
for cave in Cave.objects.all(): # for cave in Cave.objects.all():
importSubcaves(cave) # importSubcaves(cave)