diff options
author | bnewbold <bnewbold@manus.(none)> | 2007-02-06 23:34:08 -0800 |
---|---|---|
committer | bnewbold <bnewbold@manus.(none)> | 2007-02-06 23:34:08 -0800 |
commit | b88372f0327976c31e6b508b26729bab60743f82 (patch) | |
tree | 16958c4395bc881399e475a927162e8837d67310 /bn_django/photos | |
parent | f025a9f65ecd76e4442ce62684218ecb81506c9b (diff) | |
download | bnewnet-b88372f0327976c31e6b508b26729bab60743f82.tar.gz bnewnet-b88372f0327976c31e6b508b26729bab60743f82.zip |
photos app roughed in, style tweaked
TODO: search code
Diffstat (limited to 'bn_django/photos')
-rw-r--r-- | bn_django/photos/manual_import.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/bn_django/photos/manual_import.py b/bn_django/photos/manual_import.py new file mode 100644 index 0000000..a9b5448 --- /dev/null +++ b/bn_django/photos/manual_import.py @@ -0,0 +1,64 @@ +# Create your views here. + +# django imports +from django.conf import settings + +# other imports +import zipfile +import os +import stat +import shutil +from datetime import datetime +from tempfile import NamedTemporaryFile, mkdtemp +import Image +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO + +# Handling settings here +STOCKPHOTO_BASE = '/home/bnewbold/bn-project/media/photos' + +# models +from bn_django.photos.models import Gallery, Photo + +# views + + +def manual_import_photos(thezipfile, thegallery): + # Check if the gallery is valid + gallery = thegallery; + + f = file(thezipfile); + zip = zipfile.ZipFile(f) + #date = the_date + #if not date: + date = datetime.date(datetime.now()) + + destdir= os.path.join(settings.MEDIA_ROOT, STOCKPHOTO_BASE, + datetime.strftime(datetime.now(), + "%Y/%m/%d/")) + if not os.path.isdir(destdir): + os.makedirs(destdir, 0775) + for filename in zip.namelist(): + photopath = os.path.join(destdir, os.path.basename(filename)) + data = zip.read(filename) + file_data = StringIO(data) + try: + Image.open(file_data) + except: + # don't save and process non Image files + continue + photo = file(photopath, "wb") + photo.write(data) + + # Create the object + if photopath.startswith(os.path.sep): + photopath = photopath[len(settings.MEDIA_ROOT):] + photo = Photo(image=photopath, date=date, + photographer='Bryan Newbold', + title = os.path.basename(filename), + gallery_id = thegallery) + # Save it -- the thumbnails etc. get created. + photo.save() + return |