forked from expo/troggle
Extend wallets by cave report
This commit is contained in:
@@ -26,6 +26,14 @@ from django.shortcuts import render
|
||||
from troggle.core.models.troggle import TroggleModel, Person, Expedition, DataIssue
|
||||
from troggle.core.models.survex import SurvexStation
|
||||
from troggle.core.utils import writetrogglefile
|
||||
from troggle.core.utils import TROG
|
||||
|
||||
# Us ethe TROG global object to cache teh cave lookup list
|
||||
Gcavelookup = TROG['caves']['gcavelookup']
|
||||
Gcave_count = TROG['caves']['gcavecount']
|
||||
|
||||
Gcavelookup = None
|
||||
Gcave_count = None
|
||||
|
||||
'''The model declarations for Areas, Caves and Entrances. Also LogBookENtry, QM, PersonTrip
|
||||
'''
|
||||
@@ -564,8 +572,6 @@ class PersonTrip(TroggleModel):
|
||||
return f'{self.personexpedition} ({self.logbook_entry.date})'
|
||||
|
||||
|
||||
Gcavelookup = None
|
||||
Gcave_count = None
|
||||
def GetCaveLookup():
|
||||
"""A very relaxed way of finding probably the right cave given almost any string which might serve to identify it
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
from urllib.parse import urljoin
|
||||
import re
|
||||
import json
|
||||
from urllib.parse import urljoin
|
||||
from pathlib import Path
|
||||
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
@@ -160,6 +162,9 @@ class SurvexPersonRole(models.Model):
|
||||
return str(self.person) + " - " + str(self.survexblock)
|
||||
|
||||
class Wallet(models.Model):
|
||||
'''We do not keep the JSON values in the database, we query them afresh each time,
|
||||
but we will change this when we need to do a Django query on e.g. personame
|
||||
'''
|
||||
fpath = models.CharField(max_length=200)
|
||||
walletname = models.CharField(max_length=200)
|
||||
|
||||
@@ -169,6 +174,31 @@ class Wallet(models.Model):
|
||||
def get_absolute_url(self):
|
||||
return urljoin(settings.URL_ROOT, reverse('singlewallet', kwargs={"path":re.sub("#", "%23", self.walletname)}))
|
||||
|
||||
def get_json(self):
|
||||
jsonfile = Path(self.fpath, 'contents.json')
|
||||
if not Path(jsonfile).is_file():
|
||||
print(f'{jsonfile} is not a file')
|
||||
return None
|
||||
else:
|
||||
with open(jsonfile) as json_f:
|
||||
try:
|
||||
waldata = json.load(json_f)
|
||||
except:
|
||||
wurl = f"/scanupload/{self.walletname}" # .replace('#', ':')
|
||||
message = f"! {str(self.walletname)} Failed to load {jsonfile} JSON file"
|
||||
print(message)
|
||||
raise
|
||||
|
||||
return waldata
|
||||
|
||||
def date(self):
|
||||
jsondata = self.get_json()
|
||||
return jsondata["date"]
|
||||
|
||||
def name(self):
|
||||
jsondata = self.get_json()
|
||||
return jsondata["name"]
|
||||
|
||||
def __str__(self):
|
||||
return str(self.walletname) + " (Wallet)"
|
||||
|
||||
@@ -189,7 +219,7 @@ class SingleScan(models.Model):
|
||||
class DrawingFile(models.Model):
|
||||
dwgpath = models.CharField(max_length=200)
|
||||
dwgname = models.CharField(max_length=200)
|
||||
manywallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files
|
||||
dwgwallets = models.ManyToManyField("Wallet") # implicitly links via folders to scans to SVX files
|
||||
scans = models.ManyToManyField("SingleScan") # implicitly links via scans to SVX files
|
||||
dwgcontains = models.ManyToManyField("DrawingFile") # case when its a frame type
|
||||
filesize = models.IntegerField(default=0)
|
||||
|
||||
Reference in New Issue
Block a user