From 9c1e978da28228cd14d4f2a0ff3ac08ea73240ed Mon Sep 17 00:00:00 2001 From: substantialnoninfringinguser Date: Tue, 19 May 2009 06:32:42 +0100 Subject: [svn] --- parsers/people.py | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'parsers/people.py') diff --git a/parsers/people.py b/parsers/people.py index 2950fb7..cd9a661 100644 --- a/parsers/people.py +++ b/parsers/people.py @@ -25,18 +25,22 @@ def saveMugShot(mugShotPath, mugShotFilename, person): 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 + dummyObj=models.Photo(file=mugShotFilename) + + #Put a copy of the file in the right place. mugShotObj.file.path is determined by the django filesystemstorage specified in models.py + if not os.path.exists(dummyObj.file.path): + shutil.copy(mugShotPath, dummyObj.file.path) - mugShotObj.save() - mugShotObj.contains_person.add(person) - mugShotObj.save() + mugShotObj, created = save_carefully( + models.Photo, + lookupAttribs={'is_mugshot':True, 'file':mugShotFilename}, + nonLookupAttribs={'caption':"Mugshot for "+person.first_name+" "+person.last_name} + ) + + if created: + mugShotObj.contains_person.add(person) + mugShotObj.save() def parseMugShotAndBlurb(personline, header, person): #create mugshot Photo instance @@ -46,10 +50,11 @@ def parseMugShotAndBlurb(personline, header, person): 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() - person.blurb=re.search('.*.*