Beispiel #1
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
    """
    user = User.get(get_uid(app))

    app.log.debug("Photo delete request: %s", photo_id)
    try:
        photo = Photo.get(user.id, int(photo_id))
        photo.delete()

        util.delete_s3(app, photo.filename, user)

        # flash('Successfully removed!')
        app.log.debug('Successfully removed!')

    except Exception as e:
        app.log.error(e)
        # flash('Error occurred! Please try again.')
        return Response(body={'remove': 'fail'},
                        status_code=200,
                        headers={"Content-Type": "application/json"})

    return Response(body={'remove': 'success'},
                    status_code=200,
                    headers={"Content-Type": "application/json"})
Beispiel #2
0
def upload_form():
    user = User.get(get_uid(app))
    t = env.get_template('upload.html')
    body = t.render(current_user=user,
                    gmaps_key=conf['GMAPS_KEY'],
                    s3_static_url=S3_STATIC_URL)
    response = Response(body=body,
                        status_code=200,
                        headers={"Content-Type": "text/html"})
    return response
Beispiel #3
0
def home():
    t = env.get_template('home.html')
    user = User.get(get_uid(app))

    result = Photo.query(user.id)
    body = t.render(current_user=user,
                    photos=result,
                    presigned_url=util.presigned_url,
                    s3_static_url=S3_STATIC_URL)

    return Response(body=body,
                    status_code=200,
                    headers={"Content-Type": "text/html"})
Beispiel #4
0
def map_view():
    t = env.get_template('map.html')
    user = User.get(get_uid(app))

    photo_list = Photo.query(user.id)
    body = t.render(current_user=user,
                    photos=photo_list,
                    gmaps_key=conf['GMAPS_KEY'],
                    presigned_url=util.presigned_url,
                    s3_static_url=S3_STATIC_URL)

    return Response(body=body,
                    status_code=200,
                    headers={"Content-Type": "text/html"})
Beispiel #5
0
def upload():
    # flash('Your file upload have been completed successfully!')

    user = User.get(get_uid(app))
    form = util.get_parts(app)

    filename_orig = form['filename_origin'][0].decode('utf-8')
    ext = (filename_orig.rsplit('.', 1)[1]).lower()
    filename = "{0}{1}.{2}".format(next(tempfile._get_candidate_names()),
                                   uuid.uuid4().hex, ext)

    stream = io.BytesIO(form['photo'][0])
    size = util.save_s3_chalice(stream, filename, user.email, app)

    taken_date = datetime.strptime(form['taken_date'][0].decode('utf-8'),
                                   "%Y:%m:%d %H:%M:%S")
    photo = Photo(user.id, util.current_milli_time())
    photo.tags = form['tags'][0].decode('utf-8')
    photo.desc = form['desc'][0].decode('utf-8')
    photo.filename_orig = 'test'
    photo.filename = filename
    photo.filesize = size
    photo.geotag_lat = form['lat'][0].decode('utf-8')
    photo.geotag_lng = form['lng'][0].decode('utf-8')
    photo.upload_date = util.the_time_now()
    photo.taken_date = taken_date
    photo.make = form['make'][0].decode('utf-8')
    photo.model = form['model'][0].decode('utf-8')
    photo.width = form['width'][0].decode('utf-8')
    photo.height = form['height'][0].decode('utf-8')
    photo.city = form['city'][0].decode('utf-8')
    photo.nation = form['nation'][0].decode('utf-8')
    photo.address = form['address'][0].decode('utf-8')
    photo.save()

    return Response(status_code=301,
                    headers={'Location': '/api/home'},
                    body='')