From 8c818906b5c1228a6fb411cb96d1bd5f1663b49a Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:24:37 +0100 Subject: [PATCH] [svn] Added QM model and parser. Had to merge models_cave.py and models_logbooks.py into models.py. This is because logbook entries now have an optional foreign key to caves, and QMs have a required foreign key to a logbook entry of the trip that created them. So, the two files became circularly dependent. Also, the urls for the person model now allow lookups using their actual first and last name in the url instead of the primary key. We should do similar things for all models, maybe even using the url as a search which results in a page with multiple model instance results if the input is ambiguous (e.g. they only enter a first name). Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8093 by aaron @ 12/13/2008 11:17 PM --- databaseReset.py | 5 +- expo/models.py | 277 +++++++++++++++++++++++++++++++++++++++- expo/models_cave.py | 254 ------------------------------------ expo/models_logbooks.py | 82 ------------ expo/views_logbooks.py | 10 +- parsers/QMs.py | 36 ++++++ urls.py | 20 +-- 7 files changed, 331 insertions(+), 353 deletions(-) delete mode 100644 expo/models_cave.py delete mode 100644 expo/models_logbooks.py create mode 100644 parsers/QMs.py diff --git a/databaseReset.py b/databaseReset.py index 7c3160c..212c590 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -17,6 +17,7 @@ user.is_staff = True user.is_superuser = True user.save() +import parsers.logbooks import parsers.cavetab -import parsers.survex -import parsers.logbooks +import parsers.QMs +import parsers.survex diff --git a/expo/models.py b/expo/models.py index faa79af..930028b 100644 --- a/expo/models.py +++ b/expo/models.py @@ -1,3 +1,276 @@ -from models_cave import * +from django.forms import ModelForm +from django.db import models +from django.contrib import admin from models_survex import * -from models_logbooks import * \ No newline at end of file + +class Expedition(models.Model): + year = models.CharField(max_length=20, unique=True) + name = models.CharField(max_length=100) + start_date = models.DateField(blank=True,null=True) + end_date = models.DateField(blank=True,null=True) + + def __unicode__(self): + return self.year + + def GetPersonExpedition(self, name): + person_expeditions = PersonExpedition.objects.filter(expedition=self) + res = None + for person_expedition in person_expeditions: + for possible_name_from in person_expedition.GetPossibleNameForms(): + #print "nnn", possiblenamefrom + if name == possible_name_from: + assert not res, "Ambiguous: " + name + res = person_expedition + return res + + +class Person(models.Model): + first_name = models.CharField(max_length=100) + last_name = models.CharField(max_length=100) + is_vfho = models.BooleanField() + mug_shot = models.CharField(max_length=100, blank=True,null=True) + def __unicode__(self): + return "%s %s" % (self.first_name, self.last_name) + +class PersonExpedition(models.Model): + expedition = models.ForeignKey(Expedition) + person = models.ForeignKey(Person) + from_date = models.DateField(blank=True,null=True) + to_date = models.DateField(blank=True,null=True) + is_guest = models.BooleanField(default=False) + nickname = models.CharField(max_length=100,blank=True,null=True) + + def GetPossibleNameForms(self): + res = [ ] + if self.person.last_name: + res.append("%s %s" % (self.person.first_name, self.person.last_name)) + res.append("%s %s" % (self.person.first_name, self.person.last_name[0])) + res.append(self.person.first_name) + if self.nickname: + res.append(self.nickname) + return res + + def __unicode__(self): + return "%s: (%s)" % (self.person, self.expedition) + + + + + +#class LogbookSentanceRating(models.Model): +# rating = models.IntegerField() +# person_trip = models.ForeignKey(PersonTrip) +# sentance_number = models.IntegerField() + +# def __unicode__(self): +# return person_trip + +class Area(models.Model): + short_name = models.CharField(max_length=100) + name = models.CharField(max_length=200, blank=True, null=True) + description = models.TextField(blank=True,null=True) + parent = models.ForeignKey('Area', blank=True, null=True) + def __unicode__(self): + if self.parent: + return unicode(self.parent) + u" - " + unicode(self.short_name) + else: + return unicode(self.short_name) + def kat_area(self): + if self.short_name in ["1623", "1626"]: + return self.short_name + elif self.parent: + return self.parent.kat_area() + +class CaveAndEntrance(models.Model): + cave = models.ForeignKey('Cave') + entrance = models.ForeignKey('Entrance') + entrance_letter = models.CharField(max_length=20,blank=True,null=True) + def __unicode__(self): + return unicode(self.cave) + unicode(self.entrance_letter) + +class Cave(models.Model): + official_name = models.CharField(max_length=160) + area = models.ManyToManyField(Area, blank=True, null=True) + kataster_code = models.CharField(max_length=20,blank=True,null=True) + kataster_number = models.CharField(max_length=10,blank=True, null=True) + unofficial_number = models.CharField(max_length=60,blank=True, null=True) + entrances = models.ManyToManyField('Entrance', through='CaveAndEntrance') + explorers = models.TextField(blank=True,null=True) + underground_description = models.TextField(blank=True,null=True) + equipment = models.TextField(blank=True,null=True) + references = models.TextField(blank=True,null=True) + survey = models.TextField(blank=True,null=True) + kataster_status = models.TextField(blank=True,null=True) + underground_centre_line = models.TextField(blank=True,null=True) + notes = models.TextField(blank=True,null=True) + length = models.CharField(max_length=100,blank=True,null=True) + depth = models.CharField(max_length=100,blank=True,null=True) + extent = models.CharField(max_length=100,blank=True,null=True) + survex_file = models.CharField(max_length=100,blank=True,null=True) + def __unicode__(self): + if self.kataster_number: + if self.kat_area(): + return self.kat_area() + u": " + self.kataster_number + else: + return unicode("l") + u": " + self.kataster_number + else: + if self.kat_area(): + return self.kat_area() + u": " + self.unofficial_number + else: + return self.unofficial_number + def kat_area(self): + for a in self.area.all(): + if a.kat_area(): + return a.kat_area() + def entrances(self): + return CaveAndEntrance.objects.filter(cave=self) + def entrancelist(self): + rs = [] + res = "" + for e in CaveAndEntrance.objects.filter(cave=self): + rs.append(e.entrance_letter) + rs.sort() + prevR = None + n = 0 + for r in rs: + if prevR: + if chr(ord(prevR) + 1 ) == r: + prevR = r + n += 1 + else: + if n == 0: + res += ", " + prevR + else: + res += "–" + prevR + else: + prevR = r + n = 0 + res += r + if n == 0: + res += ", " + prevR + else: + res += "–" + prevR + return res + +class LogbookEntry(models.Model): + date = models.DateField() + 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) + # this will be a foreign key of the place the logbook is describing - JT + place = models.CharField(max_length=100,blank=True,null=True) + # adding optional cave reference +# cave = models.ForeignKey(Cave,blank=True,null=True) + text = models.TextField() + + # several PersonTrips point in to this object + + def __unicode__(self): + return "%s: (%s)" % (self.date, self.title) + +class PersonTrip(models.Model): + person_expedition = models.ForeignKey(PersonExpedition) + + # 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 + place = models.CharField(max_length=100) + date = models.DateField() + time_underground = models.CharField(max_length=100) + logbook_entry = models.ForeignKey(LogbookEntry) + is_logbook_entry_author = models.BooleanField() + + def __unicode__(self): + return "%s %s (%s)" % (self.person_expedition, self.place, self.date) + + +class OtherCaveName(models.Model): + name = models.CharField(max_length=160) + cave = models.ForeignKey(Cave) + def __unicode__(self): + return unicode(self.name) + +class SurveyStation(models.Model): + name = models.CharField(max_length=200) + def __unicode__(self): + return unicode(self.name) + +class Entrance(models.Model): + name = models.CharField(max_length=100, blank=True,null=True) + entrance_description = models.TextField(blank=True,null=True) + explorers = models.TextField(blank=True,null=True) + map_description = models.TextField(blank=True,null=True) + location_description = models.TextField(blank=True,null=True) + approach = models.TextField(blank=True,null=True) + underground_description = models.TextField(blank=True,null=True) + photo = models.TextField(blank=True,null=True) + MARKING_CHOICES = ( + ('P', 'Paint'), + ('P?', 'Paint (?)'), + ('T', 'Tag'), + ('T?', 'Tag (?)'), + ('R', 'Retagged'), + ('S', 'Spit'), + ('S?', 'Spit (?)'), + ('U', 'Unmarked'), + ('?', 'Unknown')) + marking = models.CharField(max_length=2, choices=MARKING_CHOICES) + marking_comment = models.TextField(blank=True,null=True) + FINDABLE_CHOICES = ( + ('?', 'To be confirmed ...'), + ('S', 'Surveyed'), + ('L', 'Lost'), + ('R', 'Refindable')) + findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True) + findability_description = models.TextField(blank=True,null=True) + alt = models.TextField(blank=True, null=True) + northing = models.TextField(blank=True, null=True) + easting = models.TextField(blank=True, null=True) + tag_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="tag_station") + exact_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="exact_station") + other_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="other_station") + other_description = models.TextField(blank=True,null=True) + bearings = models.TextField(blank=True,null=True) + def __unicode__(self): + a = CaveAndEntrance.objects.filter(entrance = self) + name = u'' + if self.name: + name = unicode(self.name) + u' ' + if len(a) == 1: + return name + unicode(a[0]) + return name + unicode(a) + def marking_val(self): + for m in self.MARKING_CHOICES: + if m[0] == self.marking: + return m[1] + def findability_val(self): + for f in self.FINDABLE_CHOICES: + if f[0] == self.findability: + return f[1] + +class QM(models.Model): + #based on qm.csv in trunk/expoweb/smkridge/204 which has the fields: + #"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment" + found_by = models.ForeignKey(LogbookEntry, related_name='QMs_found',blank=True, null=True ) + ticked_off_by = models.ForeignKey(LogbookEntry, related_name='QMs_ticked_off',null=True,blank=True) + number = models.IntegerField() + GRADE_CHOICES=( + ('A', 'A: Large obvious lead'), + ('B', 'B: Average lead'), + ('C', 'C: Tight unpromising lead'), + ('D', 'D: Dig'), + ('X', 'X: Unclimbable aven') + ) + grade = models.CharField(max_length=1, choices=GRADE_CHOICES) + location_description = models.TextField(blank=True) + #should be a foreignkey to surveystation + nearest_station_description = models.CharField(max_length=400,null=True,blank=True) + nearest_station = models.OneToOneField(SurveyStation,null=True,blank=True) + area = models.CharField(max_length=100,blank=True,null=True) + completion_description = models.TextField(blank=True,null=True) + comment=models.TextField(blank=True,null=True) + #the below are unneeded- instead use the date fields of the QM's trips + #dateFound = models.DateField(blank=True) + #dateKilled = models.DateField(blank=True) + def __str__(self): + QMnumber=str(self.found_by.cave)+'-'+str(self.found_by.date.year)+"-"+str(self.number)+self.grade + return str(QMnumber) \ No newline at end of file diff --git a/expo/models_cave.py b/expo/models_cave.py deleted file mode 100644 index 85ac928..0000000 --- a/expo/models_cave.py +++ /dev/null @@ -1,254 +0,0 @@ -from django.db import models -import models_logbooks - -class Area(models.Model): - short_name = models.CharField(max_length=100) - name = models.CharField(max_length=200, blank=True, null=True) - description = models.TextField(blank=True,null=True) - parent = models.ForeignKey('Area', blank=True, null=True) - def __unicode__(self): - if self.parent: - return unicode(self.parent) + u" - " + unicode(self.short_name) - else: - return unicode(self.short_name) - def kat_area(self): - if self.short_name in ["1623", "1626"]: - return self.short_name - elif self.parent: - return self.parent.kat_area() - -class CaveAndEntrance(models.Model): - cave = models.ForeignKey('Cave') - entrance = models.ForeignKey('Entrance') - entrance_letter = models.CharField(max_length=20,blank=True,null=True) - def __unicode__(self): - return unicode(self.cave) + unicode(self.entrance_letter) - -class Cave(models.Model): - official_name = models.CharField(max_length=160) - area = models.ManyToManyField(Area, blank=True, null=True) - kataster_code = models.CharField(max_length=20,blank=True,null=True) - kataster_number = models.CharField(max_length=10,blank=True, null=True) - unofficial_number = models.CharField(max_length=60,blank=True, null=True) - entrances = models.ManyToManyField('Entrance', through='CaveAndEntrance') - explorers = models.TextField(blank=True,null=True) - underground_description = models.TextField(blank=True,null=True) - equipment = models.TextField(blank=True,null=True) - references = models.TextField(blank=True,null=True) - survey = models.TextField(blank=True,null=True) - kataster_status = models.TextField(blank=True,null=True) - underground_centre_line = models.TextField(blank=True,null=True) - notes = models.TextField(blank=True,null=True) - length = models.CharField(max_length=100,blank=True,null=True) - depth = models.CharField(max_length=100,blank=True,null=True) - extent = models.CharField(max_length=100,blank=True,null=True) - survex_file = models.CharField(max_length=100,blank=True,null=True) - def __unicode__(self): - if self.kataster_number: - if self.kat_area(): - return self.kat_area() + u": " + self.kataster_number - else: - return unicode("l") + u": " + self.kataster_number - else: - if self.kat_area(): - return self.kat_area() + u": " + self.unofficial_number - else: - return self.unofficial_number - def kat_area(self): - for a in self.area.all(): - if a.kat_area(): - return a.kat_area() - def entrances(self): - return CaveAndEntrance.objects.filter(cave=self) - def entrancelist(self): - rs = [] - res = "" - for e in CaveAndEntrance.objects.filter(cave=self): - rs.append(e.entrance_letter) - rs.sort() - prevR = None - n = 0 - for r in rs: - if prevR: - if chr(ord(prevR) + 1 ) == r: - prevR = r - n += 1 - else: - if n == 0: - res += ", " + prevR - else: - res += "–" + prevR - else: - prevR = r - n = 0 - res += r - if n == 0: - res += ", " + prevR - else: - res += "–" + prevR - return res - - -class OtherCaveName(models.Model): - name = models.CharField(max_length=160) - cave = models.ForeignKey(Cave) - def __unicode__(self): - return unicode(self.name) - -class SurveyStation(models.Model): - name = models.CharField(max_length=200) - def __unicode__(self): - return unicode(self.name) - -class Entrance(models.Model): - name = models.CharField(max_length=100, blank=True,null=True) - entrance_description = models.TextField(blank=True,null=True) - explorers = models.TextField(blank=True,null=True) - map_description = models.TextField(blank=True,null=True) - location_description = models.TextField(blank=True,null=True) - approach = models.TextField(blank=True,null=True) - underground_description = models.TextField(blank=True,null=True) - photo = models.TextField(blank=True,null=True) - MARKING_CHOICES = ( - ('P', 'Paint'), - ('P?', 'Paint (?)'), - ('T', 'Tag'), - ('T?', 'Tag (?)'), - ('R', 'Retagged'), - ('S', 'Spit'), - ('S?', 'Spit (?)'), - ('U', 'Unmarked'), - ('?', 'Unknown')) - marking = models.CharField(max_length=2, choices=MARKING_CHOICES) - marking_comment = models.TextField(blank=True,null=True) - FINDABLE_CHOICES = ( - ('?', 'To be confirmed ...'), - ('S', 'Surveyed'), - ('L', 'Lost'), - ('R', 'Refindable')) - findability = models.CharField(max_length=1, choices=FINDABLE_CHOICES, blank=True, null=True) - findability_description = models.TextField(blank=True,null=True) - alt = models.TextField(blank=True, null=True) - northing = models.TextField(blank=True, null=True) - easting = models.TextField(blank=True, null=True) - tag_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="tag_station") - exact_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="exact_station") - other_station = models.ForeignKey(SurveyStation, blank=True,null=True, related_name="other_station") - other_description = models.TextField(blank=True,null=True) - bearings = models.TextField(blank=True,null=True) - def __unicode__(self): - a = CaveAndEntrance.objects.filter(entrance = self) - name = u'' - if self.name: - name = unicode(self.name) + u' ' - if len(a) == 1: - return name + unicode(a[0]) - return name + unicode(a) - def marking_val(self): - for m in self.MARKING_CHOICES: - if m[0] == self.marking: - return m[1] - def findability_val(self): - for f in self.FINDABLE_CHOICES: - if f[0] == self.findability: - return f[1] - -class Expedition(models.Model): - year = models.CharField(max_length=20, unique=True) - name = models.CharField(max_length=100) - start_date = models.DateField(blank=True,null=True) - end_date = models.DateField(blank=True,null=True) - - def __str__(self): - return self.year - - def GetPersonExpedition(self, name): - if name == "Dour": - name = "Anthony Day" - personyears = PersonExpedition.objects.filter(expedition=self) - res = None - for personyear in personyears: - if name == "%s %s" % (personyear.person.first_name, personyear.person.last_name): - assert not res, "Ambiguous:" + name - res = personyear - if name == "%s %s" % (personyear.person.first_name, personyear.person.last_name[0]): - assert not res, "Ambiguous:" + name - res = personyear - if name == personyear.person.first_name: - assert not res, "Ambiguous:" + name - res = personyear - return res - -class Person(models.Model): - first_name = models.CharField(max_length=100) - last_name = models.CharField(max_length=100) - is_guest = models.BooleanField() - is_vfho = models.BooleanField() - mug_shot = models.CharField(max_length=100, blank=True,null=True) - def __str__(self): - return "%s %s" % (self.first_name, self.last_name) - -class PersonExpedition(models.Model): - expedition = models.ForeignKey(Expedition) - person = models.ForeignKey(Person) - from_date = models.DateField(blank=True,null=True) - to_date = models.DateField(blank=True,null=True) - nickname = models.CharField(max_length=100,blank=True,null=True) - def __str__(self): - return "%s: (%s)" % (self.person, self.expedition) - -class LogbookEntry(models.Model): - date = models.DateField() - author = models.ForeignKey(PersonExpedition,blank=True,null=True) - title = models.CharField(max_length=100) - - # this will be a foreign key - place = models.CharField(max_length=100,blank=True,null=True) - text = models.TextField() - - #cavers = models.ManyToManyField(PersonYear) - #tu = models.CharField(max_length=50) - def __str__(self): - return "%s: (%s)" % (self.date, self.title) - -class PersonTrip(models.Model): - personexpedition = models.ForeignKey(PersonExpedition) - place = models.CharField(max_length=100) # this will be a foreign key - date = models.DateField() - timeunderground = models.CharField(max_length=100) - logbookentry = models.ForeignKey(LogbookEntry) - - #is_author = models.BooleanField() - - def __str__(self): - return "%s %s (%s)" % (self.personexpedition, self.place, self.date) - -class QM(models.Model): - #based on qm.csv in trunk/expoweb/smkridge/204 which has the fields: - #"Number","Grade","Area","Description","Page reference","Nearest station","Completion description","Comment" - found_by = models.ForeignKey(PersonTrip, related_name='QMs_found',) - ticked_off_by = models.ForeignKey(PersonTrip, related_name='QMs_ticked_off',null=True,blank=True) - #the cave field is unneeded- go through trips - #cave = models.ForeignKey(Cave, edit_inline=models.TABULAR, num_in_admin=3) - number_in_year = models.IntegerField() - GRADE_CHOICES=( - ('A', 'A: Large obvious lead'), - ('B', 'B: Average lead'), - ('C', 'C: Tight unpromising lead'), - ('D', 'D: Dig'), - ('X', 'X: Unclimbable aven') - ) - grade = models.CharField(max_length=1, choices=GRADE_CHOICES) - location_description = models.TextField(blank=True) - #should be a foreignkey to surveystation - nearest_station = models.CharField(max_length=400,blank=True) - completion_description = models.TextField(blank=True) - comment=models.TextField(blank=True) - #the below are unneeded- instead use the date fields of the QM's trips - #dateFound = models.DateField(blank=True) - #dateKilled = models.DateField(blank=True) - def __str__(self): - QMnumber=str(self.found_by.date.year)+"-"+str(self.number_in_year)+self.grade - return str(QMnumber) - - diff --git a/expo/models_logbooks.py b/expo/models_logbooks.py deleted file mode 100644 index 89f2125..0000000 --- a/expo/models_logbooks.py +++ /dev/null @@ -1,82 +0,0 @@ -from django.db import models -from django.contrib import admin -from django.forms import ModelForm - -class Expedition(models.Model): - year = models.CharField(max_length=20, unique=True) - name = models.CharField(max_length=100) - start_date = models.DateField(blank=True,null=True) - end_date = models.DateField(blank=True,null=True) - - def __unicode__(self): - return self.year - - def GetPersonExpedition(self, name): - person_expeditions = PersonExpedition.objects.filter(expedition=self) - res = None - for person_expedition in person_expeditions: - for possible_name_from in person_expedition.GetPossibleNameForms(): - #print "nnn", possiblenamefrom - if name == possible_name_from: - assert not res, "Ambiguous: " + name - res = person_expedition - return res - - -class Person(models.Model): - first_name = models.CharField(max_length=100) - last_name = models.CharField(max_length=100) - is_vfho = models.BooleanField() - mug_shot = models.CharField(max_length=100, blank=True,null=True) - def __unicode__(self): - return "%s %s" % (self.first_name, self.last_name) - -class PersonExpedition(models.Model): - expedition = models.ForeignKey(Expedition) - person = models.ForeignKey(Person) - from_date = models.DateField(blank=True,null=True) - to_date = models.DateField(blank=True,null=True) - is_guest = models.BooleanField() - nickname = models.CharField(max_length=100,blank=True,null=True) - - def GetPossibleNameForms(self): - res = [ ] - if self.person.last_name: - res.append("%s %s" % (self.person.first_name, self.person.last_name)) - res.append("%s %s" % (self.person.first_name, self.person.last_name[0])) - res.append(self.person.first_name) - if self.nickname: - res.append(self.nickname) - return res - - def __unicode__(self): - return "%s: (%s)" % (self.person, self.expedition) - - -class LogbookEntry(models.Model): - date = models.DateField() - 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) - - # this will be a foreign key of the place the logbook is describing - place = models.CharField(max_length=100,blank=True,null=True) - text = models.TextField() - - # several PersonTrips point in to this object - - def __unicode__(self): - return "%s: (%s)" % (self.date, self.title) - -class PersonTrip(models.Model): - person_expedition = models.ForeignKey(PersonExpedition) - - # 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 - place = models.CharField(max_length=100) - date = models.DateField() - time_underground = models.CharField(max_length=100) - logbook_entry = models.ForeignKey(LogbookEntry) - is_logbook_entry_author = models.BooleanField() - - def __unicode__(self): - return "%s %s (%s)" % (self.person_expedition, self.place, self.date) \ No newline at end of file diff --git a/expo/views_logbooks.py b/expo/views_logbooks.py index b44c770..ac1954a 100644 --- a/expo/views_logbooks.py +++ b/expo/views_logbooks.py @@ -2,13 +2,17 @@ from django.shortcuts import render_to_response from troggle.expo.models import Expedition, Person, PersonExpedition, PersonTrip, LogbookEntry import troggle.settings as settings import search +import re def personindex(request): persons = Person.objects.all() return render_to_response('personindex.html', {'persons': persons, 'settings': settings}) -def person(request, person_id): - person = Person.objects.filter(id = person_id)[0] +def person(request, person_id, first_name, last_name): + if first_name == '' or last_name == '': + person = Person.objects.filter(id = person_id)[0] + else: + person = Person.objects.filter(first_name = first_name, last_name = last_name)[0] return render_to_response('person.html', {'person': person, 'settings': settings}) def logbookentry(request, logbookentry_id): @@ -25,4 +29,4 @@ def logbookSearch(request, extra): return render_to_response('logbooksearch.html', { 'query_string': query_string, 'found_entries': found_entries, 'settings': settings}) - #context_instance=RequestContext(request)) \ No newline at end of file + #context_instance=RequestContext(request)) diff --git a/parsers/QMs.py b/parsers/QMs.py new file mode 100644 index 0000000..44c38c7 --- /dev/null +++ b/parsers/QMs.py @@ -0,0 +1,36 @@ +import csv +import settings +from expo.models import QM, LogbookEntry, Cave +from datetime import * +import re + +#sorry that the below code is ugly. I'll fix it sometime, really! - AC + +QM.objects.all().delete() + + + +def parseSteinbrQMs(): + try: + steinBr=Cave.objects.get(official_name="Steinbrückenhöhle") + except Cave.DoesNotExist: + print "Steinbruckenhoehle is not in the database. Please run parsers.cavetab first." + return + + + qmPath = settings.EXPOWEB+r"smkridge/204/qm.csv" + qmReader = csv.reader(open(qmPath,'r'),dialect="excel-tab") + qmReader.next() # Skip header row + for line in qmReader: + year=int(line[0][1:5]) + + #check if placeholder exists for given year, create it if not + placeholder, hadToCreate = LogbookEntry.objects.get_or_create(date__year=year, text="placeholder for QMs in 204", defaults={"date": date(year, 1, 1),"cave":steinBr}) + if hadToCreate: + print "204 placeholder logbook entry for " + str(year) + " added to database" + QMnum=re.match(r".*?-\d*?-X?(?P\d*)",line[0]).group("numb") + newQM = QM(found_by=placeholder,number=QMnum,grade=line[1],area=line[2],location_description=line[3],nearest_station_description=line[4],completion_description=line[5],comment=line[6]) + newQM.save() + print "QM "+str(newQM) + " added to database" + +parseSteinbrQMs() \ No newline at end of file diff --git a/urls.py b/urls.py index 755054c..22e4336 100644 --- a/urls.py +++ b/urls.py @@ -6,11 +6,11 @@ admin.autodiscover() urlpatterns = patterns('', # Example: - (r'^cave/$', caveindex), - (r'^cave/(?P[^/]+)/$', cave), - (r'^cave/(?P[^/]+)/(?P[^/]?)$', ent), + (r'^cave/?$', caveindex), + (r'^cave/(?P[^/]+)/?$', cave), + (r'^cave/(?P[^/]+)/?(?P[^/])$', ent), #(r'^cave/(?P[^/]+)/edit/$', edit_cave), - (r'^cavesearch/$', caveSearch), + (r'^cavesearch', caveSearch), (r'^survex/(?P.*)\.index$', index), (r'^survex/(?P.*)\.svx$', svx), @@ -18,15 +18,15 @@ urlpatterns = patterns('', (r'^survex/(?P.*)\.log$', log), (r'^survex/(?P.*)\.err$', err), - (r'^person/$', personindex), - (r'^person/(.*)$', person), + (r'^person/?$', personindex), + (r'^person/(?P\d*)(?P[a-zA-Z]*)[-_/\.\s(\%20)]*(?P[a-zA-Z]*)/?$', person), - (r'^logbookentry/(.*)$', logbookentry), - (r'^logbooksearch/(.*)$', logbookSearch), + (r'^logbookentry/(.*)/?$', logbookentry), + (r'^logbooksearch/(.*)/?$', logbookSearch), - (r'^statistics/$', stats), + (r'^statistics/?$', stats), - (r'^admin/doc/', include('django.contrib.admindocs.urls')), + (r'^admin/doc/?', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), (r'^site_media/(?P.*)$', 'django.views.static.serve',