From 25b695e53dd09415f7849b35cd7bc63ca0b2439b Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:52:59 +0100 Subject: [PATCH] [svn] Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8245 by aaron @ 2/17/2009 1:09 AM --- alwaysUseRequestContext.py | 8 +++++ databaseReset.py | 2 +- expo/models.py | 32 +++++++++++++---- expo/models_survex.py | 2 +- expo/views_logbooks.py | 7 +++- parsers/QMs.py | 2 +- parsers/cavetab.py | 5 ++- parsers/logbooks.py | 71 ++++++++++++++++++++------------------ parsers/people.py | 52 ++++++++++++++-------------- parsers/surveys.py | 6 ++-- templates/person.html | 11 +++++- urls.py | 2 +- 12 files changed, 122 insertions(+), 78 deletions(-) create mode 100644 alwaysUseRequestContext.py diff --git a/alwaysUseRequestContext.py b/alwaysUseRequestContext.py new file mode 100644 index 0000000..b587b52 --- /dev/null +++ b/alwaysUseRequestContext.py @@ -0,0 +1,8 @@ +# this is the snippet from http://www.djangosnippets.org/snippets/3/ + +from django.shortcuts import render_to_response +from django.template import RequestContext + +def render_response(req, *args, **kwargs): + kwargs['context_instance'] = RequestContext(req) + return render_to_response(*args, **kwargs) \ No newline at end of file diff --git a/databaseReset.py b/databaseReset.py index fe7bb1f..434eb5f 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -26,4 +26,4 @@ parsers.logbooks.LoadLogbooks() import parsers.survex parsers.survex.LoadAllSurvexBlocks() import parsers.QMs -import parsers.surveys \ No newline at end of file +import parsers.surveys diff --git a/expo/models.py b/expo/models.py index bbe052c..9561963 100644 --- a/expo/models.py +++ b/expo/models.py @@ -6,7 +6,7 @@ from django.contrib import admin from django.core.files.storage import FileSystemStorage from django.contrib.auth.models import User import os -import troggle.settings as settings +from django.conf import settings import datetime from models_survex import * @@ -16,7 +16,8 @@ class Expedition(models.Model): name = models.CharField(max_length=100) date_from = models.DateField(blank=True,null=True) date_to = models.DateField(blank=True,null=True) - + dates_guessed = models.BooleanField(default=False) + def __unicode__(self): return self.year @@ -67,8 +68,10 @@ class Person(models.Model): 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() + + #the below have been removed and made methods. I'm not sure what the b in bisnotable stands for. - AC 16 Feb + #notability = models.FloatField() # for listing the top 20 people + #bisnotable = models.BooleanField() user = models.ForeignKey(User, unique=True, null=True, blank=True) def get_absolute_url(self): return settings.URL_ROOT + "/person/%s_%s/" % (self.first_name, self.last_name) @@ -90,6 +93,16 @@ class Person(models.Model): # def Lastexpedition(self): # return self.personexpedition_set.order_by('-expedition')[0] + def notability(self): + notability = 0.0 + for personexpedition in person.personexpedition_set.all(): + if not personexpedition.is_guest: + notability += 1.0 / (2012 - int(self.personexpedition.expedition.year)) + return notability + + 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() @@ -105,6 +118,7 @@ class PersonExpedition(models.Model): person = models.ForeignKey(Person) date_from = models.DateField(blank=True,null=True) date_to = models.DateField(blank=True,null=True) + dates_guessed = models.BooleanField(default=False) is_guest = models.BooleanField(default=False) COMMITTEE_CHOICES = ( ('leader','Expo leader'), @@ -189,8 +203,8 @@ class LogbookEntry(models.Model): #href = models.CharField(max_length=100) - #logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', blank=True,null=True) - #logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True) + 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" @@ -204,10 +218,14 @@ class LogbookEntry(models.Model): def __unicode__(self): return "%s: (%s)" % (self.date, self.title) + def get_next_by_id(self): + Logbook.objects.get(id=self.id+1) + def get_previous_by_id(self): + Logbook.objects.get(id=self.id-1) class PersonTrip(models.Model): - person_expedition = models.ForeignKey(PersonExpedition) + person_expedition = models.ForeignKey(PersonExpedition,null=True) # 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 diff --git a/expo/models_survex.py b/expo/models_survex.py index 1a7251f..cf339f9 100644 --- a/expo/models_survex.py +++ b/expo/models_survex.py @@ -1,5 +1,5 @@ from django.db import models -import troggle.settings as settings +from django.conf import settings import os class SurvexBlock(models.Model): diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index edf2f30..38aeac6 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -1,7 +1,7 @@ from django.shortcuts import render_to_response from troggle.expo.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry import troggle.settings as settings - +from django.db import models from troggle.parsers.logbooks import LoadLogbookForExpedition from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.expo.forms import PersonForm @@ -12,6 +12,8 @@ from troggle.alwaysUseRequestContext import render_response import search import re +@models.permalink #this allows the nice get_absolute_url syntax we are using + def personindex(request): persons = Person.objects.all() # From what I can tell, "persons" seems to be the table rows, while "personss" is the table columns. - AC 16 Feb 09 @@ -36,6 +38,9 @@ def expedition(request, expeditionname): logbookentries = expedition.logbookentry_set.order_by('date') return render_response(request,'expedition.html', {'expedition': expedition, 'expedition_next':expedition_next, 'expedition_prev':expedition_prev, 'logbookentries':logbookentries, 'message':message, }) + 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) return render_response(request,'person.html', {'person': person, }) diff --git a/parsers/QMs.py b/parsers/QMs.py index 96b91fa..7858c0c 100644 --- a/parsers/QMs.py +++ b/parsers/QMs.py @@ -52,7 +52,7 @@ def parseCaveQMs(cave,pathToCSV): newQM.completion_description=line[5] newQM.comment=line[6] newQM.save() - print "QM "+str(newQM) + " added to database" + print "QM "+str(newQM) + ' added to database\r', except KeyError: continue # except IndexError: diff --git a/parsers/cavetab.py b/parsers/cavetab.py index 270e6a5..8fc34d8 100644 --- a/parsers/cavetab.py +++ b/parsers/cavetab.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- import sys sys.path.append("/home/mjg/expoweb/troggle") -import expo.models as models -import settings as settings +import troggle.expo.models as models +from django.conf import settings import csv import time @@ -177,7 +177,6 @@ def LoadCaveTab(): addToArgs(Notes, "notes") newCave = models.Cave(**args) - newCave.Sethref() newCave.save() if line[Area]: diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 8138953..9c5a057 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -20,7 +20,7 @@ import os # # the logbook loading section # -def GetTripPersons(trippeople, expedition, logtime_underground): +def GetTripPersons(trippeople, expedition, logtime_underground): res = [ ] author = None for tripperson in re.split(",|\+|&|&(?!\w+;)| and ", trippeople): @@ -252,45 +252,50 @@ def SetDatesFromLogbookEntries(expedition): persontrips = personexpedition.persontrip_set.order_by('date') personexpedition.date_from = min([persontrip.date for persontrip in persontrips] or [None]) personexpedition.date_to = max([persontrip.date for persontrip in persontrips] or [None]) + personexpedition.dates_guessed = True personexpedition.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() + +# 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() # 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.dates_guessed = True expedition.save() - - # order by appearance in the logbook (done by id) - lprevlogbookentry = None - for logbookentry in expedition.logbookentry_set.order_by('id'): - logbookentry.logbookentry_prev = lprevlogbookentry - if lprevlogbookentry: - lprevlogbookentry.logbookentry_next = logbookentry - lprevlogbookentry.save() - logbookentry.logbookentry_next = None - logbookentry.save() - lprevlogbookentry = logbookentry + +# The below has been replaced with the methods get_next_by_id and get_previous_by_id +# # order by appearance in the logbook (done by id) +# lprevlogbookentry = None +# for logbookentry in expedition.logbookentry_set.order_by('id'): +# logbookentry.logbookentry_prev = lprevlogbookentry +# if lprevlogbookentry: +# lprevlogbookentry.logbookentry_next = logbookentry +# lprevlogbookentry.save() +# logbookentry.logbookentry_next = None +# logbookentry.save() +# lprevlogbookentry = logbookentry - # order by date for setting the references - lprevlogbookentry = None - for logbookentry in expedition.logbookentry_set.order_by('date'): - if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date: - mcount = re.search("_(\d+)$", lprevlogbookentry.href) - mc = mcount and (int(mcount.group(1)) + 1) or 1 - logbookentry.href = "%s_%d" % (logbookentry.date, mc) - else: - logbookentry.href = "%s" % logbookentry.date - 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. +# # order by date for setting the references +# lprevlogbookentry = None +# for logbookentry in expedition.logbookentry_set.order_by('date'): +# if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date: +# mcount = re.search("_(\d+)$", lprevlogbookentry.href) +# mc = mcount and (int(mcount.group(1)) + 1) or 1 +# logbookentry.href = "%s_%d" % (logbookentry.date, mc) +# else: +# logbookentry.href = "%s" % logbookentry.date +# logbookentry.save() +# lprevlogbookentry = logbookentry def LoadLogbookForExpedition(expedition): diff --git a/parsers/people.py b/parsers/people.py index 9c7940c..6c94679 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -56,7 +56,7 @@ def LoadPersonsExpos(): print "Loading expeditions" models.Expedition.objects.all().delete() years = headers[5:] - years.append("2008") +# years.append("2008") for year in years: expedition = models.Expedition(year = year, name = "CUCC expo %s" % year) expedition.save() @@ -77,7 +77,7 @@ 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() @@ -90,33 +90,33 @@ def LoadPersonsExpos(): personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname=nickname, is_guest=is_guest) personexpedition.save() - + # The below is no longer necessary because the 2008 expedition people have been added to surveys.csv. - AC 16 Feb 09 # this fills in those people for whom 2008 was their first expo - print "Loading personexpeditions 2008" - for name in expomissing: - firstname, lastname = name.split() - is_guest = name in ["Eeva Makiranta", "Keith Curtis"] - print "2008:", name - 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.save() - else: - person = persons[0] - expedition = models.Expedition.objects.get(year="2008") - personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname="", is_guest=is_guest) - personexpedition.save() +# print "Loading personexpeditions 2008" +# for name in expomissing: +# firstname, lastname = name.split() +# is_guest = name in ["Eeva Makiranta", "Keith Curtis"] +# print "2008:", name +# 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.save() +# else: +# person = persons[0] +# expedition = models.Expedition.objects.get(year="2008") +# personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname="", is_guest=is_guest) +# personexpedition.save() # could rank according to surveying as well - print "Setting person notability" - for person in models.Person.objects.all(): - person.notability = 0.0 - for personexpedition in person.personexpedition_set.all(): - if not personexpedition.is_guest: - person.notability += 1.0 / (2012 - int(personexpedition.expedition.year)) - person.bisnotable = person.notability > 0.3 # I don't know how to filter by this - person.save() +# print "Setting person notability" +# for person in models.Person.objects.all(): +# person.notability = 0.0 +# for personexpedition in person.personexpedition_set.all(): +# if not personexpedition.is_guest: +# person.notability += 1.0 / (2012 - int(personexpedition.expedition.year)) +# person.bisnotable = person.notability > 0.3 # I don't know how to filter by this +# person.save() # used in other referencing parser functions diff --git a/parsers/surveys.py b/parsers/surveys.py index cd9781b..53632e8 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -42,7 +42,7 @@ for survey in surveyreader: #try and find the sketch_scan pass surveyobj.save() - print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r", # add survey scans def parseSurveyScans(year): @@ -53,7 +53,7 @@ def parseSurveyScans(year): surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups() scanList=os.listdir(os.path.join(yearPath,surveyFolder)) except AttributeError: - print surveyFolder + " ignored" + print surveyFolder + " ignored", continue for scan in scanList: @@ -61,7 +61,7 @@ def parseSurveyScans(year): scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups() scanType,scanNumber,scanFormat=scanChopped except AttributeError: - print "Adding scans: " + scan + " ignored" + print "Adding scans: " + scan + " ignored \r", continue if scanType == 'elev' or scanType == 'extend': scanType = 'elevation' diff --git a/templates/person.html b/templates/person.html index 8f8c820..88171c1 100644 --- a/templates/person.html +++ b/templates/person.html @@ -3,8 +3,17 @@ {% block title %}Person {{person|wiki_to_html_short}}{% endblock %} -{% block content %} +{% block contentheader %} +

{{person|wiki_to_html_short}}

+{% endblock %} +{% block content %} +{{person.blurb}} +{% for pic in person.photo_set +
+

+
+

{{person|wiki_to_html_short}} has been on expo in the following years:

{% for personexpedition in person.personexpedition_set.all %} diff --git a/urls.py b/urls.py index d79863c..fedc122 100644 --- a/urls.py +++ b/urls.py @@ -55,7 +55,7 @@ urlpatterns = patterns('', url(r'^calendar/(?P\d\d\d\d)/?$', views_other.calendar, name="calendar"), url(r'^survey/?$', surveyindex, name="survey"), - (r'^survey/(?P\d\d\d\d)\#(?P\d*)$', survey), + url(r'^survey/(?P\d\d\d\d)\#(?P\d*)$', survey, name="survey"), (r'^admin/doc/?', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root),