diff --git a/expo/models.py b/expo/models.py index 59d0e11..bf8e2db 100644 --- a/expo/models.py +++ b/expo/models.py @@ -76,7 +76,13 @@ class Person(TroggleModel): mug_shot = models.CharField(max_length=100, blank=True,null=True) blurb = models.TextField(blank=True,null=True) - #href = models.CharField(max_length=200) + + # this has been put back in so that the personexpedition links work + # if you're going to insist on replace something that works with an over-complex, dire, inevitably-flawed pointless + # and unnecessary regexp like (?P[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P[A-Z]*[a-z\-]*)/? + # for no reason at all, at least make it work everywhere! + href = models.CharField(max_length=200) + orderref = models.CharField(max_length=200) # for alphabetic #the below have been removed and made methods. I'm not sure what the b in bisnotable stands for. - AC 16 Feb @@ -113,14 +119,14 @@ class Person(TroggleModel): def bisnotable(self): return self.notability > 0.3 - #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 + 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(TroggleModel): @@ -209,6 +215,9 @@ class LogbookEntry(TroggleModel): cave = models.ForeignKey('Cave',blank=True,null=True) place = models.CharField(max_length=100,blank=True,null=True) text = models.TextField() + + # having this commented out prevents us from ever devising a regular URL, possibly based on the date of the trip + # and then disambiguated depending on how many trips there are #href = models.CharField(max_length=100) diff --git a/expo/view_surveys.py b/expo/view_surveys.py index 388efa9..8bf3cc3 100644 --- a/expo/view_surveys.py +++ b/expo/view_surveys.py @@ -94,35 +94,64 @@ def jgtfile(request, f): 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) +def UniqueFile(fname): 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) + mname = re.match("(.*?)(?:-(\d+))?\.(png|jpg|jpeg)$(?i)", fname) if mname: - name = "%s-%d.%s" % (mname.group(1), int(mname.group(2) or "0") + 1, mname.group(3)) + fname = "%s-%d.%s" % (mname.group(1), int(mname.group(2) or "0") + 1, mname.group(3)) + return fname + + +# join it all up and then split them off for the directories that don't exist +# anyway, this mkdir doesn't work +def SaveImageInDir(name, imgdir, project, fdata, bbinary): + print ("hihihihi", fdata, settings.SURVEYS) + fimgdir = os.path.join(settings.SURVEYS, imgdir) + if not os.path.isdir(fimgdir): + print "*** Making directory", fimgdir + os.path.mkdir(fimgdir) + fprojdir = os.path.join(fimgdir, project) + if not os.path.isdir(fprojdir): + print "*** Making directory", fprojdir + os.path.mkdir(fprojdir) + print "hhh" + + fname = os.path.join(fprojdir, name) + print fname, "fff" + fname = UniqueFile(fname) + + p2, p1 = os.path.split(fname) + p3, p2 = os.path.split(p2) + p4, p3 = os.path.split(p3) + res = os.path.join(p3, p2, p1) + print "saving file", fname - fout = open(fname, "wb") + fout = open(fname, (bbinary and "wb" or "w")) fout.write(fdata.read()) fout.close() res = os.path.join(imgdir, name) return res.replace("\\", "/") + +# do we want to consider saving project/field rather than field/project def jgtuploadfile(request): filesuploaded = [ ] - project, user, tunnelversion = request.POST["project"], request.POST["user"], request.POST["tunnelversion"] + project, user, password, tunnelversion = request.POST["tunnelproject"], request.POST["tunneluser"], request.POST["tunnelpassword"], 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) + fileuploaded = SaveImageInDir(fname, uploadedfile.field_name, project, uploadedfile, True) + filesuploaded.append(settings.URL_ROOT + "/jgtfile/" + fileuploaded) + if uploadedfile.field_name in ["sketch"] and \ + uploadedfile.content_type in ["text/plain"]: + fname = user + "_" + re.sub("[\\\\/]", "-", uploadedfile.name) # very escaped \ + print fname + fileuploaded = SaveImageInDir(fname, uploadedfile.field_name, project, uploadedfile, False) filesuploaded.append(settings.URL_ROOT + "/jgtfile/" + fileuploaded) #print "FF", request.FILES #print ("FFF", request.FILES.values()) diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index fae7491..ab85318 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -63,8 +63,8 @@ def person(request, first_name='', last_name=''): # person = Person.objects.get(href=name) # -def personexpedition(request, first_name='', last_name='', year=''): - person = Person.objects.get(first_name = first_name, last_name = last_name) +def personexpedition(request, href, year): + person = Person.objects.get(href=href) expedition = Expedition.objects.get(year=year) personexpedition = person.personexpedition_set.get(expedition=expedition) return render_response(request,'personexpedition.html', {'personexpedition': personexpedition, }) diff --git a/expo/views_other.py b/expo/views_other.py index d890a6e..9852ccc 100644 --- a/expo/views_other.py +++ b/expo/views_other.py @@ -29,7 +29,8 @@ def frontpage(request): #'randSent':randSent.randomLogbookSentence(), expeditions = Expedition.objects.order_by("-year") - return render_response(request,'index.html', {'expeditions':expeditions, 'all':'all', "message":message}) + totallogbookentries = LogbookEntry.objects.count() + return render_response(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message}) def calendar(request,year): week=['S','S','M','T','W','T','F'] diff --git a/parsers/logbooks.py b/parsers/logbooks.py index c2c46a4..6830893 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -198,7 +198,7 @@ def Parseloghtml01(year, expedition, txt): #print ldate, trippeople.strip() - # could includ the tripid (url link for cross referencing) + # could include the tripid (url link for cross referencing) EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0) @@ -245,6 +245,9 @@ yearlinks = [ ("1998", "1998/log.htm", Parseloghtml01), ("1997", "1997/log.htm", Parseloghtml01), ("1996", "1996/log.htm", Parseloghtml01), + ("1995", "1995/log.htm", Parseloghtml01), + ("1994", "1994/log.htm", Parseloghtml01), + ("1993", "1993/log.htm", Parseloghtml01), ] def SetDatesFromLogbookEntries(expedition): @@ -255,22 +258,25 @@ def SetDatesFromLogbookEntries(expedition): personexpedition.save() # The below is all unnecessary, just use the built in get_previous_by_date and get_next_by_date -# lprevpersontrip = None -# for persontrip in persontrips: -# persontrip.persontrip_prev = lprevpersontrip -# if lprevpersontrip: -# lprevpersontrip.persontrip_next = persontrip -# lprevpersontrip.save() -# persontrip.persontrip_next = None -# lprevpersontrip = persontrip -# persontrip.save() +# it might be if it f***ing worked! but it doesn't does it! + lprevpersontrip = None + for persontrip in persontrips: + persontrip.persontrip_prev = lprevpersontrip + if lprevpersontrip: + lprevpersontrip.persontrip_next = persontrip + lprevpersontrip.save() + persontrip.persontrip_next = None + lprevpersontrip = persontrip + persontrip.save() - # from trips rather than logbook entries, which may include events outside the expedition + # from trips rather than logbook entries, which may include events outside the expedition (so what?) expedition.date_from = min([personexpedition.date_from for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_from] or [None]) expedition.date_to = max([personexpedition.date_to for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_to] or [None]) expedition.save() # The below has been replaced with the methods get_next_by_id and get_previous_by_id +# (this might be true, but it's sort of in the order of the logbook. +# [Maybe we'd want to sort it by date and display it in that order, in which case it's tough luck! - JGT] # # order by appearance in the logbook (done by id) # lprevlogbookentry = None # for logbookentry in expedition.logbookentry_set.order_by('id'): @@ -282,7 +288,9 @@ def SetDatesFromLogbookEntries(expedition): # logbookentry.save() # lprevlogbookentry = logbookentry -# This combined date / number key is a weird way of doing things. Use the primary key instead. If we are going to use the date for looking up entries, we should set it up to allow multiple results. +# This combined date / number key is a weird way of doing things. Use the primary key instead. +# If we are going to use the date for looking up entries, we should set it up to allow multiple results. +# [Not weird. Very common. A date is meaningful and almost gets there. Simply needs small amount of disambiguation to make it a primary key -- JGT] # # order by date for setting the references # lprevlogbookentry = None # for logbookentry in expedition.logbookentry_set.order_by('date'): @@ -317,7 +325,7 @@ def LoadLogbooks(): models.LogbookEntry.objects.all().delete() expowebbase = os.path.join(settings.EXPOWEB, "years") #yearlinks = [ ("2001", "2001/log.htm", Parseloghtml01), ] #overwrite - #yearlinks = [ ("1996", "1996/log.htm", Parseloghtml01),] # overwrite + #yearlinks = [ ("1993", "1993/log.htm", Parseloghtml01),] # overwrite for year, lloc, parsefunc in yearlinks: expedition = models.Expedition.objects.filter(year = year)[0] @@ -327,4 +335,3 @@ def LoadLogbooks(): parsefunc(year, expedition, txt) SetDatesFromLogbookEntries(expedition) - diff --git a/parsers/people.py b/parsers/people.py index 269f13b..05a4349 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -83,11 +83,11 @@ def LoadPersonsExpos(): person = models.Person(first_name=mname.group(1), last_name=(mname.group(2) or "")) person.is_vfho = personline[header["VfHO member"]] - #person.Sethref() + person.Sethref() #print "NNNN", person.href is_guest = (personline[header["Guest"]] == "1") # this is really a per-expo catagory; not a permanent state person.save() - parseMugShotAndBlurb(personline=personline, header=header, person=person) + #parseMugShotAndBlurb(personline=personline, header=header, person=person) # make person expedition from table for year, attended in zip(headers, personline)[5:]: @@ -106,7 +106,7 @@ def LoadPersonsExpos(): persons = list(models.Person.objects.filter(first_name=firstname, last_name=lastname)) if not persons: person = models.Person(first_name=firstname, last_name = lastname, is_vfho = False, mug_shot = "") - #person.Sethref() + person.Sethref() person.save() else: person = persons[0] diff --git a/templates/index.html b/templates/index.html index 879346e..1c9fd3b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,8 +6,8 @@ {% block content %}

