From 4fc8c8ae3cb061eca0c0e1f7ae52eab0941c8f57 Mon Sep 17 00:00:00 2001
From: aaron
Date: Wed, 18 Feb 2009 07:45:45 +0100
Subject: [PATCH] [svn r8246] Photo file handling and mugshots parsing sorted.
Made URL settings more relative, less redundant.
---
troggle/expo/models.py | 5 +-
troggle/parsers/people.py | 109 ++++++++++++++++++----------------
troggle/settings.py | 8 ++-
troggle/templates/person.html | 26 +++++---
troggle/urls.py | 3 +-
5 files changed, 89 insertions(+), 62 deletions(-)
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('.*
.*
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
diff --git a/troggle/settings.py b/troggle/settings.py
index f22bd369a..c2b62b9c2 100644
--- a/troggle/settings.py
+++ b/troggle/settings.py
@@ -1,5 +1,6 @@
from localsettings import *
-# Django settings for troggle2 project.
+import os
+# Django settings for troggle project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
@@ -32,6 +33,11 @@ USE_I18N = True
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/troggle/media-admin/'
+PHOTOS = os.path.join(EXPOWEB, 'photos')
+MEDIA_URL = URL_ROOT+'/site_media/'
+SURVEYS_URL = URL_ROOT+'/survey_scans/'
+PHOTOS_URL = URL_ROOT+'/photos/'
+SVX_URL = URL_ROOT+'/survex/'
APPEND_SLASH = False
SMART_APPEND_SLASH = True
diff --git a/troggle/templates/person.html b/troggle/templates/person.html
index 88171c145..aed5989c6 100644
--- a/troggle/templates/person.html
+++ b/troggle/templates/person.html
@@ -8,17 +8,29 @@
{% endblock %}
{% block content %}
+{% if person.blurb %}
{{person.blurb}}
-{% for pic in person.photo_set
+{% endif %}
+
+{% for pic in person.photo_set.all %}
+{% if pic.is_mugshot %}
-
-{{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 %}
+
+
+
{{person|wiki_to_html_short}} has been on expo in the following years:
+
+
diff --git a/troggle/urls.py b/troggle/urls.py
index fedc1221a..a701ba129 100644
--- a/troggle/urls.py
+++ b/troggle/urls.py
@@ -75,5 +75,6 @@ urlpatterns = patterns('',
(r'^survey_scans/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.SURVEYS, 'show_indexes':True}),
-
+ (r'^photos/(?P.*)$', 'django.views.static.serve',
+ {'document_root': settings.PHOTOS, 'show_indexes':True}),
)