Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8245 by aaron @ 2/17/2009 1:09 AM
This commit is contained in:
substantialnoninfringinguser 2009-05-13 05:52:59 +01:00
parent d25fd97864
commit 25b695e53d
12 changed files with 122 additions and 78 deletions

View File

@ -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)

View File

@ -26,4 +26,4 @@ parsers.logbooks.LoadLogbooks()
import parsers.survex import parsers.survex
parsers.survex.LoadAllSurvexBlocks() parsers.survex.LoadAllSurvexBlocks()
import parsers.QMs import parsers.QMs
import parsers.surveys import parsers.surveys

View File

@ -6,7 +6,7 @@ from django.contrib import admin
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
from django.contrib.auth.models import User from django.contrib.auth.models import User
import os import os
import troggle.settings as settings from django.conf import settings
import datetime import datetime
from models_survex import * from models_survex import *
@ -16,7 +16,8 @@ class Expedition(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
date_from = models.DateField(blank=True,null=True) date_from = models.DateField(blank=True,null=True)
date_to = models.DateField(blank=True,null=True) date_to = models.DateField(blank=True,null=True)
dates_guessed = models.BooleanField(default=False)
def __unicode__(self): def __unicode__(self):
return self.year return self.year
@ -67,8 +68,10 @@ class Person(models.Model):
href = models.CharField(max_length=200) href = models.CharField(max_length=200)
orderref = models.CharField(max_length=200) # for alphabetic 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) user = models.ForeignKey(User, unique=True, null=True, blank=True)
def get_absolute_url(self): def get_absolute_url(self):
return settings.URL_ROOT + "/person/%s_%s/" % (self.first_name, self.last_name) return settings.URL_ROOT + "/person/%s_%s/" % (self.first_name, self.last_name)
@ -90,6 +93,16 @@ class Person(models.Model):
# def Lastexpedition(self): # def Lastexpedition(self):
# return self.personexpedition_set.order_by('-expedition')[0] # 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): def Sethref(self):
if self.last_name: if self.last_name:
self.href = self.first_name.lower() + "_" + self.last_name.lower() self.href = self.first_name.lower() + "_" + self.last_name.lower()
@ -105,6 +118,7 @@ class PersonExpedition(models.Model):
person = models.ForeignKey(Person) person = models.ForeignKey(Person)
date_from = models.DateField(blank=True,null=True) date_from = models.DateField(blank=True,null=True)
date_to = 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) is_guest = models.BooleanField(default=False)
COMMITTEE_CHOICES = ( COMMITTEE_CHOICES = (
('leader','Expo leader'), ('leader','Expo leader'),
@ -189,8 +203,8 @@ class LogbookEntry(models.Model):
#href = models.CharField(max_length=100) #href = models.CharField(max_length=100)
#logbookentry_next = models.ForeignKey('LogbookEntry', related_name='pnext', 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) logbookentry_prev = models.ForeignKey('LogbookEntry', related_name='pprev', blank=True,null=True)
class Meta: class Meta:
verbose_name_plural = "Logbook Entries" verbose_name_plural = "Logbook Entries"
@ -204,10 +218,14 @@ class LogbookEntry(models.Model):
def __unicode__(self): def __unicode__(self):
return "%s: (%s)" % (self.date, self.title) 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): 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 # 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 # possibly a trip has a plurality of triplets pointing into it

View File

@ -1,5 +1,5 @@
from django.db import models from django.db import models
import troggle.settings as settings from django.conf import settings
import os import os
class SurvexBlock(models.Model): class SurvexBlock(models.Model):

View File

@ -1,7 +1,7 @@
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from troggle.expo.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry from troggle.expo.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry
import troggle.settings as settings import troggle.settings as settings
from django.db import models
from troggle.parsers.logbooks import LoadLogbookForExpedition from troggle.parsers.logbooks import LoadLogbookForExpedition
from troggle.parsers.people import GetPersonExpeditionNameLookup from troggle.parsers.people import GetPersonExpeditionNameLookup
from troggle.expo.forms import PersonForm from troggle.expo.forms import PersonForm
@ -12,6 +12,8 @@ from troggle.alwaysUseRequestContext import render_response
import search import search
import re import re
@models.permalink #this allows the nice get_absolute_url syntax we are using
def personindex(request): def personindex(request):
persons = Person.objects.all() 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 # 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') 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, }) 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=''): def person(request, first_name='', last_name=''):
person = Person.objects.get(first_name = first_name, last_name = last_name) person = Person.objects.get(first_name = first_name, last_name = last_name)
return render_response(request,'person.html', {'person': person, }) return render_response(request,'person.html', {'person': person, })

View File

@ -52,7 +52,7 @@ def parseCaveQMs(cave,pathToCSV):
newQM.completion_description=line[5] newQM.completion_description=line[5]
newQM.comment=line[6] newQM.comment=line[6]
newQM.save() newQM.save()
print "QM "+str(newQM) + " added to database" print "QM "+str(newQM) + ' added to database\r',
except KeyError: except KeyError:
continue continue
# except IndexError: # except IndexError:

View File

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys import sys
sys.path.append("/home/mjg/expoweb/troggle") sys.path.append("/home/mjg/expoweb/troggle")
import expo.models as models import troggle.expo.models as models
import settings as settings from django.conf import settings
import csv import csv
import time import time
@ -177,7 +177,6 @@ def LoadCaveTab():
addToArgs(Notes, "notes") addToArgs(Notes, "notes")
newCave = models.Cave(**args) newCave = models.Cave(**args)
newCave.Sethref()
newCave.save() newCave.save()
if line[Area]: if line[Area]:

View File

@ -20,7 +20,7 @@ import os
# #
# the logbook loading section # the logbook loading section
# #
def GetTripPersons(trippeople, expedition, logtime_underground): def GetTripPersons(trippeople, expedition, logtime_underground):
res = [ ] res = [ ]
author = None author = None
for tripperson in re.split(",|\+|&|&(?!\w+;)| and ", trippeople): for tripperson in re.split(",|\+|&|&(?!\w+;)| and ", trippeople):
@ -252,45 +252,50 @@ def SetDatesFromLogbookEntries(expedition):
persontrips = personexpedition.persontrip_set.order_by('date') persontrips = personexpedition.persontrip_set.order_by('date')
personexpedition.date_from = min([persontrip.date for persontrip in persontrips] or [None]) 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.date_to = max([persontrip.date for persontrip in persontrips] or [None])
personexpedition.dates_guessed = True
personexpedition.save() personexpedition.save()
lprevpersontrip = None # The below is all unnecessary, just use the built in get_previous_by_date and get_next_by_date
for persontrip in persontrips: # lprevpersontrip = None
persontrip.persontrip_prev = lprevpersontrip # for persontrip in persontrips:
if lprevpersontrip: # persontrip.persontrip_prev = lprevpersontrip
lprevpersontrip.persontrip_next = persontrip # if lprevpersontrip:
lprevpersontrip.save() # lprevpersontrip.persontrip_next = persontrip
persontrip.persontrip_next = None # lprevpersontrip.save()
lprevpersontrip = persontrip # persontrip.persontrip_next = None
persontrip.save() # 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
expedition.date_from = min([personexpedition.date_from for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_from] or [None]) 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.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() expedition.save()
# order by appearance in the logbook (done by id) # The below has been replaced with the methods get_next_by_id and get_previous_by_id
lprevlogbookentry = None # # order by appearance in the logbook (done by id)
for logbookentry in expedition.logbookentry_set.order_by('id'): # lprevlogbookentry = None
logbookentry.logbookentry_prev = lprevlogbookentry # for logbookentry in expedition.logbookentry_set.order_by('id'):
if lprevlogbookentry: # logbookentry.logbookentry_prev = lprevlogbookentry
lprevlogbookentry.logbookentry_next = logbookentry # if lprevlogbookentry:
lprevlogbookentry.save() # lprevlogbookentry.logbookentry_next = logbookentry
logbookentry.logbookentry_next = None # lprevlogbookentry.save()
logbookentry.save() # logbookentry.logbookentry_next = None
lprevlogbookentry = logbookentry # logbookentry.save()
# lprevlogbookentry = logbookentry
# order by date for setting the references # 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.
lprevlogbookentry = None # # order by date for setting the references
for logbookentry in expedition.logbookentry_set.order_by('date'): # lprevlogbookentry = None
if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date: # for logbookentry in expedition.logbookentry_set.order_by('date'):
mcount = re.search("_(\d+)$", lprevlogbookentry.href) # if lprevlogbookentry and lprevlogbookentry.date == logbookentry.date:
mc = mcount and (int(mcount.group(1)) + 1) or 1 # mcount = re.search("_(\d+)$", lprevlogbookentry.href)
logbookentry.href = "%s_%d" % (logbookentry.date, mc) # mc = mcount and (int(mcount.group(1)) + 1) or 1
else: # logbookentry.href = "%s_%d" % (logbookentry.date, mc)
logbookentry.href = "%s" % logbookentry.date # else:
logbookentry.save() # logbookentry.href = "%s" % logbookentry.date
lprevlogbookentry = logbookentry # logbookentry.save()
# lprevlogbookentry = logbookentry
def LoadLogbookForExpedition(expedition): def LoadLogbookForExpedition(expedition):

View File

@ -56,7 +56,7 @@ def LoadPersonsExpos():
print "Loading expeditions" print "Loading expeditions"
models.Expedition.objects.all().delete() models.Expedition.objects.all().delete()
years = headers[5:] years = headers[5:]
years.append("2008") # years.append("2008")
for year in years: for year in years:
expedition = models.Expedition(year = year, name = "CUCC expo %s" % year) expedition = models.Expedition(year = year, name = "CUCC expo %s" % year)
expedition.save() expedition.save()
@ -77,7 +77,7 @@ def LoadPersonsExpos():
person = models.Person(first_name=mname.group(1), last_name=(mname.group(2) or "")) person = models.Person(first_name=mname.group(1), last_name=(mname.group(2) or ""))
person.is_vfho = personline[header["VfHO member"]] person.is_vfho = personline[header["VfHO member"]]
person.Sethref() #person.Sethref()
#print "NNNN", person.href #print "NNNN", person.href
is_guest = (personline[header["Guest"]] == "1") # this is really a per-expo catagory; not a permanent state is_guest = (personline[header["Guest"]] == "1") # this is really a per-expo catagory; not a permanent state
person.save() person.save()
@ -90,33 +90,33 @@ def LoadPersonsExpos():
personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname=nickname, is_guest=is_guest) personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname=nickname, is_guest=is_guest)
personexpedition.save() 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 # this fills in those people for whom 2008 was their first expo
print "Loading personexpeditions 2008" # print "Loading personexpeditions 2008"
for name in expomissing: # for name in expomissing:
firstname, lastname = name.split() # firstname, lastname = name.split()
is_guest = name in ["Eeva Makiranta", "Keith Curtis"] # is_guest = name in ["Eeva Makiranta", "Keith Curtis"]
print "2008:", name # print "2008:", name
persons = list(models.Person.objects.filter(first_name=firstname, last_name=lastname)) # persons = list(models.Person.objects.filter(first_name=firstname, last_name=lastname))
if not persons: # if not persons:
person = models.Person(first_name=firstname, last_name = lastname, is_vfho = False, mug_shot = "") # person = models.Person(first_name=firstname, last_name = lastname, is_vfho = False, mug_shot = "")
person.Sethref() # #person.Sethref()
person.save() # person.save()
else: # else:
person = persons[0] # person = persons[0]
expedition = models.Expedition.objects.get(year="2008") # expedition = models.Expedition.objects.get(year="2008")
personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname="", is_guest=is_guest) # personexpedition = models.PersonExpedition(person=person, expedition=expedition, nickname="", is_guest=is_guest)
personexpedition.save() # personexpedition.save()
# could rank according to surveying as well # could rank according to surveying as well
print "Setting person notability" # print "Setting person notability"
for person in models.Person.objects.all(): # for person in models.Person.objects.all():
person.notability = 0.0 # person.notability = 0.0
for personexpedition in person.personexpedition_set.all(): # for personexpedition in person.personexpedition_set.all():
if not personexpedition.is_guest: # if not personexpedition.is_guest:
person.notability += 1.0 / (2012 - int(personexpedition.expedition.year)) # 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.bisnotable = person.notability > 0.3 # I don't know how to filter by this
person.save() # person.save()
# used in other referencing parser functions # used in other referencing parser functions

