Пример #1
0
def share_links(request):
    '''links offered up on creation or "share"'''
    c = {}
    key = request.matchdict['key']
    ah.addEventContext(key, c)
    event,permissions = eh.eventAndPermissionsForAccessKey(key)
    if permissions.administer:
        return render_to_response('share_admin.mako',
                                  c,
                                  request=request)
    else:
        return render_to_response('share.mako',
                                  c,
                                  request=request)
Пример #2
0
def uploads_posted(request):
        eventKey = request.matchdict['key']
        event,permissions = eh.eventAndPermissionsForAccessKey(eventKey)
        storage_dir = '/data/pictobin/uploads'
        values =  request.POST.values()
        if len(values) == 0:
            return json.dumps([])
 
        outs = []
        for v in values:
            picInfo = request.params.get('picInfo', 
                                         {'name':'untitled',
                                          'creator_name':'anonymous'                                          })
        
            fdata = v.file.read()
            newPicture = Picture(creator_name = picInfo['creator_name'],
                                 event = event,
                                 name = picInfo['name'],
                                 added = datetime.datetime.now(), 
                                 )
            Session.add(newPicture);
            Session.flush();
            rowId = newPicture.id
            fpath_raw =  fh.getFilePathByPictureId(rowId, 'raw')
            with open(fpath_raw,'w') as f: f.write(fdata)
            from models import PictureMeta
            from PIL import Image
            from PIL.ExifTags import TAGS

            def get_exif(fn):
                ret = {}
                i = Image.open(fn)
                info = i._getexif()
                for tag, value in info.items():
                    decoded = TAGS.get(tag, tag)
                    ret[decoded] = value
                return ret
            filetags = get_exif(fpath_raw)
            for k,v in filetags.iteritems():
                try:
                    m = PictureMeta(key = k, value = json.dumps(v),source='exif',
                                    picture = newPicture)
                    Session.add(m)
                except UnicodeDecodeError:
                    continue
                    
            fpath_800 = ih.makeC800(rowId)
            ih.updateThumbs(rowId)
            newPicture.filename = fpath_800
            outs.append( { 
                    "picInfo":newPicture.toGalleryDict(),
                    "name":picInfo['name'],
                    "filename":fpath_800,
                    "size":len(fdata),
                    "url":fh.getFileAddressByPictureId(rowId),
                    "thumbnail_url":fh.getThumbnailAddressByPictureId(rowId,'small'),
                    "delete_url":"/uploads/deleteOne?id={0}".format(rowId),
                    "delete_type":"DELETE"
                    })

        import transaction
        transaction.commit();
        return outs