forked from expo/troggle
Populate blank wallet fields with survex data
This commit is contained in:
parent
bc3da1182b
commit
724234949f
@ -191,6 +191,7 @@ class Wallet(models.Model):
|
|||||||
|
|
||||||
return waldata
|
return waldata
|
||||||
|
|
||||||
|
# Yes this is horribly, horribly inefficient, esp. for a page that have date, people and cave in it
|
||||||
def date(self):
|
def date(self):
|
||||||
jsondata = self.get_json()
|
jsondata = self.get_json()
|
||||||
return jsondata["date"]
|
return jsondata["date"]
|
||||||
@ -199,12 +200,16 @@ class Wallet(models.Model):
|
|||||||
jsondata = self.get_json()
|
jsondata = self.get_json()
|
||||||
return jsondata["people"]
|
return jsondata["people"]
|
||||||
|
|
||||||
|
def cave(self):
|
||||||
|
jsondata = self.get_json()
|
||||||
|
return jsondata["cave"]
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
jsondata = self.get_json()
|
jsondata = self.get_json()
|
||||||
return jsondata["name"]
|
return jsondata["name"]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return str(self.walletname) + " (Wallet)"
|
return "[" + str(self.walletname) + " (Wallet)]"
|
||||||
|
|
||||||
class SingleScan(models.Model):
|
class SingleScan(models.Model):
|
||||||
ffile = models.CharField(max_length=200)
|
ffile = models.CharField(max_length=200)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os, stat
|
import os, stat
|
||||||
import re
|
import re
|
||||||
|
import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urljoin, unquote as urlunquote
|
from urllib.parse import urljoin, unquote as urlunquote
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
@ -8,7 +9,7 @@ from django.conf import settings
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from troggle.core.models.survex import Wallet, SingleScan
|
from troggle.core.models.survex import Wallet, SingleScan, SurvexBlock
|
||||||
from troggle.core.models.caves import GetCaveLookup
|
from troggle.core.models.caves import GetCaveLookup
|
||||||
from troggle.core.views.expo import getmimetype
|
from troggle.core.views.expo import getmimetype
|
||||||
#import parsers.surveys
|
#import parsers.surveys
|
||||||
@ -21,9 +22,43 @@ need to check if inavlid query string is invalid, or produces multiple replies
|
|||||||
and render a user-friendly error page.
|
and render a user-friendly error page.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
def populatewallet(w):
|
||||||
|
'''Copy survex data here just for display, not permanently
|
||||||
|
'''
|
||||||
|
# {% for personrole in wallet.survexblock.survexpersonrole_set.all %}
|
||||||
|
# {% if personrole.personexpedition %}
|
||||||
|
# <a href="{{personrole.personexpedition.get_absolute_url}}">{{personrole.personname}}</a>
|
||||||
|
# {% else %}
|
||||||
|
# {{personrole.personname}}
|
||||||
|
# {% endif %}
|
||||||
|
# {% endfor %}
|
||||||
|
|
||||||
|
survexpeople = []
|
||||||
|
blocks = SurvexBlock.objects.filter(scanswallet = w)
|
||||||
|
for b in blocks:
|
||||||
|
for personrole in b.survexpersonrole_set.all():
|
||||||
|
survexpeople.append(personrole.personname)
|
||||||
|
w.people = list(set(survexpeople)) # remove duplicates
|
||||||
|
|
||||||
|
def datewallet(w, earliest):
|
||||||
|
blocks = SurvexBlock.objects.filter(scanswallet = w)
|
||||||
|
for b in blocks:
|
||||||
|
if b.date < earliest:
|
||||||
|
earliest = b.date
|
||||||
|
w.date = earliest
|
||||||
|
|
||||||
|
def caveifywallet(w):
|
||||||
|
print('*')
|
||||||
|
blocks = SurvexBlock.objects.filter(scanswallet = w)
|
||||||
|
for b in blocks:
|
||||||
|
# NB b.cave is not populated by parser. Use b.survexfile.cave instead, or we could parse b.survexpath
|
||||||
|
if b.survexfile.cave:
|
||||||
|
w.cave = b.survexfile.cave # just gets the last one, randomly
|
||||||
|
print(w.cave)
|
||||||
|
|
||||||
|
|
||||||
def walletslistyear(request, year):
|
def walletslistyear(request, year):
|
||||||
'''Page which displays a list of all the wallets in a specific year
|
'''Page which displays a list of all the wallets in a specific year - TO BE WRITTEN
|
||||||
'''
|
'''
|
||||||
if year < 1976 or year > 2050:
|
if year < 1976 or year > 2050:
|
||||||
return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'})
|
return render(request, 'errors/generic.html', {'message': 'Year out of range. Must be between 1976 and 2050'})
|
||||||
@ -35,16 +70,38 @@ def walletslistyear(request, year):
|
|||||||
def cavewallets(request, caveid):
|
def cavewallets(request, caveid):
|
||||||
'''Returns all the wallets for just one cave
|
'''Returns all the wallets for just one cave
|
||||||
'''
|
'''
|
||||||
|
|
||||||
Gcavelookup = GetCaveLookup()
|
Gcavelookup = GetCaveLookup()
|
||||||
if caveid in Gcavelookup:
|
if caveid in Gcavelookup:
|
||||||
cave = Gcavelookup[caveid]
|
cave = Gcavelookup[caveid]
|
||||||
else:
|
else:
|
||||||
return render(request,'errors/badslug.html', {'badslug': caveid})
|
return render(request,'errors/badslug.html', {'badslug': caveid})
|
||||||
|
|
||||||
|
earliest = datetime.datetime.now().date()
|
||||||
|
|
||||||
# remove duplication. SOrting is done in the template
|
# remove duplication. SOrting is done in the template
|
||||||
wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave)) # NB a filtered set
|
wallets = set(Wallet.objects.filter(survexblock__survexfile__cave=cave)) # NB a filtered set
|
||||||
manywallets = list(wallets)
|
manywallets = list(wallets)
|
||||||
|
|
||||||
|
|
||||||
|
for w in manywallets:
|
||||||
|
wp = w.people()
|
||||||
|
if not wp: # an -empty list
|
||||||
|
populatewallet(w)
|
||||||
|
else:
|
||||||
|
if len(wp) == 1:
|
||||||
|
nobody = wp[0].lower()
|
||||||
|
if nobody == 'unknown' or nobody == 'nobody' or nobody == ' ':
|
||||||
|
populatewallet(w)
|
||||||
|
|
||||||
|
if not w.date():
|
||||||
|
datewallet(w, earliest)
|
||||||
|
|
||||||
|
c = w.cave()
|
||||||
|
|
||||||
|
if not c:
|
||||||
|
caveifywallet(w)
|
||||||
|
|
||||||
return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave})
|
return render(request, 'cavewallets.html', { 'manywallets':manywallets, 'settings': settings, 'cave': cave})
|
||||||
|
|
||||||
def oldwallet(request, path):
|
def oldwallet(request, path):
|
||||||
|
@ -12,7 +12,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
|
|||||||
<p>This lists all the files in a wallet, some of which may not be for this specific cave.
|
<p>This lists all the files in a wallet, some of which may not be for this specific cave.
|
||||||
|
|
||||||
<table width=95%>
|
<table width=95%>
|
||||||
<tr><th>Wallet</th><th>Wallet Date</th><th>Wallet Name</th><th>People</th><th>Scans</th><th>Survex blocks</th><th>Survex dates</th><th>Drawings using these scans</th></tr>
|
<tr><th>Wallet</th><th>Wallet Date</th><th>Wallet Name</th><th>People</th><th>Cave</th><th>Scans</th><th>Survex blocks</th><th>Drawings using these scans</th></tr>
|
||||||
{% for wallet in manywallets|dictsort:"walletname" %}
|
{% for wallet in manywallets|dictsort:"walletname" %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td>
|
<td style="padding:2px"><a href="{{wallet.get_absolute_url}}">{{wallet.walletname}}</a></td>
|
||||||
@ -20,6 +20,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
|
|||||||
<td style="padding:2px">{{wallet.date}}</td>
|
<td style="padding:2px">{{wallet.date}}</td>
|
||||||
<td style="padding:2px">{{wallet.name}}</td>
|
<td style="padding:2px">{{wallet.name}}</td>
|
||||||
<td style="padding:2px">{{wallet.people}}</td>
|
<td style="padding:2px">{{wallet.people}}</td>
|
||||||
|
<td style="padding:2px">{{wallet.cave}}</td>
|
||||||
|
|
||||||
<td align="right" style="padding:2px">{{wallet.singlescan_set.all|length}}</td>
|
<td align="right" style="padding:2px">{{wallet.singlescan_set.all|length}}</td>
|
||||||
<td style="padding:2px">
|
<td style="padding:2px">
|
||||||
@ -27,11 +28,7 @@ traced to produce Tunnel or Therion drawings and eventually the final complete c
|
|||||||
<a href="{% url "svx" survexblock.survexfile.path %}">{{survexblock}}</a>
|
<a href="{% url "svx" survexblock.survexfile.path %}">{{survexblock}}</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
<td style="padding:2px">
|
|
||||||
{% for survexblock in wallet.survexblock_set.all %}
|
|
||||||
{{survexblock.date}}
|
|
||||||
{% endfor %}
|
|
||||||
</td>
|
|
||||||
<td style="padding:2px">
|
<td style="padding:2px">
|
||||||
{% for drawing in wallet.drawingfile_set.all %}
|
{% for drawing in wallet.drawingfile_set.all %}
|
||||||
<a href="{% url "dwgfilesingle" drawing.dwgpath %}">{{drawing.dwgpath}}</a><br>
|
<a href="{% url "dwgfilesingle" drawing.dwgpath %}">{{drawing.dwgpath}}</a><br>
|
||||||
|
Loading…
Reference in New Issue
Block a user