mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 12:27:09 +00:00
ruf cleanup imports, bigly.
This commit is contained in:
@@ -1,45 +1,30 @@
|
||||
import datetime
|
||||
import json
|
||||
import operator
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import urllib
|
||||
from functools import reduce
|
||||
from pathlib import Path
|
||||
from urllib.parse import unquote
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
|
||||
from django.core.files.storage import FileSystemStorage, default_storage
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
from django.template import Context, loader
|
||||
from django.urls import reverse
|
||||
|
||||
import settings
|
||||
from troggle.core.models.caves import Cave
|
||||
from troggle.core.models.logbooks import QM, LogbookEntry # , PersonLogEntry
|
||||
from troggle.core.models.survex import DrawingFile, SurvexBlock, SurvexFile, SurvexPersonRole, Wallet
|
||||
from troggle.core.models.logbooks import LogbookEntry # , PersonLogEntry
|
||||
from troggle.core.models.survex import DrawingFile, SurvexBlock, SurvexFile, SurvexPersonRole
|
||||
from troggle.core.models.wallets import Wallet
|
||||
|
||||
# from databaseReset import reinit_db # don't do this. databaseRest runs code *at import time*
|
||||
from troggle.core.models.troggle import DataIssue, Expedition, Person, PersonExpedition
|
||||
from troggle.core.models.troggle import DataIssue, Expedition
|
||||
from troggle.core.views.caves import getCave
|
||||
from troggle.core.views.scans import caveifywallet, oldwallet
|
||||
|
||||
# from troggle import settings
|
||||
from troggle.parsers.imports import (
|
||||
import_caves,
|
||||
import_drawingsfiles,
|
||||
import_logbooks,
|
||||
import_people,
|
||||
import_QMs,
|
||||
import_survex,
|
||||
import_surveyscans,
|
||||
)
|
||||
from troggle.parsers.scans import contentsjson
|
||||
|
||||
from .auth import login_required_if_public
|
||||
@@ -194,13 +179,13 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
||||
else:
|
||||
try:
|
||||
sxpath = str(Path(sx).with_suffix(""))
|
||||
svxfile = SurvexFile.objects.get(path=sxpath)
|
||||
SurvexFile.objects.get(path=sxpath)
|
||||
except MultipleObjectsReturned:
|
||||
# can happen if connecting a wallet to a survex file.. i think..
|
||||
QSsvxfiles = SurvexFile.objects.filter(path=sxpath)
|
||||
for s in QSsvxfiles:
|
||||
print(s.path, s.cave, s.survexdirectory)
|
||||
svxfile = QSsvxfiles[0] # dont' know how this happened, fix later..
|
||||
# QSsvxfiles[0] # dont' know how this happened, fix later..
|
||||
except:
|
||||
file_complaint = (
|
||||
f"{wallet} Survex file {sx} exists, but is not registered in the database {sxpath}. How?.."
|
||||
@@ -286,7 +271,7 @@ def get_complaints(complaints, waldata, svxfiles, files, wallet, wurl):
|
||||
caveobject = None
|
||||
else:
|
||||
complaints.append(
|
||||
f'No cave ID is given. If there is no survex file, please give something, even if it is just "1623-000", "surface survey" or "scraps found in hut"'
|
||||
'No cave ID is given. If there is no survex file, please give something, even if it is just "1623-000", "surface survey" or "scraps found in hut"'
|
||||
)
|
||||
caveobject = None
|
||||
|
||||
@@ -323,7 +308,6 @@ def scanupload(request, path=None):
|
||||
Should sanitise to ensure no spurious backslashes e.g. in windows style paths"""
|
||||
waldata = {}
|
||||
if contents_path.is_file():
|
||||
create = False # yes wallet exists because JSON exists, even if no files in the surveyscans folder, or even if that folder does not exist
|
||||
with open(contents_path) as json_file:
|
||||
try:
|
||||
waldata = json.load(json_file)
|
||||
@@ -333,7 +317,7 @@ def scanupload(request, path=None):
|
||||
DataIssue.objects.create(parser="scans", message=message, url=wurl) # set URL to this wallet folder
|
||||
raise
|
||||
else: # no JSON file exists
|
||||
print(f"--- No JSON exists, so creating blank copy")
|
||||
print("--- No JSON exists, so creating blank copy")
|
||||
waldata = WALLET_BLANK_JSON.copy()
|
||||
if not waldata["survex file"]:
|
||||
try:
|
||||
@@ -347,10 +331,9 @@ def scanupload(request, path=None):
|
||||
return waldata
|
||||
|
||||
def save_json(jsondict):
|
||||
newfolder = contents_path.parent
|
||||
# print(f'--- Wallet directory in :drawings: repo {newfolder=} {jsondict}')
|
||||
if not os.path.exists(contents_path.parent):
|
||||
print(f"--- No wallet directory in :drawings: repo, so creating it")
|
||||
print("--- No wallet directory in :drawings: repo, so creating it")
|
||||
os.makedirs(contents_path.parent)
|
||||
|
||||
with open(contents_path, "w") as jfile:
|
||||
@@ -521,7 +504,7 @@ def scanupload(request, path=None):
|
||||
commit_json(wd)
|
||||
|
||||
else:
|
||||
print(f"--- INVALID JSON Update form submitted")
|
||||
print("--- INVALID JSON Update form submitted")
|
||||
print(formj.errors)
|
||||
return render(request, "errors/generic.html", {"message": formj.errors})
|
||||
|
||||
@@ -671,7 +654,7 @@ def scanupload(request, path=None):
|
||||
# else:
|
||||
# print(f' - Wallet not matching *ref {b.scanswallet=} {wallet}')
|
||||
except:
|
||||
message = f"Specified survex file not found - database may be empty, or this survex file is not *included anywhere."
|
||||
message = "Specified survex file not found - database may be empty, or this survex file is not *included anywhere."
|
||||
# return render(request, 'errors/generic.html', {'message': message})
|
||||
pass
|
||||
|
||||
@@ -704,7 +687,7 @@ def scanupload(request, path=None):
|
||||
print(f" - Setting wallet name to {names[0]}")
|
||||
elif len(names) == 0:
|
||||
waldata["name"] = ""
|
||||
print(f" - Setting wallet name blank")
|
||||
print(" - Setting wallet name blank")
|
||||
else:
|
||||
waldata["name"] = f"several, please edit: {names}"
|
||||
print(
|
||||
|
||||
Reference in New Issue
Block a user