From 91e4f0f8c0f4daa8434d21e2a0240718e4000187 Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 06:02:42 +0100 Subject: [PATCH] [svn] Reverted the reverts from 8267. Fixed the next / previous trip in personexpedition on the LogbookEntry template -- I had misunderstood what this was supposed to do last time I messed with it. This involved adding the methods PersonTrip.get_persons_next_trip and persons_previous_trip. Couldn't find any other broken things. Kept the productive changes in 8267: extending the logbook parsing back to 1993, changing index page, changes to view_surveys.py Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8274 by aaron @ 3/14/2009 8:38 AM --- expo/models.py | 12 ++++++++++++ expo/views_logbooks.py | 4 ++-- expo/views_other.py | 3 +-- parsers/logbooks.py | 36 ++++++++++++++++-------------------- parsers/people.py | 6 +++--- templates/logbookentry.html | 8 ++++---- urls.py | 9 ++++----- 7 files changed, 42 insertions(+), 36 deletions(-) diff --git a/expo/models.py b/expo/models.py index 395f973..6b94dde 100644 --- a/expo/models.py +++ b/expo/models.py @@ -260,7 +260,19 @@ class PersonTrip(TroggleModel): def __unicode__(self): return "%s %s (%s)" % (self.person_expedition, self.place, self.date) + def get_persons_next_trip(self): + try: + return PersonTrip.objects.filter(person_expedition__person=self.person_expedition.person, date__gt=self.date)[0] + except: + return + def get_persons_previous_trip(self): + try: + return PersonTrip.objects.filter(person_expedition__person=self.person_expedition.person, date__lt=self.date)[0] + except: + return + +# def get_persons_previous_trip(self): # # move following classes into models_cave # diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index ab85318..fae7491 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, href, year): - person = Person.objects.get(href=href) +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) return render_response(request,'personexpedition.html', {'personexpedition': personexpedition, }) diff --git a/expo/views_other.py b/expo/views_other.py index 9852ccc..d890a6e 100644 --- a/expo/views_other.py +++ b/expo/views_other.py @@ -29,8 +29,7 @@ def frontpage(request): #'randSent':randSent.randomLogbookSentence(), expeditions = Expedition.objects.order_by("-year") - totallogbookentries = LogbookEntry.objects.count() - return render_response(request,'index.html', {'expeditions':expeditions, 'all':'all', 'totallogbookentries':totallogbookentries, "message":message}) + return render_response(request,'index.html', {'expeditions':expeditions, 'all':'all', "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 6830893..9566d2d 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -198,7 +198,7 @@ def Parseloghtml01(year, expedition, txt): #print ldate, trippeople.strip() - # could include the tripid (url link for cross referencing) + # could includ the tripid (url link for cross referencing) EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0) @@ -244,10 +244,10 @@ yearlinks = [ ("1999", "1999/log.htm", Parseloghtml01), ("1998", "1998/log.htm", Parseloghtml01), ("1997", "1997/log.htm", Parseloghtml01), - ("1996", "1996/log.htm", Parseloghtml01), + ("1996", "1996/log.htm", Parseloghtml01), ("1995", "1995/log.htm", Parseloghtml01), ("1994", "1994/log.htm", Parseloghtml01), - ("1993", "1993/log.htm", Parseloghtml01), + ("1993", "1993/log.htm", Parseloghtml01), ] def SetDatesFromLogbookEntries(expedition): @@ -258,25 +258,22 @@ def SetDatesFromLogbookEntries(expedition): personexpedition.save() # The below is all unnecessary, just use the built in get_previous_by_date and get_next_by_date -# 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() +# 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 (so what?) + # from trips rather than logbook entries, which may include events outside the expedition 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'): @@ -288,9 +285,7 @@ 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. -# [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] +# 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. # # order by date for setting the references # lprevlogbookentry = None # for logbookentry in expedition.logbookentry_set.order_by('date'): @@ -325,7 +320,7 @@ def LoadLogbooks(): models.LogbookEntry.objects.all().delete() expowebbase = os.path.join(settings.EXPOWEB, "years") #yearlinks = [ ("2001", "2001/log.htm", Parseloghtml01), ] #overwrite - #yearlinks = [ ("1993", "1993/log.htm", Parseloghtml01),] # overwrite + #yearlinks = [ ("1996", "1996/log.htm", Parseloghtml01),] # overwrite for year, lloc, parsefunc in yearlinks: expedition = models.Expedition.objects.filter(year = year)[0] @@ -335,3 +330,4 @@ def LoadLogbooks(): parsefunc(year, expedition, txt) SetDatesFromLogbookEntries(expedition) + diff --git a/parsers/people.py b/parsers/people.py index 05a4349..269f13b 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/logbookentry.html b/templates/logbookentry.html index 2148102..5b972e8 100644 --- a/templates/logbookentry.html +++ b/templates/logbookentry.html @@ -44,13 +44,13 @@ - {% if persontrip.persontrip_prev %} - {{persontrip.persontrip_prev.date}} + {% if persontrip.get_previous_by_date %} + {{persontrip.get_persons_previous_trip.date}} {% endif %} - {% if persontrip.persontrip_next %} - {{persontrip.persontrip_next.date}} + {% if persontrip.get_persons_next_trip %} + {{persontrip.get_persons_next_trip.date}} {% endif %} diff --git a/urls.py b/urls.py index 4ab0f0a..64b159d 100644 --- a/urls.py +++ b/urls.py @@ -17,12 +17,11 @@ urlpatterns = patterns('', #(r'^person/(?P\d*)/?$', views_logbooks.person), - url(r'^person/(?P[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P[A-Z]*[a-z\-]*)/?', views_logbooks.person, name="person"), + url(r'^person/(?P[A-Z]*[a-z\-\']*)[^a-zA-Z]*(?P[a-z\-\']*[^a-zA-Z]*[A-Z]*[a-z\-]*)/?', views_logbooks.person, name="person"), #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/(.+?)/(\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'^logbookentry/(.+)$', views_logbooks.logbookentry,name="logbookentry"), url(r'^survexblock/(.+)$', views_caves.survexblock, name="survexblock"), @@ -78,5 +77,5 @@ urlpatterns = patterns('', {'document_root': settings.SURVEYS, 'show_indexes':True}), (r'^photos/(?P.*)$', 'django.views.static.serve', - {'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}), + {'document_root': settings.PHOTOS, 'show_indexes':True}), )