View File

@ -42,7 +42,7 @@ for survey in surveyreader:
#try and find the sketch_scan #try and find the sketch_scan
pass pass
surveyobj.save() surveyobj.save()
print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number print "added survey " + survey[header['Year']] + "#" + surveyobj.wallet_number + "\r",
# add survey scans # add survey scans
def parseSurveyScans(year): def parseSurveyScans(year):
@ -53,7 +53,7 @@ def parseSurveyScans(year):
surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups() surveyNumber=re.match(r'\d\d\d\d#0*(\d+)',surveyFolder).groups()
scanList=os.listdir(os.path.join(yearPath,surveyFolder)) scanList=os.listdir(os.path.join(yearPath,surveyFolder))
except AttributeError: except AttributeError:
print surveyFolder + " ignored" print surveyFolder + " ignored",
continue continue
for scan in scanList: 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() scanChopped=re.match(r'(?i).*(notes|elev|plan|elevation|extend)(\d*)\.(png|jpg|jpeg)',scan).groups()
scanType,scanNumber,scanFormat=scanChopped scanType,scanNumber,scanFormat=scanChopped
except AttributeError: except AttributeError:
print "Adding scans: " + scan + " ignored" print "Adding scans: " + scan + " ignored \r",
continue continue
if scanType == 'elev' or scanType == 'extend': if scanType == 'elev' or scanType == 'extend':
scanType = 'elevation' scanType = 'elevation'

