diff --git a/expo/models.py b/expo/models.py index b3a7f5b..35d7431 100644 --- a/expo/models.py +++ b/expo/models.py @@ -5,24 +5,28 @@ from django.db import models from django.contrib import admin from django.core.files.storage import FileSystemStorage from django.contrib.auth.models import User +from django.contrib.contenttypes.models import ContentType import os from django.conf import settings import datetime from models_survex import * -class Model(models.Model): +#This class is for adding fields and methods which all of our models will have. +class TroggleModel(models.Model): new_since_parsing = models.BooleanField(default=False) - def save(self): - new_since_parsing = True - super(Model, self).save() + + def get_admin_url(self): + return settings.URL_ROOT + "/admin/expo/" + self._meta.object_name + "/" + str(self.pk) -class Expedition(Model): + class Meta: + abstract = True + +class Expedition(TroggleModel): year = models.CharField(max_length=20, unique=True) 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 @@ -65,7 +69,7 @@ class Expedition(Model): -class Person(Model): +class Person(TroggleModel): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.") @@ -119,7 +123,7 @@ class Person(Model): #self.notability = 0.0 # set temporarily -class PersonExpedition(Model): +class PersonExpedition(TroggleModel): expedition = models.ForeignKey(Expedition) person = models.ForeignKey(Person) date_from = models.DateField(blank=True,null=True) @@ -197,7 +201,7 @@ class PersonExpedition(Model): def get_absolute_url(self): return settings.URL_ROOT + '/personexpedition/' + str(self.person.first_name) + '_' + str(self.person.last_name) + '/' +self.expedition.year -class LogbookEntry(models.Model): +class LogbookEntry(TroggleModel): date = models.DateField() 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 @@ -229,7 +233,7 @@ class LogbookEntry(models.Model): def get_previous_by_id(self): Logbook.objects.get(id=self.id-1) -class PersonTrip(models.Model): +class PersonTrip(TroggleModel): person_expedition = models.ForeignKey(PersonExpedition,null=True) # this will be a foreign key of the place(s) the trip went through @@ -252,7 +256,7 @@ class PersonTrip(models.Model): # move following classes into models_cave # -class Area(models.Model): +class Area(TroggleModel): short_name = models.CharField(max_length=100) name = models.CharField(max_length=200, blank=True, null=True) description = models.TextField(blank=True,null=True) @@ -268,14 +272,14 @@ class Area(models.Model): elif self.parent: return self.parent.kat_area() -class CaveAndEntrance(models.Model): +class CaveAndEntrance(TroggleModel): 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): +class Cave(TroggleModel): # too much here perhaps official_name = models.CharField(max_length=160) area = models.ManyToManyField(Area, blank=True, null=True) @@ -357,18 +361,18 @@ class Cave(models.Model): -class OtherCaveName(models.Model): +class OtherCaveName(TroggleModel): name = models.CharField(max_length=160) cave = models.ForeignKey(Cave) def __unicode__(self): return unicode(self.name) -class SurveyStation(models.Model): +class SurveyStation(TroggleModel): name = models.CharField(max_length=200) def __unicode__(self): return unicode(self.name) -class Entrance(models.Model): +class Entrance(TroggleModel): 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) @@ -421,7 +425,7 @@ class Entrance(models.Model): if f[0] == self.findability: return f[1] -class CaveArea(models.Model): +class CaveArea(TroggleModel): description = models.TextField() name = models.CharField(max_length=200, unique = True) cave = models.ForeignKey('Cave') @@ -429,7 +433,7 @@ class CaveArea(models.Model): survexFile = models.CharField(max_length=200) -class QM(models.Model): +class QM(TroggleModel): #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 ) @@ -458,7 +462,7 @@ class QM(models.Model): return str(QMnumber) photoFileStorage = FileSystemStorage(location=settings.EXPOWEB+'photos', base_url=settings.PHOTOS_URL) -class Photo(models.Model): +class Photo(TroggleModel): caption = models.CharField(max_length=1000,blank=True,null=True) contains_person_trip = models.ManyToManyField(PersonTrip,blank=True,null=True) contains_person = models.ManyToManyField(Person,blank=True,null=True) @@ -486,7 +490,7 @@ def get_scan_path(instance, filename): number="%02d" % instance.survey.wallet_number + str(instance.survey.wallet_letter) #using %02d string formatting because convention was 2009#01 return os.path.join('./',year,year+r'#'+number,instance.contents+str(instance.number_in_wallet)+r'.jpg') -class ScannedImage(models.Model): +class ScannedImage(TroggleModel): file = models.ImageField(storage=scansFileStorage, upload_to=get_scan_path) scanned_by = models.ForeignKey(Person,blank=True, null=True) scanned_on = models.DateField(null=True) @@ -506,7 +510,7 @@ class ScannedImage(models.Model): def __str__(self): return get_scan_path(self,'') -class Survey(models.Model): +class Survey(TroggleModel): expedition = models.ForeignKey('Expedition') wallet_number = models.IntegerField(blank=True,null=True) wallet_letter = models.CharField(max_length=1,blank=True,null=True) diff --git a/expo/views_caves.py b/expo/views_caves.py index 005a8cd..487bbc9 100644 --- a/expo/views_caves.py +++ b/expo/views_caves.py @@ -14,7 +14,7 @@ def caveindex(request): def cavehref(request, cave_id='', offical_name=''): try: cave = Cave.objects.get(kataster_number=cave_id) - except DoesNotExist: + except Cave.DoesNotExist: cave = Cave.objects.get(unofficial_number=cave_id) return render_response(request,'cave.html', {'cave': cave,}) diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 9c5a057..c2c46a4 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -252,7 +252,6 @@ 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() # The below is all unnecessary, just use the built in get_previous_by_date and get_next_by_date @@ -269,7 +268,6 @@ def SetDatesFromLogbookEntries(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_to = max([personexpedition.date_to for personexpedition in expedition.personexpedition_set.all() if personexpedition.date_to] or [None]) - expedition.dates_guessed = True expedition.save() # The below has been replaced with the methods get_next_by_id and get_previous_by_id diff --git a/templates/base.html b/templates/base.html index 5d173f3..8c79f87 100644 --- a/templates/base.html +++ b/templates/base.html @@ -32,7 +32,7 @@ | Log in {% endif %} {% endblock%} - | Home + | Home | {% block editLink %} {% endblock %} diff --git a/templates/cave.html b/templates/cave.html index c97b9cd..d76a211 100644 --- a/templates/cave.html +++ b/templates/cave.html @@ -1,6 +1,6 @@ {% extends "cavebase.html" %} {% load wiki_markup %} - +{% block editLink %}Edit cave {{cave|wiki_to_html_short}}{% endblock %} {% block content %}
diff --git a/templates/expedition.html b/templates/expedition.html index b6be4ac..4f91abd 100644 --- a/templates/expedition.html +++ b/templates/expedition.html @@ -2,7 +2,7 @@ {% load wiki_markup %} {% block title %}Expedition {{expedition.name}}{% endblock %} - +{% block editLink %}Edit expedition {{expedition|wiki_to_html_short}}{% endblock %} {% block content %}

