diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 06:15:48 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 06:15:48 +0100 |
commit | 625b2156e388a92d57fa446c931bbf410f5a4e29 (patch) | |
tree | 8866421569ba567be82b58a45d90e142c46e5c0a /parsers/logbooks.py | |
parent | 1a36856b407684a9d48f04e170a160b3c04aa706 (diff) | |
download | troggle-625b2156e388a92d57fa446c931bbf410f5a4e29.tar.gz troggle-625b2156e388a92d57fa446c931bbf410f5a4e29.tar.bz2 troggle-625b2156e388a92d57fa446c931bbf410f5a4e29.zip |
[svn] Weeks of local changes.
- Import is now non-destructive
- Parsers write output to a log file (path be specified in settings)
- databaseReset.py content been divided into separate functions which can be called for varying levels of deletion and importing
- control panel (view, template, urlpattern) added for deleting and importing
- Logins and signup fixed
- CaveArea model updated, view, hierarchical url patterns, and beginning of template added
- New site style
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8324 by cucc @ 5/3/2009 5:56 AM
Diffstat (limited to 'parsers/logbooks.py')
-rw-r--r-- | parsers/logbooks.py | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/parsers/logbooks.py b/parsers/logbooks.py index 976d71a..7c8364a 100644 --- a/parsers/logbooks.py +++ b/parsers/logbooks.py @@ -13,6 +13,7 @@ import re import datetime
import os
+from troggle.helpers import save_carefully
#
# When we edit logbook entries, allow a "?" after any piece of data to say we've frigged it and
@@ -72,21 +73,23 @@ def GetTripCave(place): #need to be fuzzier about matching h noncaveplaces = [ "Journey", "Loser Plateau" ]
def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_underground):
+ """ saves a logbook entry and related persontrips """
trippersons, author = GetTripPersons(trippeople, expedition, logtime_underground)
# tripCave = GetTripCave(place)
-
- lbo = models.LogbookEntry(date=date, place=place, title=title[:50], text=text, author=author, expedition=expedition)
+ #
lplace = place.lower()
if lplace not in noncaveplaces:
- lbo.cave=GetCaveLookup().get(lplace)
- #print "pppp %s |%s|" % (lplace, str(lbo.cave))
-
- lbo.save()
- #print "ttt", date, place
+ cave=GetCaveLookup().get(lplace)
+
+ #Check for an existing copy of the current entry, and save
+ lookupAttribs={'date':date, 'title':title[:50]}
+ nonLookupAttribs={'place':place, 'text':text, 'author':author, 'expedition':expedition, 'cave':cave}
+ lbo, created=save_carefully(models.LogbookEntry, lookupAttribs, nonLookupAttribs)
+
for tripperson, time_underground in trippersons:
- pto = models.PersonTrip(person_expedition = tripperson, place=place, date=date, time_underground=time_underground,
- logbook_entry=lbo, is_logbook_entry_author=(tripperson == author))
- pto.save()
+ lookupAttribs={'person_expedition':tripperson, 'date':date}
+ nonLookupAttribs={'place':place,'time_underground':time_underground,'logbook_entry':lbo,'is_logbook_entry_author':(tripperson == author)}
+ save_carefully(models.PersonTrip, lookupAttribs, nonLookupAttribs)
def ParseDate(tripdate, year):
@@ -235,7 +238,7 @@ def Parseloghtml03(year, expedition, txt): yearlinks = [
("2008", "2008/2008logbook.txt", Parselogwikitxt),
- ("2007", "2007/2007logbook.txt", Parselogwikitxt),
+ #("2007", "2007/2007logbook.txt", Parselogwikitxt),
("2006", "2006/logbook/logbook_06.txt", Parselogwikitxt),
("2005", "2005/logbook.html", Parseloghtmltxt),
("2004", "2004/logbook.html", Parseloghtmltxt),
@@ -299,15 +302,17 @@ def SetDatesFromLogbookEntries(expedition): # logbookentry.href = "%s" % logbookentry.date
# logbookentry.save()
# lprevlogbookentry = logbookentry
- for logbookentry in expedition.logbookentry_set.all():
- logbookentry.slug = slugify(logbookentry.title)
- logbookentry.save()
+
def LoadLogbookForExpedition(expedition):
- print "deleting logbooks for", expedition
- expedition.logbookentry_set.all().delete()
- models.PersonTrip.objects.filter(person_expedition__expedition=expedition).delete()
+ """ Parses all logbook entries for one expedition """
+
+ #We're checking for stuff that's changed in admin before deleting it now.
+ #print "deleting logbooks for", expedition
+ #expedition.logbookentry_set.all().delete()
+ #models.PersonTrip.objects.filter(person_expedition__expedition=expedition).delete()
+
expowebbase = os.path.join(settings.EXPOWEB, "years")
year = str(expedition.year)
for lyear, lloc, parsefunc in yearlinks:
@@ -322,7 +327,10 @@ def LoadLogbookForExpedition(expedition): def LoadLogbooks():
- models.LogbookEntry.objects.all().delete()
+ """ This is the master function for parsing all logbooks into the Troggle database. Requires yearlinks, which is a list of tuples for each expedition with expedition year, logbook path, and parsing function. """
+
+ #Deletion has been moved to a seperate function to enable the non-destructive importing
+ #models.LogbookEntry.objects.all().delete()
expowebbase = os.path.join(settings.EXPOWEB, "years")
#yearlinks = [ ("2001", "2001/log.htm", Parseloghtml01), ] #overwrite
#yearlinks = [ ("1996", "1996/log.htm", Parseloghtml01),] # overwrite
|