From 24dc7c5a0c996945a0709f8e82b026914ee9dbfc Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Wed, 13 May 2009 05:53:37 +0100 Subject: [svn] Photo file handling and mugshots parsing sorted. Made URL settings more relative, less redundant. Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8246 by aaron @ 2/18/2009 6:45 AM --- parsers/people.py | 107 +++++++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 50 deletions(-) (limited to 'parsers/people.py') diff --git a/parsers/people.py b/parsers/people.py index 6c94679..3a8fb05 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -6,6 +6,7 @@ import csv import re import datetime import os +import shutil # Julian: the below code was causing errors and it seems like a duplication of the above. Hope I haven't broken anything by commenting it. -Aaron # @@ -16,34 +17,39 @@ import os # pyo = models.PersonExpedition(person = pObject, expedition = yo, is_guest=is_guest) # pyo.save() -def parseMugShotAndBlurb(firstname, lastname, person, header, pObject): + + +def saveMugShot(mugShotPath, mugShotFilename, person): + if mugShotFilename.startswith(r'i/'): #if filename in cell has the directory attached (I think they all do), remove it + mugShotFilename=mugShotFilename[2:] + else: + mugShotFilename=mugShotFilename # just in case one doesn't + + mugShotObj = models.Photo( + caption="Mugshot for "+person.first_name+" "+person.last_name, + is_mugshot=True, + file=mugShotFilename, + ) + + shutil.copy(mugShotPath, mugShotObj.file.path) #Put a copy of the file in the right place. mugShotObj.file.path is determined by the django filesystemstorage specified in models.py + + mugShotObj.save() + mugShotObj.contains_person.add(person) + mugShotObj.save() + +def parseMugShotAndBlurb(personline, header, person): #create mugshot Photo instance - mugShotPath = os.path.join(settings.EXPOWEB, "folk", person[header["Mugshot"]]) + mugShotFilename=personline[header["Mugshot"]] + mugShotPath = os.path.join(settings.EXPOWEB, "folk", mugShotFilename) if mugShotPath[-3:]=='jpg': #if person just has an image, add it - mugShotObj = models.Photo( - caption="Mugshot for "+firstname+" "+lastname, - is_mugshot=True, - file=mugShotPath, - ) - mugShotObj.save() - mugShotObj.contains_person.add(pObject) - mugShotObj.save() + saveMugShot(mugShotPath=mugShotPath, mugShotFilename=mugShotFilename, person=person) elif mugShotPath[-3:]=='htm': #if person has an html page, find the image(s) and add it. Also, add the text from the html page to the "blurb" field in his model instance. personPageOld=open(mugShotPath,'r').read() - pObject.blurb=re.search('.*.* 0.3 # I don't know how to filter by this -# person.save() + #print "Setting person notability" + #for person in models.Person.objects.all(): + #person.notability = 0.0 + #for personexpedition in person.personexpedition_set.all(): + #if not personexpedition.is_guest: + #person.notability += 1.0 / (2012 - int(personexpedition.expedition.year)) + #person.bisnotable = person.notability > 0.3 # I don't know how to filter by this + #person.save() # used in other referencing parser functions -- cgit v1.2.3