mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-04-02 23:21:01 +01:00
comments and tidy
This commit is contained in:
@@ -42,8 +42,7 @@ class SimpleTest(SimpleTestCase):
|
|||||||
# from PIL import Image
|
# from PIL import Image
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
from troggle.core.utils import save_carefully
|
|
||||||
|
|
||||||
def test_import_parsers_survex(self):
|
def test_import_parsers_survex(self):
|
||||||
import troggle.core.models.caves as models_caves
|
import troggle.core.models.caves as models_caves
|
||||||
import troggle.core.models.survex as models_survex
|
import troggle.core.models.survex as models_survex
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ todo = """
|
|||||||
- Can we rewrite things to eliminate the CaveSlug and objects? Surely
|
- Can we rewrite things to eliminate the CaveSlug and objects? Surely
|
||||||
foreign keys work fine ?!
|
foreign keys work fine ?!
|
||||||
|
|
||||||
- Why do we have CaveAndEntrance objects ?
|
- Why do we have CaveAndEntrance objects ? These do not need to be explcit for a many:many relationship these days
|
||||||
|
|
||||||
- move the aliases list from the code and put into an editable file
|
- move the aliases list from the code and put into an editable file
|
||||||
|
|
||||||
@@ -112,12 +112,12 @@ class Cave(TroggleModel):
|
|||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
# we do not use URL_ROOT any more.
|
# we do not use URL_ROOT any more.
|
||||||
if self.kataster_number:
|
# if self.kataster_number:
|
||||||
pass
|
# pass
|
||||||
elif self.unofficial_number:
|
# elif self.unofficial_number:
|
||||||
pass
|
# pass
|
||||||
else:
|
# else:
|
||||||
self.official_name.lower()
|
# self.official_name.lower()
|
||||||
return self.url # not good Django style? NEEDS actual URL
|
return self.url # not good Django style? NEEDS actual URL
|
||||||
|
|
||||||
def url_parent(self):
|
def url_parent(self):
|
||||||
@@ -199,6 +199,8 @@ class Cave(TroggleModel):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
def writeDataFile(self):
|
def writeDataFile(self):
|
||||||
|
"""Seems to be a duplicate of file_output() ?!
|
||||||
|
REFACTOR"""
|
||||||
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")
|
||||||
|
|||||||
@@ -159,8 +159,6 @@ def write_and_commit(files, message):
|
|||||||
try:
|
try:
|
||||||
with open(filepath, mode, **kwargs) as f:
|
with open(filepath, mode, **kwargs) as f:
|
||||||
print(f"WRITING {cwd}---{filename} ")
|
print(f"WRITING {cwd}---{filename} ")
|
||||||
# as the wsgi process www-data, we have group write-access but are not owner, so cannot chmod.
|
|
||||||
# os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
|
|
||||||
f.write(content)
|
f.write(content)
|
||||||
except PermissionError:
|
except PermissionError:
|
||||||
raise WriteAndCommitError(
|
raise WriteAndCommitError(
|
||||||
@@ -278,61 +276,6 @@ def writetrogglefile(filepath, filecontent):
|
|||||||
# not catching and re-raising any exceptions yet, inc. the stderr etc.,. We should do that.
|
# not catching and re-raising any exceptions yet, inc. the stderr etc.,. We should do that.
|
||||||
|
|
||||||
|
|
||||||
# def save_carefully(objectType, coUniqueAttribs={}, otherAttribs={}):
|
|
||||||
# """Looks up instance using coUniqueAttribs and carries out the following:
|
|
||||||
# -if instance does not exist in DB: add instance to DB, return (new instance, True)
|
|
||||||
# -if instance exists in DB and was modified using Troggle: do nothing, return (existing instance, False)
|
|
||||||
# -if instance exists in DB and was not modified using Troggle: overwrite instance, return (instance, False)
|
|
||||||
|
|
||||||
# The checking is accomplished using Django's get_or_create and the new_since_parsing boolean field
|
|
||||||
# defined in core.models.TroggleModel.
|
|
||||||
|
|
||||||
# We are not using new_since_parsing - it is a fossil from Aaron Curtis's design in 2006. So it is always false.
|
|
||||||
|
|
||||||
# NOTE: this takes twice as long as simply creating a new object with the given values.
|
|
||||||
|
|
||||||
# As of Jan.2023 this function is not used anywhere in troggle.
|
|
||||||
|
|
||||||
# """
|
|
||||||
# try:
|
|
||||||
# instance, created = objectType.objects.get_or_create(defaults=otherAttribs, **coUniqueAttribs)
|
|
||||||
# except:
|
|
||||||
# print(" !! - FAIL in SAVE CAREFULLY ===================", objectType)
|
|
||||||
# print(" !! - -- objects.get_or_create()")
|
|
||||||
# print(f" !! - coUniqueAttribs:{coUniqueAttribs}\n !! - otherAttribs:{otherAttribs}")
|
|
||||||
# raise
|
|
||||||
# if not created and not instance.new_since_parsing:
|
|
||||||
# for k, v in list(
|
|
||||||
# otherAttribs.items()
|
|
||||||
# ): # overwrite the existing attributes from the logbook text (except date and title)
|
|
||||||
# setattr(instance, k, v)
|
|
||||||
# try:
|
|
||||||
# instance.save()
|
|
||||||
# except:
|
|
||||||
# print(" !! - SAVE CAREFULLY ===================", objectType)
|
|
||||||
# print(" !! - -- instance.save()")
|
|
||||||
# print(f" !! - coUniqueAttribs:{coUniqueAttribs}\n !! - otherAttribs:{otherAttribs}")
|
|
||||||
# raise
|
|
||||||
# try:
|
|
||||||
# str(instance)
|
|
||||||
# except:
|
|
||||||
# pass
|
|
||||||
# if created:
|
|
||||||
# logging.info(str(instance) + " was just added to the database for the first time. \n")
|
|
||||||
|
|
||||||
# if not created and instance.new_since_parsing:
|
|
||||||
# logging.info(
|
|
||||||
# str(instance) + " has been modified using Troggle since parsing, so the current script left it as is. \n"
|
|
||||||
# )
|
|
||||||
|
|
||||||
# if not created and not instance.new_since_parsing:
|
|
||||||
# logging.info(
|
|
||||||
# " instance:<"
|
|
||||||
# + str(instance)
|
|
||||||
# + "> existed in the database unchanged since last parse. It have been overwritten."
|
|
||||||
# )
|
|
||||||
# return (instance, created)
|
|
||||||
|
|
||||||
"""The following is a Bard converted version of Radosts's MIT copyrighted Javascript on 2023-10-27
|
"""The following is a Bard converted version of Radosts's MIT copyrighted Javascript on 2023-10-27
|
||||||
with hand-editing.
|
with hand-editing.
|
||||||
|
|
||||||
|
|||||||
@@ -648,6 +648,7 @@ def survexdir(request):
|
|||||||
"""report on all the primary survex files, per cave and per directory
|
"""report on all the primary survex files, per cave and per directory
|
||||||
"""
|
"""
|
||||||
caves = Cave.objects.all()
|
caves = Cave.objects.all()
|
||||||
|
|
||||||
survexfiles = SurvexFile.objects.all().order_by("cave")
|
survexfiles = SurvexFile.objects.all().order_by("cave")
|
||||||
for f in survexfiles:
|
for f in survexfiles:
|
||||||
f.pathbad = True
|
f.pathbad = True
|
||||||
|
|||||||
Reference in New Issue
Block a user