2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 16:51:54 +00:00

[svn] Removed redundant fields "date" and "place" from Persontrip model. A PersonTrip's date and place are stored in its parent LogbookEntry. PersonTrips are the people who participate in the trip in a LogbookEntry, so it would make no sense to have different dates and places from the LogbookEntry they are foreignkeyed to.

This commit is contained in:
substantialnoninfringinguser 2009-06-09 00:29:00 +01:00
parent 012d948193
commit 006becf6ca
3 changed files with 27 additions and 14 deletions

View File

@ -90,7 +90,7 @@ admin.site.register(PersonRole)
admin.site.register(PersonExpedition,PersonExpeditionAdmin) admin.site.register(PersonExpedition,PersonExpeditionAdmin)
admin.site.register(Role) admin.site.register(Role)
admin.site.register(LogbookEntry, LogbookEntryAdmin) admin.site.register(LogbookEntry, LogbookEntryAdmin)
admin.site.register(PersonTrip) #admin.site.register(PersonTrip)
admin.site.register(QM, QMAdmin) admin.site.register(QM, QMAdmin)
admin.site.register(Survey, SurveyAdmin) admin.site.register(Survey, SurveyAdmin)
admin.site.register(ScannedImage) admin.site.register(ScannedImage)

View File

@ -238,7 +238,7 @@ class LogbookEntry(TroggleModel):
author = models.ForeignKey(PersonExpedition,blank=True,null=True) # the person who writes it up doesn't have to have been on the trip 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) 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) place = models.CharField(max_length=100,blank=True,null=True,help_text="Only use this if you haven't chosen a cave")
text = models.TextField() text = models.TextField()
slug = models.SlugField(max_length=50) slug = models.SlugField(max_length=50)
#href = models.CharField(max_length=100) #href = models.CharField(max_length=100)
@ -270,28 +270,36 @@ class PersonTrip(TroggleModel):
# this will be a foreign key of the place(s) the trip went through # 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 # possibly a trip has a plurality of triplets pointing into it
place = models.CharField(max_length=100) #place = models.CharField(max_length=100)
# should add cave thing here (copied from logbook maybe) #date = models.DateField()
date = models.DateField() time_underground = models.FloatField(help_text="In decimal hours")
time_underground = models.FloatField()
logbook_entry = models.ForeignKey(LogbookEntry) logbook_entry = models.ForeignKey(LogbookEntry)
is_logbook_entry_author = models.BooleanField() is_logbook_entry_author = models.BooleanField()
def date(self):
return self.logbook_entry.date
def place(self):
if self.logbook_entry.cave:
return self.logbook_entry.cave
else:
return self.logbook_entry.place
#persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True) #persontrip_next = models.ForeignKey('PersonTrip', related_name='pnext', blank=True,null=True)
#persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True) #persontrip_prev = models.ForeignKey('PersonTrip', related_name='pprev', blank=True,null=True)
def __unicode__(self): def __unicode__(self):
return "%s %s (%s)" % (self.person_expedition, self.place, self.date) return "%s %s (%s)" % (self.person_expedition, self.place(), self.date())
def get_persons_next_trip(self): def get_persons_next_trip(self):
try: try:
return PersonTrip.objects.filter(person_expedition__person=self.person_expedition.person, date__gt=self.date)[0] return PersonTrip.objects.filter(person_expedition__person=self.person_expedition.person, person_expedition__date__gt=self.date)[0]
except: except:
return return
def get_persons_previous_trip(self): def get_persons_previous_trip(self):
try: try:
return PersonTrip.objects.filter(person_expedition__person=self.person_expedition.person, date__lt=self.date)[0] return PersonTrip.objects.filter(person_expedition__person=self.person_expedition.person, person_expedition__date__lt=self.date)[0]
except: except:
return return

View File

@ -87,12 +87,13 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_
lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs) lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs)
for tripperson, time_underground in trippersons: for tripperson, time_underground in trippersons:
lookupAttribs={'person_expedition':tripperson, 'date':date} lookupAttribs={'person_expedition':tripperson, 'logbook_entry':lbo}
nonLookupAttribs={'place':place,'time_underground':time_underground,'logbook_entry':lbo,'is_logbook_entry_author':(tripperson == author)} nonLookupAttribs={'time_underground':time_underground,'is_logbook_entry_author':(tripperson == author)}
save_carefully(models.PersonTrip, lookupAttribs, nonLookupAttribs) save_carefully(models.PersonTrip, lookupAttribs, nonLookupAttribs)
def ParseDate(tripdate, year): def ParseDate(tripdate, year):
""" Interprets dates in the expo logbooks and returns a correct datetime.date object """
mdatestandard = re.match("(\d\d\d\d)-(\d\d)-(\d\d)", tripdate) mdatestandard = re.match("(\d\d\d\d)-(\d\d)-(\d\d)", tripdate)
mdategoof = re.match("(\d\d?)/0?(\d)/(20|19)?(\d\d)", tripdate) mdategoof = re.match("(\d\d?)/0?(\d)/(20|19)?(\d\d)", tripdate)
if mdatestandard: if mdatestandard:
@ -256,10 +257,14 @@ yearlinks = [
] ]
def SetDatesFromLogbookEntries(expedition): def SetDatesFromLogbookEntries(expedition):
"""
Sets the date_from and date_to field for an expedition based on persontrips.
Then sets the expedition date_from and date_to based on the personexpeditions.
"""
for personexpedition in expedition.personexpedition_set.all(): for personexpedition in expedition.personexpedition_set.all():
persontrips = personexpedition.persontrip_set.order_by('date') persontrips = personexpedition.persontrip_set.order_by('logbook_entry__date')
personexpedition.date_from = min([persontrip.date for persontrip in persontrips] or [None]) personexpedition.date_from = min([persontrip.logbook_entry.date for persontrip in persontrips] or [None])
personexpedition.date_to = max([persontrip.date for persontrip in persontrips] or [None]) personexpedition.date_to = max([persontrip.logbook_entry.date for persontrip in persontrips] or [None])
personexpedition.save() personexpedition.save()
# The below is all unnecessary, just use the built in get_previous_by_date and get_next_by_date # The below is all unnecessary, just use the built in get_previous_by_date and get_next_by_date