diff options
Diffstat (limited to 'expo')
-rw-r--r-- | expo/models.py | 122 | ||||
-rw-r--r-- | expo/view_surveys.py | 120 | ||||
-rw-r--r-- | expo/views.py | 11 | ||||
-rw-r--r-- | expo/views_caves.py | 7 | ||||
-rw-r--r-- | expo/views_logbooks.py | 7 | ||||
-rw-r--r-- | expo/views_other.py | 2 |
6 files changed, 186 insertions, 83 deletions
diff --git a/expo/models.py b/expo/models.py index 98b5d2b..aa84110 100644 --- a/expo/models.py +++ b/expo/models.py @@ -23,6 +23,7 @@ class Expedition(models.Model): class Meta:
ordering = ('year',)
+ # lose these two functions (inelegant, and we may create a file with the dates that we can load from)
def GuessDateFrom(self):
try:
return self.logbookentry_set.order_by('date')[0].date
@@ -59,13 +60,17 @@ class Person(models.Model): is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.")
mug_shot = models.CharField(max_length=100, blank=True,null=True)
blurb = models.TextField(blank=True,null=True)
+
href = models.CharField(max_length=200)
+ orderref = models.CharField(max_length=200) # for alphabetic
+ notability = models.FloatField() # for listing the top 20 people
+ bisnotable = models.BooleanField()
user = models.ForeignKey(User, unique=True, null=True, blank=True)
class Meta:
verbose_name_plural = "People"
class Meta:
- ordering = ('last_name', 'first_name')
+ ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name')
def __unicode__(self):
if self.last_name:
@@ -78,6 +83,15 @@ class Person(models.Model): def Lastexpedition(self):
return self.personexpedition_set.order_by('-expedition')[0]
+ def Sethref(self):
+ if self.last_name:
+ self.href = self.first_name.lower() + "_" + self.last_name.lower()
+ self.orderref = self.last_name + " " + self.first_name
+ else:
+ self.href = self.first_name.lower()
+ self.orderref = self.first_name
+ self.notability = 0.0 # set temporarily
+
class PersonExpedition(models.Model):
expedition = models.ForeignKey(Expedition)
@@ -94,7 +108,6 @@ class PersonExpedition(models.Model): res[-1]['roles'] += ", " + str(personrole.role)
else:
res.append({'date':personrole.survex_block.date, 'survexpath':personrole.survex_block.survexpath, 'roles':str(personrole.role)})
- print res
return res
class Meta:
@@ -117,18 +130,8 @@ class PersonExpedition(models.Model): # needs converting dict into list
return sorted(res.items())
-
- # deprecated
- def GetPossibleNameForms(self):
- res = [ ]
- if self.person.last_name:
- res.append("%s %s" % (self.person.first_name, self.person.last_name))
- res.append("%s %s" % (self.person.first_name, self.person.last_name[0]))
- res.append(self.person.first_name)
- if self.nickname:
- res.append(self.nickname)
- return res
-
+ # don't use tabs.
+ # possibly not useful functions anyway
def ListDays(self):
if self.date_from and self.date_to:
res=[]
@@ -156,13 +159,52 @@ class PersonExpedition(models.Model): return self.person.first_name
-#class LogbookSentanceRating(models.Model):
-# rating = models.IntegerField()
-# person_trip = models.ForeignKey(PersonTrip)
-# sentance_number = models.IntegerField()
+class LogbookEntry(models.Model):
+ date = models.DateField()
+ expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
+ author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip
+ title = models.CharField(max_length=200)
+ cave = models.ForeignKey('Cave',blank=True,null=True)
+ place = models.CharField(max_length=100,blank=True,null=True)
+ text = models.TextField()
+ href = models.CharField(max_length=100)
-# def __unicode__(self):
-# return person_trip
+ # turn these into functions
+ logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', blank=True,null=True)
+ logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True)
+
+ class Meta:
+ verbose_name_plural = "Logbook Entries"
+ # several PersonTrips point in to this object
+ class Meta:
+ ordering = ('-date',)
+
+ def __unicode__(self):
+ return "%s: (%s)" % (self.date, self.title)
+
+
+class PersonTrip(models.Model):
+ person_expedition = models.ForeignKey(PersonExpedition)
+
+ # this will be a foreign key of the place(s) the trip went through
+ # possibly a trip has a plurality of triplets pointing into it
+ place = models.CharField(max_length=100)
+ # should add cave thing here (copied from logbook maybe)
+ date = models.DateField()
+ time_underground = models.FloatField()
+ logbook_entry = models.ForeignKey(LogbookEntry)
+ is_logbook_entry_author = models.BooleanField()
+
+ persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)
+ persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)
+
+ def __unicode__(self):
+ return "%s %s (%s)" % (self.person_expedition, self.place, self.date)
+
+
+#
+# move following classes into models_cave
+#
class Area(models.Model):
short_name = models.CharField(max_length=100)
@@ -266,46 +308,6 @@ class Cave(models.Model): res += "–" + prevR
return res
-class LogbookEntry(models.Model):
- date = models.DateField()
- expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
- author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip
- title = models.CharField(max_length=200)
- cave = models.ForeignKey(Cave,blank=True,null=True)
- place = models.CharField(max_length=100,blank=True,null=True)
- text = models.TextField()
- href = models.CharField(max_length=100)
-
- # turn these into functions
- logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', blank=True,null=True)
- logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True)
-
- class Meta:
- verbose_name_plural = "Logbook Entries"
- # several PersonTrips point in to this object
- class Meta:
- ordering = ('-date',)
-
- def __unicode__(self):
- return "%s: (%s)" % (self.date, self.title)
-
-class PersonTrip(models.Model):
- person_expedition = models.ForeignKey(PersonExpedition)
-
- # this will be a foreign key of the place(s) the trip went through
- # possibly a trip has a plurality of triplets pointing into it
- place = models.CharField(max_length=100)
- # should add cave thing here (copied from logbook maybe)
- date = models.DateField()
- time_underground = models.FloatField()
- logbook_entry = models.ForeignKey(LogbookEntry)
- is_logbook_entry_author = models.BooleanField()
-
- persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)
- persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)
-
- def __unicode__(self):
- return "%s %s (%s)" % (self.person_expedition, self.place, self.date)
class OtherCaveName(models.Model):
diff --git a/expo/view_surveys.py b/expo/view_surveys.py index 2c5b5a1..388efa9 100644 --- a/expo/view_surveys.py +++ b/expo/view_surveys.py @@ -1,5 +1,21 @@ +import troggle.settings as settings
import fileAbstraction
+from django.shortcuts import render_to_response
from django.http import HttpResponse, Http404
+import os
+import re
+
+# inline fileabstraction into here if it's not going to be useful anywhere else
+# keep things simple and ignore exceptions everywhere for now
+
+def getMimeType(extension):
+ try:
+ return {"txt": "text/plain",
+ "html": "text/html",
+ }[extension]
+ except:
+ print "unknown file type"
+ return "text/plain"
def listdir(request, path):
@@ -13,16 +29,104 @@ def upload(request, path): def download(request, path):
#try:
+
return HttpResponse(fileAbstraction.readFile(path), mimetype=getMimeType(path.split(".")[-1]))
#except:
# raise Http404
-def getMimeType(extension):
- try:
- return {"txt": "text/plain",
- "html": "text/html",
- }[extension]
- except:
- print "unknown file type"
- return "text/plain"
\ No newline at end of file +#
+# julian's quick hack for something that works
+# could signal directories by ending with /, and forward cases where it's missing
+#
+extmimetypes = {".txt": "text/plain",
+ ".html": "text/html",
+ ".png": "image/png",
+ ".jpg": "image/jpeg",
+ }
+
+def jgtfile(request, f):
+ fp = os.path.join(settings.SURVEYS, f)
+ # could also surf through SURVEX_DATA
+
+ # directory listing
+ if os.path.isdir(fp):
+ listdirfiles = [ ]
+ listdirdirs = [ ]
+
+ for lf in sorted(os.listdir(fp)):
+ hpath = os.path.join(f, lf) # not absolute path
+ if lf[0] == "." or lf[-1] == "~":
+ continue
+
+ hpath = hpath.replace("\\", "/") # for windows users
+ href = hpath.replace("#", "%23") # '#' in file name annoyance
+
+ flf = os.path.join(fp, lf)
+ if os.path.isdir(flf):
+ nfiles = len([sf for sf in os.listdir(flf) if sf[0] != "."])
+ listdirdirs.append((href, hpath + "/", nfiles))
+ else:
+ listdirfiles.append((href, hpath, os.path.getsize(flf)))
+
+ upperdirs = [ ]
+ lf = f
+ while lf:
+ hpath = lf.replace("\\", "/") # for windows users
+ if hpath[-1] != "/":
+ hpath += "/"
+ href = hpath.replace("#", "%23")
+ lf = os.path.split(lf)[0]
+ upperdirs.append((href, hpath))
+ upperdirs.append(("", "/"))
+
+ return render_to_response('listdir.html', {'file':f, 'listdirfiles':listdirfiles, 'listdirdirs':listdirdirs, 'upperdirs':upperdirs, 'settings': settings})
+
+ # flat output of file when loaded
+ if os.path.isfile(fp):
+ ext = os.path.splitext(fp)[1].lower()
+ mimetype = extmimetypes.get(ext, "text/plain")
+ fin = open(fp)
+ ftext = fin.read()
+ fin.close()
+ return HttpResponse(ftext, mimetype=mimetype)
+
+ return HttpResponse("unknown file::%s::" % f, mimetype = "text/plain")
+
+
+def SaveImageInDir(name, imgdir, fdata):
+ print ("hihihihi", fdata, settings.SURVEYS)
+ print os.path.join(settings.SURVEYS, imgdir)
+ if not os.path.isdir(os.path.join(settings.SURVEYS, imgdir)):
+ print "*** Must have directory '%s' in '%s'" % (imgdir, settings.SURVEYS)
+ while True:
+ fname = os.path.join(settings.SURVEYS, imgdir, name)
+ if not os.path.exists(fname):
+ break
+ mname = re.match("(.*?)(?:-(\d+))?\.(png|jpg|jpeg)$(?i)", name)
+ if mname:
+ name = "%s-%d.%s" % (mname.group(1), int(mname.group(2) or "0") + 1, mname.group(3))
+ print "saving file", fname
+ fout = open(fname, "wb")
+ fout.write(fdata.read())
+ fout.close()
+ res = os.path.join(imgdir, name)
+ return res.replace("\\", "/")
+
+def jgtuploadfile(request):
+ filesuploaded = [ ]
+ project, user, tunnelversion = request.POST["project"], request.POST["user"], request.POST["tunnelversion"]
+ print (project, user, tunnelversion)
+ for uploadedfile in request.FILES.values():
+ if uploadedfile.field_name in ["tileimage", "backgroundimage"] and \
+ uploadedfile.content_type in ["image/png", "image/jpeg"]:
+ fname = user + "_" + re.sub("[\\\\/]", "-", uploadedfile.name) # very escaped \
+ print fname
+ fileuploaded = SaveImageInDir(fname, uploadedfile.field_name, uploadedfile)
+ filesuploaded.append(settings.URL_ROOT + "/jgtfile/" + fileuploaded)
+ #print "FF", request.FILES
+ #print ("FFF", request.FILES.values())
+ message = ""
+ print "gothere"
+ return render_to_response('fileupload.html', {'message':message, 'filesuploaded':filesuploaded, 'settings': settings})
+
diff --git a/expo/views.py b/expo/views.py index 718c720..4183f68 100644 --- a/expo/views.py +++ b/expo/views.py @@ -1,4 +1,7 @@ -from views_caves import *
-from views_survex import *
-from views_logbooks import *
-from views_other import *
+# primary namespace
+import view_surveys
+import views_caves
+import views_survex
+import views_logbooks
+import views_other
+
diff --git a/expo/views_caves.py b/expo/views_caves.py index 3363a2e..684f4b4 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -7,15 +7,10 @@ import search def caveindex(request):
caves = Cave.objects.all()
- notablecavehrefs = [ "161", "204", "258", "76" ]
+ notablecavehrefs = [ "161", "204", "258", "76" ] # could detect notability by trips and notability of people who have been down them
notablecaves = [ Cave.objects.get(href=href) for href in notablecavehrefs ]
return render_to_response('caveindex.html', {'caves': caves, 'notablecaves':notablecaves, 'settings': settings})
-def cave(request, cave_id):
- #hm, we're only choosing by the number within kataster, needs to be fixed. Caves in 1626 will presumably not work. - AC 7DEC08
- cave = Cave.objects.filter(kataster_number = cave_id)[0]
- return render_to_response('cave.html', {'cave': cave, 'settings': settings})
-
def cavehref(request, href):
cave = Cave.objects.get(href=href)
return render_to_response('cave.html', {'cave': cave, 'settings': settings})
diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index 513701b..a179c50 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -11,13 +11,14 @@ import re def personindex(request):
persons = Person.objects.all()
-
personss = [ ]
ncols = 5
nc = (len(persons) + ncols - 1) / ncols
for i in range(ncols):
personss.append(persons[i * nc: (i + 1) * nc])
- return render_to_response('personindex.html', {'persons': persons, 'personss':personss, 'settings': settings})
+
+ notablepersons = Person.objects.filter(bisnotable=True)
+ return render_to_response('personindex.html', {'persons': persons, 'personss':personss, 'notablepersons':notablepersons, 'settings': settings})
def expedition(request, expeditionname):
year = int(expeditionname)
@@ -42,12 +43,10 @@ def personexpedition(request, name, expeditionname): personexpedition = person.personexpedition_set.get(expedition=expedition)
return render_to_response('personexpedition.html', {'personexpedition': personexpedition, 'settings': settings})
-
def logbookentry(request, logbookentry_id):
logbookentry = LogbookEntry.objects.filter(href = logbookentry_id)[0]
return render_to_response('logbookentry.html', {'logbookentry': logbookentry, 'settings': settings})
-
def logbookSearch(request, extra):
query_string = ''
found_entries = None
diff --git a/expo/views_other.py b/expo/views_other.py index 1155036..e413297 100644 --- a/expo/views_other.py +++ b/expo/views_other.py @@ -18,7 +18,7 @@ def stats(request): statsDict['logbookEntryCount'] = int(LogbookEntry.objects.count())
return render_to_response('statistics.html', statsDict)
-def frontPage(request):
+def frontpage(request):
message = "no test message" #reverse('personn', kwargs={"name":"hkjhjh"})
if "reloadexpos" in request.GET:
message = LoadPersonsExpos()
|