diff --git a/troggle/expo/models.py b/troggle/expo/models.py index 9561963da..faa4ce3f9 100644 --- a/troggle/expo/models.py +++ b/troggle/expo/models.py @@ -451,12 +451,13 @@ class QM(models.Model): def __str__(self): QMnumber=str(self.found_by.cave)+'-'+str(self.found_by.date.year)+"-"+str(self.number)+self.grade return str(QMnumber) - + +photoFileStorage = FileSystemStorage(location=settings.EXPOWEB+'photos', base_url=settings.PHOTOS_URL) class Photo(models.Model): caption = models.CharField(max_length=1000,blank=True,null=True) contains_person_trip = models.ManyToManyField(PersonTrip,blank=True,null=True) contains_person = models.ManyToManyField(Person,blank=True,null=True) - file = models.ImageField(upload_to='photos',) + file = models.ImageField(storage=photoFileStorage, upload_to='.',) is_mugshot = models.BooleanField(default=False) contains_cave = models.ForeignKey(Cave,blank=True,null=True) contains_entrance = models.ForeignKey(Entrance, related_name="photo_file",blank=True,null=True) diff --git a/troggle/parsers/people.py b/troggle/parsers/people.py index 6c9467972..3a8fb0559 100644 --- a/troggle/parsers/people.py +++ b/troggle/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('
.*+
+
{{ pic.caption }} +
+{{person|wiki_to_html_short}} has been on expo in the following years:
-
-{% for personexpedition in person.personexpedition_set.all %}
- | {{personexpedition.expedition.year}}
+{% endif %}
{% endfor %}
+
+
+
+