{{expedition.name}}: {{expedition.date_from}} - {{expedition.date_to}}

diff --git a/templates/logbookentry.html b/templates/logbookentry.html index 2bfb564..690d21c 100644 --- a/templates/logbookentry.html +++ b/templates/logbookentry.html @@ -2,7 +2,7 @@ {% load wiki_markup %} {% block title %}Logbook {{logbookentry.id}}{% endblock %} - +{% block editLink %}Edit logbook entry {{logbookentry|wiki_to_html_short}}{% endblock %} {% block content %}

{{logbookentry.title|safe}}

diff --git a/templates/person.html b/templates/person.html index aed5989..d28f82a 100644 --- a/templates/person.html +++ b/templates/person.html @@ -3,6 +3,8 @@ {% block title %}Person {{person|wiki_to_html_short}}{% endblock %} +{% block editLink %}| Edit person {{person|wiki_to_html_short}}{% endblock %} + {% block contentheader %}

{{person|wiki_to_html_short}}

{% endblock %} diff --git a/urls.py b/urls.py index 6c54916..49eb1b3 100644 --- a/urls.py +++ b/urls.py @@ -34,9 +34,9 @@ urlpatterns = patterns('', - (r'^cave/(?P[^/]+)/?(?P[^/])$', ent), + url(r'^cave/(?P[^/]+)/?(?P[^/])$', ent), #(r'^cave/(?P[^/]+)/edit/$', edit_cave), - (r'^cavesearch', caveSearch), + #(r'^cavesearch', caveSearch), url(r'^cavearea', caveArea, name="caveArea"), url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"),