diff options
Diffstat (limited to 'core/models.py')
-rw-r--r-- | core/models.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/core/models.py b/core/models.py index 8527015..a78e49b 100644 --- a/core/models.py +++ b/core/models.py @@ -15,7 +15,7 @@ from django.template import Context, loader import settings getcontext().prec=2 #use 2 significant figures for decimal calculations -from models_survex import * +from troggle.core.models_survex import * def get_related_by_wikilinks(wiki_text): @@ -55,7 +55,7 @@ class TroggleModel(models.Model): return urlparse.urljoin(settings.URL_ROOT, "/admin/core/" + self.object_name().lower() + "/" + str(self.pk)) class Meta: - abstract = True + abstract = True class TroggleImageModel(ImageModel): new_since_parsing = models.BooleanField(default=False, editable=False) @@ -68,7 +68,7 @@ class TroggleImageModel(ImageModel): class Meta: - abstract = True + abstract = True # # single Expedition, usually seen by year @@ -125,7 +125,7 @@ class ExpeditionDay(TroggleModel): 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.") + is_vfho = models.BooleanField(help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False) mug_shot = models.CharField(max_length=100, blank=True,null=True) blurb = models.TextField(blank=True,null=True) @@ -134,13 +134,13 @@ class Person(TroggleModel): #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() + #bisnotable = models.BooleanField(default=False) user = models.OneToOneField(User, null=True, blank=True) def get_absolute_url(self): return urlparse.urljoin(settings.URL_ROOT,reverse('person',kwargs={'first_name':self.first_name,'last_name':self.last_name})) class Meta: - verbose_name_plural = "People" + verbose_name_plural = "People" class Meta: ordering = ('orderref',) # "Wookey" makes too complex for: ('last_name', 'first_name') @@ -264,13 +264,13 @@ class LogbookEntry(TroggleModel): if item == "cave": #Allow a logbookentries cave to be directly accessed despite not having a proper foreignkey return CaveSlug.objects.get(slug = self.cave_slug).cave return super(LogbookEntry, self).__getattribute__(item) - + def __init__(self, *args, **kwargs): - if "cave" in kwargs.keys(): - if kwargs["cave"] is not None: - kwargs["cave_slug"] = CaveSlug.objects.get(cave = kwargs["cave"], primary = True).slug - kwargs.pop("cave") - return super(LogbookEntry, self).__init__(*args, **kwargs) + if "cave" in kwargs.keys(): + if kwargs["cave"] is not None: + kwargs["cave_slug"] = CaveSlug.objects.get(cave=kwargs["cave"], primary=True).slug + kwargs.pop("cave") + return super(LogbookEntry, self).__init__(*args, **kwargs) def isLogbookEntry(self): # Function used in templates return True @@ -312,7 +312,7 @@ class PersonTrip(TroggleModel): #date = models.DateField() #MJG wants to KILL THIS (redundant information) time_underground = models.FloatField(help_text="In decimal hours") logbook_entry = models.ForeignKey(LogbookEntry) - is_logbook_entry_author = models.BooleanField() + is_logbook_entry_author = models.BooleanField(default=False) # sequencing by person (difficult to solve locally) @@ -371,7 +371,7 @@ class CaveAndEntrance(models.Model): class CaveSlug(models.Model): cave = models.ForeignKey('Cave') slug = models.SlugField(max_length=50, unique = True) - primary = models.BooleanField() + primary = models.BooleanField(default=False) class Cave(TroggleModel): @@ -520,11 +520,11 @@ class Cave(TroggleModel): areas = self.area.all() lowestareas = list(areas) for area in areas: - if area.parent in areas: - try: - lowestareas.remove(area.parent) - except: - pass + if area.parent in areas: + try: + lowestareas.remove(area.parent) + except: + pass return lowestareas[0] def getCaveByReference(reference): @@ -546,7 +546,7 @@ class OtherCaveName(TroggleModel): class EntranceSlug(models.Model): entrance = models.ForeignKey('Entrance') slug = models.SlugField(max_length=50, unique = True) - primary = models.BooleanField() + primary = models.BooleanField(default=False) class Entrance(TroggleModel): name = models.CharField(max_length=100, blank=True,null=True) @@ -608,21 +608,21 @@ class Entrance(TroggleModel): s = SurvexStation.objects.lookup(self.tag_station) return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z) except: - return r + "%s Tag Station not in dataset" % self.tag_station + return r + "%s Tag Station not in dataset" % self.tag_station if self.exact_station: try: s = SurvexStation.objects.lookup(self.exact_station) return r + "%0.0fE %0.0fN %0.0fAlt" % (s.x, s.y, s.z) except: - return r + "%s Exact Station not in dataset" % self.tag_station + return r + "%s Exact Station not in dataset" % self.tag_station if self.other_station: try: s = SurvexStation.objects.lookup(self.other_station) return r + "%0.0fE %0.0fN %0.0fAlt %s" % (s.x, s.y, s.z, self.other_description) except: - return r + "%s Other Station not in dataset" % self.tag_station + return r + "%s Other Station not in dataset" % self.tag_station if self.FINDABLE_CHOICES == "S": - r += "ERROR, Entrance has been surveyed but has no survex point" + r += "ERROR, Entrance has been surveyed but has no survex point" if self.bearings: return r + self.bearings return r @@ -657,7 +657,7 @@ class Entrance(TroggleModel): return SurvexStation.objects.lookup(self.tag_station) def needs_surface_work(self): - return self.findability != "S" or not self.has_photo or self.marking != "T" + return self.findability != "S" or not self.has_photo or self.marking != "T" def get_absolute_url(self): @@ -754,10 +754,10 @@ class QM(TroggleModel): comment=models.TextField(blank=True,null=True) def __unicode__(self): - return u"%s %s" % (self.code(), self.grade) + return u"%s %s" % (self.code(), self.grade) def code(self): - return u"%s-%s-%s" % (unicode(self.found_by.cave)[6:], self.found_by.date.year, self.number) + return u"%s-%s-%s" % (unicode(self.found_by.cave)[6:], self.found_by.date.year, self.number) def get_absolute_url(self): #return settings.URL_ROOT + '/cave/' + self.found_by.cave.kataster_number + '/' + str(self.found_by.date.year) + '-' + '%02d' %self.number @@ -770,7 +770,7 @@ class QM(TroggleModel): return QM.objects.get(id=self.id-1) def wiki_link(self): - return u"%s%s%s" % ('[[QM:',self.code(),']]') + return u"%s%s%s" % ('[[QM:',self.code(),']]') photoFileStorage = FileSystemStorage(location=settings.PHOTOS_ROOT, base_url=settings.PHOTOS_URL) class DPhoto(TroggleImageModel): @@ -825,7 +825,7 @@ class ScannedImage(TroggleImageModel): #This is an ugly hack to deal with the #s in our survey scan paths. The correct thing is to write a custom file storage backend which calls urlencode on the name for making file.url but not file.path. def correctURL(self): - return string.replace(self.file.url,r'#',r'%23') + return string.replace(self.file.url,r'#',r'%23') def __unicode__(self): return get_scan_path(self,'') @@ -852,10 +852,10 @@ class Survey(TroggleModel): return self.expedition.year+"#"+"%02d" % int(self.wallet_number) def notes(self): - return self.scannedimage_set.filter(contents='notes') + return self.scannedimage_set.filter(contents='notes') def plans(self): - return self.scannedimage_set.filter(contents='plan') + return self.scannedimage_set.filter(contents='plan') def elevations(self): - return self.scannedimage_set.filter(contents='elevation') + return self.scannedimage_set.filter(contents='elevation') |