forked from expo/troggle
clean out broken QM bits
This commit is contained in:
parent
13f3057185
commit
942cbdd4b2
@ -146,12 +146,17 @@ class Cave(TroggleModel):
|
||||
return str(self.slug())
|
||||
|
||||
def get_QMs(self):
|
||||
return QM.objects.filter(found_by__cave_slug=self.caveslug_set.all())
|
||||
'''Does not work because found_by is a string == cave_slug not an object identifier
|
||||
This chnage was made to remove tricky __get_attribute__ code whihc is hard for
|
||||
most folks to maintain and is not really necessary. Need to do a proper search for the cave.
|
||||
Seems pretty broken - all needs re-doing more cleanly.
|
||||
'''
|
||||
return QM.objects.filter(found_by__cave_slug=self.slug)
|
||||
|
||||
def new_QM_number(self, year=datetime.date.today().year):
|
||||
"""Given a cave and the current year, returns the next QM number."""
|
||||
try:
|
||||
res=QM.objects.filter(found_by__date__year=year, found_by__cave=self).order_by('-number')[0]
|
||||
res=QM.objects.filter(found_by__date__year=year, found_by__cave_slug=self.slug).order_by('-number')[0]
|
||||
except IndexError:
|
||||
return 1
|
||||
return res.number+1
|
||||
@ -379,6 +384,10 @@ class Entrance(TroggleModel):
|
||||
|
||||
class LogbookEntry(TroggleModel):
|
||||
"""Single parsed entry from Logbook
|
||||
|
||||
But what is all this__getattribute__ meta stuff for ? When is it needed ?!?
|
||||
Le'ts get rid of it and set the 'cave' attribute to a cave object elsehwhere. This is
|
||||
attempting to be Too Clever.
|
||||
"""
|
||||
LOGBOOK_ENTRY_TYPES = (
|
||||
("wiki", "Wiki style logbook"),
|
||||
@ -386,7 +395,7 @@ class LogbookEntry(TroggleModel):
|
||||
)
|
||||
date = models.DateField()#MJG wants to turn this into a datetime such that multiple Logbook entries on the same day can be ordered.ld()
|
||||
expeditionday = models.ForeignKey("ExpeditionDay", null=True,on_delete=models.SET_NULL)#MJG wants to KILL THIS (redundant information)
|
||||
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.SET_NULL) # yes this is double-
|
||||
expedition = models.ForeignKey(Expedition,blank=True, null=True,on_delete=models.SET_NULL) # yes this is double-
|
||||
title = models.CharField(max_length=settings.MAX_LOGBOOK_ENTRY_TITLE_LENGTH)
|
||||
cave_slug = models.SlugField(max_length=50, blank=True, null=True)
|
||||
place = models.CharField(max_length=100,blank=True, null=True,help_text="Only use this if you haven't chosen a cave")
|
||||
@ -399,29 +408,29 @@ class LogbookEntry(TroggleModel):
|
||||
# several PersonTrips point in to this object
|
||||
ordering = ('-date',)
|
||||
|
||||
def __getattribute__(self, item):
|
||||
if item == "cave":
|
||||
#Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey
|
||||
return CaveSlug.objects.get(slug = self.cave_slug).cave
|
||||
# parse error in python3.8
|
||||
# https://stackoverflow.com/questions/41343263/provide-classcell-example-for-python-3-6-metaclass
|
||||
#https://github.com/django/django/pull/7653
|
||||
#return TroggleModel.__getattribute__(item)
|
||||
#return super(LogbookEntry, self).__getattribute__(item) # works in py3.5, fails in 3.8
|
||||
return TroggleModel.__getattribute__(self,item) # works in py 3.5 AND in 3.8
|
||||
# def __getattribute__(self, item):
|
||||
# if item == "cave":
|
||||
# #Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey
|
||||
# return CaveSlug.objects.get(slug = self.cave_slug).cave
|
||||
# # parse error in python3.8
|
||||
# # https://stackoverflow.com/questions/41343263/provide-classcell-example-for-python-3-6-metaclass
|
||||
# #https://github.com/django/django/pull/7653
|
||||
# #return TroggleModel.__getattribute__(item)
|
||||
# #return super(LogbookEntry, self).__getattribute__(item) # works in py3.5, fails in 3.8
|
||||
# return TroggleModel.__getattribute__(self,item) # works in py 3.5 AND in 3.8
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if "cave" in list(kwargs.keys()):
|
||||
if kwargs["cave"] is not None:
|
||||
kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
||||
kwargs.pop("cave")
|
||||
# parse error in python3.8
|
||||
return TroggleModel.__init__(self, *args, **kwargs) # seems OK in 3.5 & 3.8! failure later elsewhere with 3.8
|
||||
#return TroggleModel().__init__(self, *args, **kwargs) # parses OK, fails at runtime in 3.8
|
||||
#return super().__init__(self, *args, **kwargs) # fails in 3.8
|
||||
#return super().__init__(*args, **kwargs) # works in py3.5 fails in 3.8
|
||||
#return super(LogbookEntry, self).__init__(*args, **kwargs) # works in py3.5
|
||||
#return TroggleModel.__init__(*args, **kwargs) # fails in py3.5, runtime fail in 3.8
|
||||
# def __init__(self, *args, **kwargs):
|
||||
# if "cave" in list(kwargs.keys()):
|
||||
# if kwargs["cave"] is not None:
|
||||
# kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug
|
||||
# kwargs.pop("cave")
|
||||
# # parse error in python3.8
|
||||
# return TroggleModel.__init__(self, *args, **kwargs) # seems OK in 3.5 & 3.8! failure later elsewhere with 3.8
|
||||
# #return TroggleModel().__init__(self, *args, **kwargs) # parses OK, fails at runtime in 3.8
|
||||
# #return super().__init__(self, *args, **kwargs) # fails in 3.8
|
||||
# #return super().__init__(*args, **kwargs) # works in py3.5 fails in 3.8
|
||||
# #return super(LogbookEntry, self).__init__(*args, **kwargs) # works in py3.5
|
||||
# #return TroggleModel.__init__(*args, **kwargs) # fails in py3.5, runtime fail in 3.8
|
||||
|
||||
def isLogbookEntry(self): # Function used in templates
|
||||
return True
|
||||
@ -481,13 +490,13 @@ class QM(TroggleModel):
|
||||
|
||||
def code(self):
|
||||
if self.found_by:
|
||||
return "%s-%s-%s" % (str(self.found_by.cave)[6:], self.found_by.date.year, self.number)
|
||||
return "%s-%s-%s" % (str(self.found_by.cave_slug)[6:], self.found_by.date.year, self.number)
|
||||
else:
|
||||
return "%s" % (self.number)
|
||||
|
||||
def get_absolute_url(self):
|
||||
#return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number
|
||||
return urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.found_by.cave.kataster_number,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
|
||||
return urljoin(settings.URL_ROOT, reverse('qm',kwargs={'cave_id':self.found_by.cave_slug,'year':self.found_by.date.year,'qm_id':self.number,'grade':self.grade}))
|
||||
|
||||
def get_next_by_id(self):
|
||||
return QM.objects.get(id=self.id+1)
|
||||
|
@ -18,8 +18,7 @@ from troggle.core.forms import UploadFileForm, SimpleUploadFileForm
|
||||
'''Utility functions and code to serve the control panel and individual user's
|
||||
progress and task list (deprecated as we do not have individual user login).
|
||||
|
||||
Also has code to download a logbook in a choice of formats (why?!) and to
|
||||
download all QMs (not working)
|
||||
Also has code to download a logbook in a choice of formats (why?!)
|
||||
'''
|
||||
|
||||
todo = '''
|
||||
@ -110,7 +109,7 @@ def downloadlogbook(request,year=None,extension=None,queryset=None):
|
||||
'''Constructs, from the database, a complete HTML (or TXT) formatted logbook - but TEXT ONLY
|
||||
for the current year. Formats available are HTML2005 or 2008text
|
||||
|
||||
There are no images stored in the database, so this is only a tool for a first pass, tobe followed by
|
||||
There are no images stored in the database, so this is only a tool for a first pass, to be followed by
|
||||
extensive hand-editing.
|
||||
'''
|
||||
|
||||
@ -147,40 +146,12 @@ def downloadlogbook(request,year=None,extension=None,queryset=None):
|
||||
response.write(t.render(c))
|
||||
return response
|
||||
|
||||
|
||||
def downloadQMs(request):
|
||||
# Note to self: use get_cave method for the below
|
||||
if request.method=='GET':
|
||||
try:
|
||||
cave=Cave.objects.get(kataster_number=request.GET['cave_id'])
|
||||
except Cave.DoesNotExist:
|
||||
cave=Cave.objects.get(name=request.GET['cave_id'])
|
||||
|
||||
from export import toqms
|
||||
|
||||
response = HttpResponse(content_type='text/csv')
|
||||
response['Content-Disposition'] = 'attachment; filename=qm.csv'
|
||||
toqms.writeQmTable(response,cave)
|
||||
return response
|
||||
|
||||
def ajax_test(request):
|
||||
post_text = request.POST['post_data']
|
||||
return HttpResponse("{'response_text': '"+post_text+" recieved.'}",
|
||||
content_type="application/json")
|
||||
|
||||
def eyecandy(request):
|
||||
return
|
||||
|
||||
def ajax_QM_number(request):
|
||||
res=""
|
||||
if request.method=='POST':
|
||||
cave=Cave.objects.get(id=request.POST['cave'])
|
||||
print(cave)
|
||||
exp=Expedition.objects.get(pk=request.POST['year'])
|
||||
print(exp)
|
||||
res=cave.new_QM_number(exp.year)
|
||||
|
||||
return HttpResponse(res)
|
||||
|
||||
@login_required_if_public
|
||||
def scanupload(request, year='2050'):
|
||||
|
@ -1,6 +1,6 @@
|
||||
<p>{% if cave.get_QMs %}
|
||||
<h2>Question marks</h2>
|
||||
<h2>Question marks for {{cave.kataster_number}} - {{cave.official_name|safe}} - {{cave.unofficial_number}}</h2>
|
||||
<h3>Extant</h3>
|
||||
<p>{% if cave.get_QMs %}
|
||||
<ul id="cavelist">
|
||||
{% for QM in cave.get_QMs %}
|
||||
{% if QM.ticked_off_by %}
|
||||
|
@ -110,31 +110,6 @@
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr>
|
||||
<td>qms to qms.csv</td><td>
|
||||
<form name="export_qms" method="get" action="downloadqms">
|
||||
|
||||
<!--This is for choosing caves by area (drilldown).
|
||||
|
||||
<select id="qmcaveareachooser" class="searchable" >
|
||||
</select>
|
||||
|
||||
-->
|
||||
|
||||
Choose a cave.
|
||||
<select name="cave_id" id="qmcavechooser">
|
||||
|
||||
{% for cave in caves %}
|
||||
<option value="{{cave.kataster_number}}">{{cave}}
|
||||
</option>
|
||||
{% endfor %}
|
||||
|
||||
</select>
|
||||
|
||||
<input type="submit" value="Download"/>
|
||||
</form>
|
||||
</td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
|
7
urls.py
7
urls.py
@ -11,7 +11,7 @@ from django.urls import reverse, resolve
|
||||
from troggle.core.views import caves, statistics, survex
|
||||
from troggle.core.views.surveys import scansingle, singlewallet, allwallets, dwgdata, dwgfilesingle, dwgfileupload
|
||||
from troggle.core.views.other import troggle404, frontpage, todos, controlpanel, frontpage, scanupload
|
||||
from troggle.core.views.other import downloadlogbook, ajax_QM_number, downloadQMs
|
||||
from troggle.core.views.other import downloadlogbook
|
||||
from troggle.core.views.caves import ent, cavepage
|
||||
from troggle.core.views.logbooks import get_logbook_entries, logbookentry, logbookSearch
|
||||
from troggle.core.views.logbooks import personindex, person, get_people
|
||||
@ -155,11 +155,8 @@ trogglepatterns = [
|
||||
|
||||
|
||||
# QMs pages - must precede other /caves pages
|
||||
re_path(r'^cave/qms/([^/]+)/?$', caves.caveQMs), # blank page usually
|
||||
re_path(r'^cave/qms/([^/]+)/?$', caves.caveQMs), # Broken- QMs have no proper link to cave id
|
||||
re_path(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d*)(?P<grade>[ABCDX]?)?$', caves.qm, name="qm"),
|
||||
re_path(r'^cave/(?P<cave_id>[^/]+)/qm\.csv/?$', downloadQMs, name="downloadqms"),
|
||||
re_path(r'^newqmnumber/?$', ajax_QM_number, ), # blank page if no ch given
|
||||
# re_path(r'^downloadqms$', other.downloadQMs), # MultiValueDictKeyError
|
||||
|
||||
# Prospecting Guide document
|
||||
re_path(r'^prospecting_guide/$', prospecting),
|
||||
|
Loading…
Reference in New Issue
Block a user