class Photo(Model):
    """
    User table for DynamoDB
    """
    class Meta:
        table_name = 'Photo'
        region = conf['AWS_REGION']

    user_id = UnicodeAttribute(hash_key=True)
    id = NumberAttribute(range_key=True)
    tags = UnicodeAttribute(null=False)
    desc = UnicodeAttribute(null=False)
    filename_orig = UnicodeAttribute(null=False)
    filename = UnicodeAttribute(null=False)
    filesize = NumberAttribute(null=False)
    geotag_lat = UnicodeAttribute(null=False)
    geotag_lng = UnicodeAttribute(null=False)
    upload_date = UTCDateTimeAttribute(default=util.the_time_now())
    taken_date = UTCDateTimeAttribute(default=util.the_time_now())
    make = UnicodeAttribute(null=True)
    model = UnicodeAttribute(null=True)
    width = UnicodeAttribute(null=False)
    height = UnicodeAttribute(null=False)
    city = UnicodeAttribute(null=True)
    nation = UnicodeAttribute(null=False)
    address = UnicodeAttribute(null=False)
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:
            app.logger.debug(current_user)
            size = util.save(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'])