2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-21 23:01:52 +00:00
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
parsers.survex.LoadAllSurvexBlocks()
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.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

View File

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

View File

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

View File

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

View File

@ -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]:

View File

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

View File

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

View File

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

View File

@ -3,8 +3,17 @@
{% 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>
{% 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'^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/(.*)', admin.site.root),