The unfinished front page

-

Further work

+

Julian's work: +

parse 1992-1976 logbooks; (esp top 161)

+

detect T/U on log entries;

+

name matching and spelling in survex files;

+

Improve logbook wikihtml text

+ +

Other work:

surf through the tunnel sketches and images

bugs with all.svx block (double dot) -

name matching and spelling in survex files;

render bitmap view of every survex block as a thumbnail

upload tunnel images and tunnel sketches

-

parse 1995-1976 logbooks; (esp top 161)

where are the subcaves;

cave section entrance match for logbook entries

-

detect T/U on log entries;

-

Improve logbook wikihtml text

simplify the survex parsing code (if necessary);

wiki survex stop linegap between comment lins

links between logbooks and survex blocks to cave things;

@@ -48,6 +51,7 @@ {% for expedition in expeditions %}
  • {{expedition.name}} + - {{expedition.logbookentry_set.count}} logbook entries
  • {% endfor %} diff --git a/templates/logbookentry.html b/templates/logbookentry.html index 690d21c..2148102 100644 --- a/templates/logbookentry.html +++ b/templates/logbookentry.html @@ -44,13 +44,13 @@ - {% if persontrip.get_previous_by_date %} - {{persontrip.get_previous_by_date.date}} + {% if persontrip.persontrip_prev %} + {{persontrip.persontrip_prev.date}} {% endif %} - {% if persontrip.get_next_by_date %} - {{persontrip.get_next_by_date.date}} + {% if persontrip.persontrip_next %} + {{persontrip.persontrip_next.date}} {% endif %} diff --git a/urls.py b/urls.py index 42e611d..cb95636 100644 --- a/urls.py +++ b/urls.py @@ -21,7 +21,8 @@ urlpatterns = patterns('', #url(r'^person/(\w+_\w+)$', views_logbooks.person, name="person"), url(r'^expedition/(\d+)$', views_logbooks.expedition, name="expedition"), - url(r'^personexpedition/(?P[A-Z]*[a-z]*)[^a-zA-Z]*(?P[A-Z]*[a-z]*)/(?P\d+)/?$', views_logbooks.personexpedition, name="personexpedition"), + #url(r'^personexpedition/(?P[A-Z]*[a-z]*)[^a-zA-Z]*(?P[A-Z]*[a-z]*)/(?P\d+)/?$', views_logbooks.personexpedition, name="personexpedition"), + url(r'^personexpedition/(.+?)/(\d+)$', views_logbooks.personexpedition, name="personexpedition"), url(r'^logbookentry/(.+)$', views_logbooks.logbookentry,name="logbookentry"), url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"),