diff options
-rw-r--r-- | expo/models.py | 11 | ||||
-rw-r--r-- | expo/models_survex.py | 16 | ||||
-rw-r--r-- | expo/views_logbooks.py | 18 | ||||
-rw-r--r-- | parsers/logbooks.py | 37 | ||||
-rw-r--r-- | parsers/people.py | 5 | ||||
-rw-r--r-- | parsers/survex.py | 3 | ||||
-rw-r--r-- | templates/expedition.html | 4 | ||||
-rw-r--r-- | templates/logbookentry.html | 14 | ||||
-rw-r--r-- | templates/personexpedition.html | 36 | ||||
-rw-r--r-- | urls.py | 3 |
10 files changed, 122 insertions, 25 deletions
diff --git a/expo/models.py b/expo/models.py index 3cc0492..ebaf9ab 100644 --- a/expo/models.py +++ b/expo/models.py @@ -45,6 +45,8 @@ class Person(models.Model): is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.")
mug_shot = models.CharField(max_length=100, blank=True,null=True)
blurb = models.TextField(blank=True,null=True)
+ href = models.CharField(max_length=200)
+
class Meta:
verbose_name_plural = "People"
@@ -53,12 +55,6 @@ class Person(models.Model): return "%s %s" % (self.first_name, self.last_name)
return self.first_name
- # this should be a member entry
- def href(self):
- if self.last_name:
- return "%s_%s" % (self.first_name.lower(), self.last_name.lower())
- return self.first_name.lower()
-
class PersonExpedition(models.Model):
expedition = models.ForeignKey(Expedition)
@@ -205,9 +201,10 @@ class LogbookEntry(models.Model): expedition = models.ForeignKey(Expedition,blank=True,null=True) # yes this is double-
author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip
title = models.CharField(max_length=200)
- cave = models.ForeignKey(Cave,blank=True,null=True)
+ cave = models.ForeignKey(Cave,blank=True,null=True)
place = models.CharField(max_length=100,blank=True,null=True)
text = models.TextField()
+ 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)
diff --git a/expo/models_survex.py b/expo/models_survex.py index da8ec88..80e5f5b 100644 --- a/expo/models_survex.py +++ b/expo/models_survex.py @@ -1,5 +1,6 @@ from django.db import models
-
+import troggle.settings as settings
+import os
class SurvexBlock(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
@@ -11,15 +12,28 @@ class SurvexBlock(models.Model): end_year = models.IntegerField(blank=True, null=True)
end_month = models.IntegerField(blank=True, null=True)
end_day = models.IntegerField(blank=True, null=True)
+
person = models.ManyToManyField('Person', through='PersonRole', blank=True, null=True)
+
begin_file = models.CharField(max_length=200)
begin_char = models.IntegerField()
end_file = models.CharField(max_length=200, blank=True, null=True)
end_char = models.IntegerField(blank=True, null=True)
+
def __unicode__(self):
return unicode(self.name)
+
+ def filecontents(self):
+ f = os.path.join(settings.SURVEX_DATA, self.begin_file)
+ fin = open(f)
+ res = fin.read()
+ fin.close()
+ return res
+
+
class PersonRole(models.Model):
+ personexpedition = models.ForeignKey('PersonExpedition')
person = models.ForeignKey('Person')
survex_block = models.ForeignKey('SurvexBlock')
role = models.ForeignKey('Role')
diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index 1f3de23..935eebd 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -22,17 +22,19 @@ def expedition(request, expeditionname): return render_to_response('expedition.html', {'expedition': expedition, 'expedition_next':expedition_next, 'expedition_prev':expedition_prev, 'logbookentries':logbookentries, 'message':message, 'settings': settings})
def person(request, name):
- persons = Person.objects.all()
- for person in persons:
- if person.href() == name:
- break
- person = None
+ person = Person.objects.get(href=name)
return render_to_response('person.html', {'person': person, 'settings': settings})
+def personexpedition(request, name, expeditionname):
+ person = Person.objects.get(href=name)
+ year = int(expeditionname)
+ expedition = Expedition.objects.get(year=year)
+ personexpedition = person.personexpedition_set.get(expedition=expedition)
+ return render_to_response('personexpedition.html', {'personexpedition': personexpedition, 'settings': settings})
+
+
def logbookentry(request, logbookentry_id):
- logbookentry = LogbookEntry.objects.filter(id = logbookentry_id)[0]
-
-
+ logbookentry = LogbookEntry.objects.filter(href = logbookentry_id)[0]
return render_to_response('logbookentry.html', {'logbookentry': logbookentry, 'settings': settings})
diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 53726c6..a2cf58a 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -169,10 +169,20 @@ def Parseloghtml01(year, expedition, txt): triptitles = triptitle.split(" - ")
tripcave = triptitles[0].strip()
- ltriptext = re.sub("</p>", "", triptext)
+ ltriptext = triptext
+
+ mtail = re.search('(?:<a href="[^"]*">[^<]*</a>|\s|/|-|&|</?p>|\((?:same day|\d+)\))*$', ltriptext)
+ if mtail:
+ #print mtail.group(0)
+ ltriptext = ltriptext[:mtail.start(0)]
+ ltriptext = re.sub("</p>", "", ltriptext)
ltriptext = re.sub("\s*?\n\s*", " ", ltriptext)
- ltriptext = re.sub("<p>", "\n\n", ltriptext).strip()
+ ltriptext = re.sub("<p>|<br>", "\n\n", ltriptext).strip()
#ltriptext = re.sub("[^\s0-9a-zA-Z\-.,:;'!]", "NONASCII", ltriptext)
+ ltriptext = re.sub("</?u>", "_", ltriptext)
+ ltriptext = re.sub("</?i>", "''", ltriptext)
+ ltriptext = re.sub("</?b>", "'''", ltriptext)
+
#print ldate, trippeople.strip()
# could includ the tripid (url link for cross referencing)
@@ -246,6 +256,28 @@ def SetDatesFromLogbookEntries(expedition): expedition.date_to = max([personexpedition.date_to for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_to] or [None])
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
+
+ # 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):
@@ -268,6 +300,7 @@ def LoadLogbooks(): models.LogbookEntry.objects.all().delete()
expowebbase = os.path.join(settings.EXPOWEB, "years")
#yearlinks = [ ("2001", "2001/log.htm", Parseloghtml01), ] #overwrite
+ #yearlinks = [ ("1997", "1997/log.htm", Parseloghtml01),] # overwrite
for year, lloc, parsefunc in yearlinks:
expedition = models.Expedition.objects.filter(year = year)[0]
diff --git a/parsers/people.py b/parsers/people.py index d85d772..c59d3d8 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -81,8 +81,11 @@ def LoadPersonsExpos(): print firstname, lastname, "NNN", nickname #assert lastname == person[header[""]], person + href = firstname.lower() + if lastname: + href += "_" + lastname.lower() pObject = models.Person(first_name = firstname, - last_name = lastname, + last_name = lastname, href=href, is_vfho = person[header["VfHO member"]], ) diff --git a/parsers/survex.py b/parsers/survex.py index 00b6254..1f688c3 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -70,7 +70,8 @@ def make_model(name, parent, iter_lines, sf, c, l): and names.strip("\t").strip(" ") != "Both"]) for name in re.split("&|/|\+|,|;", names): try: - models.PersonRole(person = exp.GetPersonExpedition(name.strip(" ")).person, + models.PersonRole(personexpedition = exp.GetPersonExpedition(name.strip(" ")), + person = exp.GetPersonExpedition(name.strip(" ")).person, survex_block = m, role = models.Role.objects.get(name = roles[role])).save() except AttributeError: diff --git a/templates/expedition.html b/templates/expedition.html index 72fec15..bcbed62 100644 --- a/templates/expedition.html +++ b/templates/expedition.html @@ -18,7 +18,7 @@ <tr><th>Caver</th><th>From</th><th>To</th></tr> {% for personexpedition in expedition.personexpedition_set.all %} <tr> - <td><a href="{% url person personexpedition.person.href%}">{{personexpedition.person}}</a></td> + <td><a href="{% url personexpedition personexpedition.person.href personexpedition.expedition.year%}">{{personexpedition.person}}</a></td> <td>{{personexpedition.date_from}}</td> <td>{{personexpedition.date_to}}</td> </tr> @@ -36,7 +36,7 @@ {% for logbookentry in logbookentries %} <tr> <td>{{logbookentry.date}}</td> - <td><a href="{% url logbookentry logbookentry.id %}">{{logbookentry.title|safe}}</td> + <td><a href="{% url logbookentry logbookentry.href %}">{{logbookentry.title|safe}}</td> <td><a href="{% url person logbookentry.author.person.href%}">{{logbookentry.author.name}}</a></td> <td>{{logbookentry.place}}</td> </tr> diff --git a/templates/logbookentry.html b/templates/logbookentry.html index 4a0dd61..6ed9b32 100644 --- a/templates/logbookentry.html +++ b/templates/logbookentry.html @@ -10,12 +10,22 @@ <p><a href="{% url expedition logbookentry.expedition.year %}">{{logbookentry.expedition.name}}</a></p>
<p>place: {{logbookentry.place}}</p>
+<p>
+ {% if logbookentry.logbookentry_prev %}
+ <a href="{% url logbookentry logbookentry.logbookentry_prev.href %}">{{logbookentry.logbookentry_prev.date}}</a>
+ {% endif %}
+ {% if logbookentry.logbookentry_next %}
+ <a href="{% url logbookentry logbookentry.logbookentry_next.href %}">{{logbookentry.logbookentry_next.date}}</a>
+ {% endif %}
+</p>
+
<table class="cavers">
<tr><th>Caver</th><th>T/U</th><th>Prev</th><th>Next</th></tr>
{% for persontrip in logbookentry.persontrip_set.all %}
<tr>
{% ifequal persontrip.person_expedition logbookentry.author %}
<td class="author">
+{{persontrip.person_expedition.person.personrole_set.count}}
{% else %}
<td>
{% endifequal %}
@@ -30,12 +40,12 @@ <td>
{% if persontrip.persontrip_prev %}
- <a href="{% url logbookentry persontrip.persontrip_prev.logbook_entry.id %}">{{persontrip.persontrip_prev.date}}</a>
+ <a href="{% url logbookentry persontrip.persontrip_prev.logbook_entry.href %}">{{persontrip.persontrip_prev.date}}</a>
{% endif %}
</td>
<td>
{% if persontrip.persontrip_next %}
- <a href="{% url logbookentry persontrip.persontrip_next.logbook_entry.id %}">{{persontrip.persontrip_next.date}}</a>
+ <a href="{% url logbookentry persontrip.persontrip_next.logbook_entry.href %}">{{persontrip.persontrip_next.date}}</a>
{% endif %}
</td>
</tr>
diff --git a/templates/personexpedition.html b/templates/personexpedition.html new file mode 100644 index 0000000..91c618a --- /dev/null +++ b/templates/personexpedition.html @@ -0,0 +1,36 @@ +{% extends "base.html" %}
+{% load wiki_markup %}
+
+{% block title %}Person {{personexpedition.person|wiki_to_html_short}} for {{personexpedition.expedition}}{% endblock %}
+
+
+{% block content %}
+<h2>{{personexpedition.person}}: {{personexpedition.expedition}} ({{personexpedition.date_from}} - {{personexpedition.date_to}})</h2>
+
+<div id="col2">
+<table class="survexcontibutions">
+<tr><th>Date</th><th>Place</th><th>Role</th></tr>
+{% for personrole in personexpedition.personrole_set.all %}
+ <tr>
+ <td>{{personrole.survex_block.start_month}}</td>
+ <td>{{personrole.survex_block.name}}</td>
+ <td>{{personrole.role}}</td>
+ </tr>
+{% endfor %}
+</table>
+</div>
+
+<div id="col1">
+<table class="expeditionlogbooks">
+<tr><th>Date</th><th>Title</th><th>Place</th></tr>
+{% for persontrip in personexpedition.persontrip_set.all %}
+ <tr>
+ <td>{{persontrip.date}}</td>
+ <td><a href="{% url logbookentry persontrip.logbook_entry.href %}">{{persontrip.logbook_entry.title|safe}}</td>
+ <td>{{persontrip.place}}</td>
+ </tr>
+{% endfor %}
+</table>
+</div>
+
+{% endblock %}
@@ -23,10 +23,11 @@ urlpatterns = patterns('', url(r'^personindex$', personindex, name="personindex"),
url(r'^person/(.+)$', person, name="person"),
- url(r'^logbookentry/(\d+)$', logbookentry, name="logbookentry"),
+ url(r'^logbookentry/(.+)$', logbookentry, name="logbookentry"),
url(r'^logbooksearch/(.*)/?$', logbookSearch),
url(r'^expedition/(\d+)$', expedition, name="expedition"),
+ url(r'^personexpedition/(.+?)/(\d+)$', personexpedition, name="personexpedition"),
url(r'^statistics/?$', stats, name="stats"),
|