示例#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"})
示例#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
示例#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"})
示例#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"})
示例#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='')
示例#6
0
def search():
    """
    Search function for description and tags in Photo table.
    :return: List of photo object which retrieved DB.
    """
    t = env.get_template('home.html')
    user = User(get_uid(app))

    parsed = parse_qs(app.current_request.raw_body.decode())
    keyword = parsed.get('search')[0]

    photo_pages = Photo.query(
        user.id,
        Photo.tags.contains(keyword) | Photo.desc.contains(keyword))

    body = t.render(current_user=user,
                    photos=photo_pages,
                    presigned_url=util.presigned_url,
                    msg="Search results for '{0}'.. ".format(keyword),
                    s3_static_url=S3_STATIC_URL)

    return Response(body=body,
                    status_code=200,
                    headers={"Content-Type": "text/html"})