View File

@ -3,8 +3,17 @@
{% block title %}Person {{person|wiki_to_html_short}}{% endblock %} {% block title %}Person {{person|wiki_to_html_short}}{% endblock %}
{% block content %} {% block contentheader %}
<h2> {{person|wiki_to_html_short}} </h2>
{% endblock %}
{% block content %}
{{person.blurb}}
{% for pic in person.photo_set
<div class="figure">
<p> <img src="{{ person.correctURL }}" class="thumbnail" /> </p>
</div>
<p>{{person|wiki_to_html_short}} has been on expo in the following years:</p> <p>{{person|wiki_to_html_short}} has been on expo in the following years:</p>
<p> <p>
{% for personexpedition in person.personexpedition_set.all %} {% for personexpedition in person.personexpedition_set.all %}

View File

@ -55,7 +55,7 @@ urlpatterns = patterns('',
url(r'^calendar/(?P<year>\d\d\d\d)/?$', views_other.calendar, name="calendar"), url(r'^calendar/(?P<year>\d\d\d\d)/?$', views_other.calendar, name="calendar"),
url(r'^survey/?$', surveyindex, name="survey"), url(r'^survey/?$', surveyindex, name="survey"),
(r'^survey/(?P<year>\d\d\d\d)\#(?P<wallet_number>\d*)$', survey), url(r'^survey/(?P<year>\d\d\d\d)\#(?P<wallet_number>\d*)$', survey, name="survey"),
(r'^admin/doc/?', include('django.contrib.admindocs.urls')), (r'^admin/doc/?', include('django.contrib.admindocs.urls')),
(r'^admin/(.*)', admin.site.root), (r'^admin/(.*)', admin.site.root),