summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSam Wenham <sam@wenhams.co.uk>2019-02-24 13:03:34 +0000
committerSam Wenham <sam@wenhams.co.uk>2019-02-24 13:03:34 +0000
commit8f66837f6fb5b74ba3166ae6e31328f8a9e68d96 (patch)
treef5683df0d04d8decad0685198e6e76980e376ef0 /core
parent670559ec8722d8f2f5c97e93bbed1f610cc67206 (diff)
downloadtroggle-8f66837f6fb5b74ba3166ae6e31328f8a9e68d96.tar.gz
troggle-8f66837f6fb5b74ba3166ae6e31328f8a9e68d96.tar.bz2
troggle-8f66837f6fb5b74ba3166ae6e31328f8a9e68d96.zip
Make things more compatiable with newer python
Fix the expeditions list Improvements to make it compatiable with django 1.8 Bump the years to add 2018 Update the .hgignore file to ignore junk
Diffstat (limited to 'core')
-rw-r--r--core/models.py9
-rw-r--r--core/views_logbooks.py56
-rw-r--r--core/views_other.py4
-rw-r--r--core/views_survex.py18
4 files changed, 54 insertions, 33 deletions
diff --git a/core/models.py b/core/models.py
index a78e49b..f87792e 100644
--- a/core/models.py
+++ b/core/models.py
@@ -30,7 +30,7 @@ def get_related_by_wikilinks(wiki_text):
number = qmdict['number'])
res.append(qm)
except QM.DoesNotExist:
- print 'fail on '+str(wikilink)
+ print('fail on '+str(wikilink))
return res
@@ -141,7 +141,6 @@ class Person(TroggleModel):
class Meta:
verbose_name_plural = "People"
- class Meta:
ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
def __unicode__(self):
@@ -529,11 +528,11 @@ class Cave(TroggleModel):
def getCaveByReference(reference):
areaname, code = reference.split("-", 1)
- print areaname, code
+ print(areaname, code)
area = Area.objects.get(short_name = areaname)
- print area
+ print(area)
foundCaves = list(Cave.objects.filter(area = area, kataster_number = code).all()) + list(Cave.objects.filter(area = area, unofficial_number = code).all())
- print list(foundCaves)
+ print(list(foundCaves))
assert len(foundCaves) == 1
return foundCaves[0]
diff --git a/core/views_logbooks.py b/core/views_logbooks.py
index 0aee9c6..c6f9086 100644
--- a/core/views_logbooks.py
+++ b/core/views_logbooks.py
@@ -16,9 +16,18 @@ from django.template.defaultfilters import slugify
from troggle.helper import login_required_if_public
import datetime
+from django.views.generic.list import ListView
+from django.utils import timezone
-# Django uses Context, not RequestContext when you call render_to_response. We always want to use RequestContext, so that django adds the context from settings.TEMPLATE_CONTEXT_PROCESSORS. This way we automatically get necessary settings variables passed to each template. So we use a custom method, render_response instead of render_to_response. Hopefully future Django releases will make this unnecessary.
-#from troggle.alwaysUseRequestContext import render_response
+
+# Django uses Context, not RequestContext when you call render
+# to_response. We always want to use RequestContext, so that
+# django adds the context from settings.TEMPLATE_CONTEXT_PROCESSORS.
+# This way we automatically get necessary settings variables passed
+# to each template. So we use a custom method, render_response
+# instead of render_to_response. Hopefully future Django releases
+# will make this unnecessary.
+# from troggle.alwaysUseRequestContext import render_response
import re
@@ -50,13 +59,13 @@ def personindex(request):
def expedition(request, expeditionname):
- expedition = Expedition.objects.get(year=int(expeditionname))
+ this_expedition = Expedition.objects.get(year=int(expeditionname))
expeditions = Expedition.objects.all()
personexpeditiondays = [ ]
- dateditems = list(expedition.logbookentry_set.all()) + list(expedition.survexblock_set.all())
+ dateditems = list(this_expedition.logbookentry_set.all()) + list(this_expedition.survexblock_set.all())
dates = list(set([item.date for item in dateditems]))
dates.sort()
- for personexpedition in expedition.personexpedition_set.all():
+ for personexpedition in this_expedition.personexpedition_set.all():
prow = [ ]
for date in dates:
pcell = { "persontrips": PersonTrip.objects.filter(personexpedition=personexpedition,
@@ -71,21 +80,30 @@ def expedition(request, expeditionname):
message = LoadLogbookForExpedition(expedition)
return render_with_context(request,'expedition.html', {'expedition': expedition, 'expeditions':expeditions, 'personexpeditiondays':personexpeditiondays, 'message':message, 'settings':settings, 'dateditems': dateditems })
- def get_absolute_url(self):
+class ExpeditionListView(ListView):
+
+ model = Expedition
+
+ def get_context_data(self, **kwargs):
+ context = super(ExpeditionListView, self).get_context_data(**kwargs)
+ context['now'] = timezone.now()
+ return context
+
+def get_absolute_url(self):
return ('expedition', (expedition.year))
def person(request, first_name='', last_name='', ):
- person = Person.objects.get(first_name = first_name, last_name = last_name)
+ this_person = Person.objects.get(first_name = first_name, last_name = last_name)
- #This is for removing the reference to the user's profile, in case they set it to the wrong person
+ # This is for removing the reference to the user's profile, in case they set it to the wrong person
if request.method == 'GET':
if request.GET.get('clear_profile')=='True':
- person.user=None
- person.save()
+ this_person.user=None
+ this_person.save()
return HttpResponseRedirect(reverse('profiles_select_profile'))
- return render_with_context(request,'person.html', {'person': person, })
+ return render_with_context(request,'person.html', {'person': this_person, })
def GetPersonChronology(personexpedition):
@@ -115,20 +133,20 @@ def GetPersonChronology(personexpedition):
def personexpedition(request, first_name='', last_name='', year=''):
person = Person.objects.get(first_name = first_name, last_name = last_name)
- expedition = Expedition.objects.get(year=year)
- personexpedition = person.personexpedition_set.get(expedition=expedition)
+ this_expedition = Expedition.objects.get(year=year)
+ personexpedition = person.personexpedition_set.get(expedition=this_expedition)
personchronology = GetPersonChronology(personexpedition)
return render_with_context(request,'personexpedition.html', {'personexpedition': personexpedition, 'personchronology':personchronology})
def logbookentry(request, date, slug):
- logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
+ this_logbookentry = LogbookEntry.objects.filter(date=date, slug=slug)
- if len(logbookentry)>1:
- return render_with_context(request, 'object_list.html',{'object_list':logbookentry})
+ if len(this_logbookentry)>1:
+ return render_with_context(request, 'object_list.html',{'object_list':this_logbookentry})
else:
- logbookentry=logbookentry[0]
- return render_with_context(request, 'logbookentry.html', {'logbookentry': logbookentry})
+ this_logbookentry=this_logbookentry[0]
+ return render_with_context(request, 'logbookentry.html', {'logbookentry': this_logbookentry})
def logbookSearch(request, extra):
@@ -196,7 +214,7 @@ def newLogbookEntry(request, expeditionyear, pdate = None, pslug = None):
'expeditionyear': expeditionyear})
f.write(template.render(context))
f.close()
- print logbookparsers.parseAutoLogBookEntry(filename)
+ print(logbookparsers.parseAutoLogBookEntry(filename))
return HttpResponseRedirect(reverse('expedition', args=[expedition.year])) # Redirect after POST
else:
if pslug and pdate:
diff --git a/core/views_other.py b/core/views_other.py
index f9a4661..d99cc32 100644
--- a/core/views_other.py
+++ b/core/views_other.py
@@ -87,8 +87,8 @@ def downloadSurveys(request):
def downloadLogbook(request,year=None,extension=None,queryset=None):
if year:
- expedition=Expedition.objects.get(year=year)
- logbook_entries=LogbookEntry.objects.filter(expedition=expedition)
+ current_expedition=Expedition.objects.get(year=year)
+ logbook_entries=LogbookEntry.objects.filter(expedition=current_expedition)
filename='logbook'+year
elif queryset:
logbook_entries=queryset
diff --git a/core/views_survex.py b/core/views_survex.py
index 28a4370..e252095 100644
--- a/core/views_survex.py
+++ b/core/views_survex.py
@@ -77,7 +77,7 @@ class SvxForm(forms.Form):
def DiffCode(self, rcode):
code = self.GetDiscCode()
difftext = difflib.unified_diff(code.splitlines(), rcode.splitlines())
- difflist = [ diffline.strip() for diffline in difftext if not re.match("\s*$", diffline) ]
+ difflist = [ diffline.strip() for diffline in difftext if not re.match(r"\s*$", diffline) ]
return difflist
def SaveCode(self, rcode):
@@ -98,7 +98,7 @@ class SvxForm(forms.Form):
return "SAVED"
def Process(self):
- print "....\n\n\n....Processing\n\n\n"
+ print("....\n\n\n....Processing\n\n\n")
cwd = os.getcwd()
os.chdir(os.path.split(settings.SURVEX_DATA + self.data['filename'])[0])
os.system(settings.CAVERN + " --log " + settings.SURVEX_DATA + self.data['filename'] + ".svx")
@@ -137,13 +137,13 @@ def svx(request, survex_file):
if not difflist:
message = "OUTPUT FROM PROCESSING"
logmessage = form.Process()
- print logmessage
+ print(logmessage)
else:
message = "SAVE FILE FIRST"
form.data['code'] = rcode
if "save" in rform.data:
if request.user.is_authenticated():
- #print "sssavvving"
+ #print("sssavvving")
message = form.SaveCode(rcode)
else:
message = "You do not have authority to save this file"
@@ -163,7 +163,7 @@ def svx(request, survex_file):
difflist.insert(0, message)
#print [ form.data['code'] ]
- svxincludes = re.findall('\*include\s+(\S+)(?i)', form.data['code'] or "")
+ svxincludes = re.findall(r'\*include\s+(\S+)(?i)', form.data['code'] or "")
vmap = {'settings': settings,
'has_3d': os.path.isfile(settings.SURVEX_DATA + survex_file + ".3d"),
@@ -256,7 +256,7 @@ def identifycavedircontents(gcavedir):
# direct local non-database browsing through the svx file repositories
# perhaps should use the database and have a reload button for it
def survexcaveslist(request):
- cavesdir = os.path.join(settings.SURVEX_DATA, "caves")
+ cavesdir = os.path.join(settings.SURVEX_DATA, "caves-1623")
#cavesdircontents = { }
onefilecaves = [ ]
@@ -264,9 +264,11 @@ def survexcaveslist(request):
subdircaves = [ ]
# first sort the file list
- fnumlist = [ (-int(re.match("\d*", f).group(0) or "0"), f) for f in os.listdir(cavesdir) ]
+ fnumlist = [ (-int(re.match(r"\d*", f).group(0) or "0"), f) for f in os.listdir(cavesdir) ]
fnumlist.sort()
+ print(fnumlist)
+
# go through the list and identify the contents of each cave directory
for num, cavedir in fnumlist:
if cavedir in ["144", "40"]:
@@ -297,6 +299,8 @@ def survexcaveslist(request):
multifilecaves.append((survdirobj[0], survdirobj[1:]))
# single file caves
else:
+ #print("survdirobj = ")
+ #print(survdirobj)
onefilecaves.append(survdirobj[0])
return render_to_response('svxfilecavelist.html', {'settings': settings, "onefilecaves":onefilecaves, "multifilecaves":multifilecaves, "subdircaves":subdircaves })