Example #1
0
def delete_lightbox(lightbox_id):
    logger.debug('delete lightbox id: %d' % lightbox_id)
    lightbox = Lightbox.get_by_id(lightbox_id)
    logger.debug('delete lightbox name: %s' % lightbox.name)
    db.delete(lightbox)
    response = make_response('OK', 200)
    return response
Example #2
0
def get_lightbox(lightbox_id):
    logger.debug('get lightbox id: %d' % lightbox_id)
    lightbox = Lightbox.get_by_id(lightbox_id)
    photo_keys = []
    for photo in lightbox.photos:
        photo_keys.append(photo.key().id())
    result = {"lightbox_id": lightbox.key().id(), "name": lightbox.name, "photos": photo_keys}
    logger.debug(result)
    return jsonify(lightbox=result)
Example #3
0
def copy_image_to_lightbox():
    lightboxId = int(request.json['lightboxId'])
    photoId = int(request.json['photoId'])
    logger.debug('copy image id %s lightbox id %s' % (photoId, lightboxId))
    #user = users.get_current_user()
    lightbox = Lightbox.get_by_id(lightboxId)
    original = Photo.get_by_id(photoId)
    copied = clone_entity(original, lightbox=lightbox)
    copied.put()
    return jsonify(lightbox={"id": lightbox.key().id(), "photos": [copied.key().id()]})
Example #4
0
def get_lightboxes():
    user = users.get_current_user()
    lightboxes = Lightbox.all().order('created').filter('owner =', user).fetch(limit=None)
    logger.debug(lightboxes)
    result = []
    for lightbox in lightboxes:
        photos = []
        for photo in lightbox.photos:
            photos.append(photo.key().id())
        result.append({"id": lightbox.key().id(), "name": lightbox.name, "photos": photos})
    logger.debug(result)
    return jsonify(lightboxes=result)
Example #5
0
def add_lightbox():
    lightbox_name = request.json['lightbox_name']
    logger.debug('create lightbox with name %s' % lightbox_name)
    user = users.get_current_user()
    lightbox = Lightbox()
    lightbox.owner = user
    lightbox.name = lightbox_name
    lightbox.put()
    return jsonify(lightbox={"id": lightbox.key().id(), "name": lightbox.name, "photos": []})
Example #6
0
def upload():
    lightbox_id = int(request.form['lightboxId'])
    lightbox = Lightbox.get_by_id(lightbox_id)
    photos = []

    for file in request.files.getlist('file'):
        logger.debug('processing file name %s for lightbox id: %d' % (file.filename, lightbox_id))
        photo = Photo()
        photo.lightbox = lightbox
        image_data = file.read()
        photo.full_image = db.Blob(image_data)
        photo.thumbnail = db.Blob(images.resize(image_data, 180, 180))
        photo.owner = users.get_current_user()
        photo.name = file.filename
        photo.put()
        photos.append(photo.key().id())

    return jsonify(lightbox={"id": lightbox.key().id(), "photos": photos})