Exemplo n.º 1
0
def edit(photo_id):
    """
    Edit uploaded photo information.
    :param photo_id: target photo id
    :return: HTML template for edit form or Json data
    """

    if request.method == 'GET':
        photo = Photo.get(current_user.id, photo_id)
        return render_template('upload.html', photo=photo, gmaps_key=conf['GMAPS_KEY'])

    elif request.method == 'PUT':
        data = request.get_json()
        try:
            photo = Photo.get(current_user.id, photo_id)
            photo.tags = data['tags']
            photo.desc = data['desc']
            photo.geotag_lat = data['lat']
            photo.geotag_lng = data['lng']
            photo.city = data['city']
            photo.nation = data['nation']
            photo.address = data['address']
            photo.save()
            return jsonify(update='success')

        except Exception as e:
            app.logger.error(e)
            return jsonify(update='fail')
    else:
        return redirect(url_for("/", gmaps_key=conf['GMAPS_KEY']))
def photo_delete(photo_id):
    """
    Delete specific file (with thumbnail) and delete DB record.
    :param photo_id: target photo id
    :return: Json data remove:fail or success
    """

    app.logger.debug("Photo delete request: %s", photo_id)
    try:
        ## TODO #4 : Review following code to delete uploaded photo information in DynamoDB.
        ## -- begin --
        photo = Photo.get(current_user.id, photo_id)
        photo.delete()
        ## -- end --

        util.delete(app, photo.filename, current_user)
        flash('Successfully removed!')
        app.logger.debug('Successfully removed!')

    except Exception as e:
        app.logger.error(e)
        flash('Error occurred! Please try again.')
        return jsonify(remove='fail')

    return jsonify(remove='success')
Exemplo n.º 3
0
def photo_url(photo_id):
    """
    Return image url for thumbnail and original photo.
    :param photo_id: target photo id
    :return: image url for authenticated user
    """
    mode = request.args.get('mode')
    try:
        photo = Photo.get(current_user.id, photo_id)
        path = os.path.join(conf['UPLOAD_FOLDER'], util.email_normalize(current_user.email))

        if mode == "thumbnail":
            full_path = os.path.join(os.path.join(path, "thumbnail"), photo.filename)
        else:
            full_path = os.path.join(path, photo.filename)

        with open(full_path, 'rb') as f:
            contents = f.read()
            resp = make_response(contents)

    except Exception as e:
        app.logger.error(e)
        flash('Error occurred! Please try again.')
        return 'http://placehold.it/400x300'

    app.logger.debug("mode: %s, %s", mode, full_path)
    resp.content_type = "image/jpeg"
    return resp
Exemplo n.º 4
0
def map_view(photo_id=None):
    """
    Map view with photo marker.
    :param photo_id: target photo id
    :return: HTML template for the map.
    """

    if not photo_id:
        photo_list = Photo.query(current_user.id)
        app.logger.debug("photo_id: {0}".format(photo_id))
    else:
        photo_list = Photo.get(current_user.id, photo_id)

    return render_template("map.html", photos=photo_list, gmaps_key=conf['GMAPS_KEY'])
Exemplo n.º 5
0
def photo_delete(photo_id):
    """
    Delete specific file (with thumbnail) and delete DB record.
    :param photo_id: target photo id
    :return: Json data remove:fail or success
    """

    app.logger.debug("Photo delete request: %s", photo_id)
    try:
        photo = Photo.get(current_user.id, photo_id)
        photo.delete()
        util.delete(app, photo.filename, current_user)
        flash('Successfully removed!')
        app.logger.debug('Successfully removed!')

    except Exception as e:
        app.logger.error(e)
        flash('Error occurred! Please try again.')
        return jsonify(remove='fail')

    return jsonify(remove='success')