Exemple #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']))
Exemple #2
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'])
Exemple #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
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')
Exemple #5
0
def photos():
    """
    Retrieve uploaded photo information
    :param page: page number for the pagination.
    :return: HTML template for photo list
    """
    results = Photo.query(current_user.id)

    return render_template('home.html', photos=results, gmaps_key=conf['GMAPS_KEY'],
                           sizeof_fmt=util.sizeof_fmt, current_user=current_user, presigned_url=util.presigned_url)
Exemple #6
0
def search():
    """
    Search function for description and tags in Photo table.
    :return: List of photo object which retrieved DB.
    """
    keyword = request.form['search']
    app.logger.debug(keyword)
    photo_pages = Photo.query(current_user.id, Photo.tags.contains(keyword) | Photo.desc.contains(keyword))

    flash("Search results for '{0}'.. ".format(keyword))
    return render_template('home.html', photos=photo_pages, gmaps_key=conf['GMAPS_KEY'], presigned_url=util.presigned_url)
def search():
    """
    Search function for description and tags in Photo table.
    :return: List of photo object which retrieved DB.
    """

    ## TODO #3 : Review following code to search result via keyword in the DynamoDB.
    ## -- begin --
    keyword = request.form['search']
    photo_pages = Photo.query(
        current_user.id,
        Photo.tags.contains(keyword) | Photo.desc.contains(keyword))
    ## -- end --

    flash("Search results for '{0}'.. ".format(keyword))
    return render_template('home.html',
                           photos=photo_pages,
                           gmaps_key=conf['GMAPS_KEY'])
Exemple #8
0
def photos(page=1):
    """
    Retrieve uploaded photo information
    :param page: page number for the pagination.
    :return: HTML template for photo list
    """

    results = Photo.query(current_user.id)
    photo_count = conf['PER_PAGE'] ## TODO : Paging 관련 DDB Fix 필요
    pagination = Pagination(page, conf['PER_PAGE'], photo_count)

    if page != 1:
        offset = conf['PER_PAGE'] * (page - 1)
    else:
        offset = 0

    return render_template('home.html', pagination=pagination, photos=results, gmaps_key=conf['GMAPS_KEY'],
                           sizeof_fmt=util.sizeof_fmt, current_user=current_user)
Exemple #9
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')
Exemple #10
0
def upload():
    """
    Photo file upload  function
    :return: HTML template for upload form or uploaded photo list
    """

    form = PhotoForm(request.form)

    if request.method == 'POST':
        app.logger.debug(form.data)
        app.logger.debug("form.taken_date.data:%s", form.taken_date.data)
        upload_photo = request.files['photo']
        ext = (upload_photo.filename.rsplit('.', 1)[1]).lower()
        filename = secure_filename("{0}.{1}".format(uuid.uuid4(), ext))
        taken_date = datetime.strptime(form.taken_date.data, "%Y:%m:%d %H:%M:%S")

        app.logger.debug("take_date:{0}".format(taken_date))

        try:
            size = util.save_s3(upload_photo, filename, current_user.email, app)

            photo = Photo(current_user.id, util.current_milli_time())
            photo.tags = form.tags.data
            photo.desc = form.desc.data
            photo.filename_orig = upload_photo.filename
            photo.filename = filename
            photo.filesize = size
            photo.geotag_lat = form.lat.data
            photo.geotag_lng = form.lng.data
            photo.upload_date = util.the_time_now()
            photo.taken_date = taken_date
            photo.make = form.make.data
            photo.model = form.model.data
            photo.width = form.width.data
            photo.height = form.height.data
            photo.city = form.city.data
            photo.nation = form.nation.data
            photo.address = form.address.data
            photo.save()

            flash('Your file upload have been completed successfully!')
            return redirect(url_for("photoView.photos", form=form, gmaps_key=conf['GMAPS_KEY']))

        except Exception as e:
            app.logger.error(e)
            util.delete(app, filename, current_user)
            return errorHandler.server_error(e)

    return render_template('upload.html', form=form, gmaps_key=conf['GMAPS_KEY'])
Exemple #11
0
"""
    model.__init__.py
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CloudAlbum is a sample application for TechSummit 2018 workshop.

    :copyright: © 2018 by Sungshik Jou.
    :license: BSD, see LICENSE for more details.
"""
from pynamodb.models import Model
from pynamodb.attributes import UnicodeAttribute, ListAttribute
from cloudalbum.config import conf
from werkzeug.security import generate_password_hash, check_password_hash
import uuid
from cloudalbum.model.models_ddb import User
from cloudalbum.model.models_ddb import Photo

if not User.exists():
    User.create_table(read_capacity_units=conf['DDB_RCU'],
                      write_capacity_units=conf['DDB_WCU'],
                      wait=True)
    print('DynamoDB User table created!')

if not Photo.exists():
    Photo.create_table(read_capacity_units=conf['DDB_RCU'],
                       write_capacity_units=conf['DDB_WCU'],
                       wait=True)
    print('DynamoDB Photo table created!')