예제 #1
0
def delete_api_albums(id):
    try:
        album = Album.get(current_user, id)
        album.delete(current_user)
    except ValueError as error:
        return error.args[0], 400
    return json.dumps(True)
예제 #2
0
def put_api_albums():
    try:
        album = Album.get(current_user, request.json['id'])
        album = album.update(current_user, request.json['name'])
    except ValueError as error:
        return error.args[0], 400
    return json.dumps(album.__dict__)
예제 #3
0
def put_api_albums_share(id):
    try:
        album = Album.get(current_user, id)
        album.share(current_user, request.json['shared'])
    except ValueError as error:
        return error.args[0], 400
    return json.dumps(album.__dict__)
예제 #4
0
 def create(user, album, hash, file, exif_datetime):
     needs_update = False
     file_name, file_extension = os.path.splitext(file)
     if not exif_datetime:
         exif_datetime = "1930:08:25 12:00:00"
     exif_datetime = datetime.strptime(exif_datetime, "%Y:%m:%d %H:%M:%S")
     destination_album = None
     with getcursor() as cur:
         if album:
             destination_album = Album.get(user, album)
         if not destination_album:
             destination_album = Album.get_album_by_name(user, "Unsorted")
         try:
             cur.execute(
                 "INSERT INTO photos (owner, album, hash, extension, exif_datetime, created)"
                 " VALUES (%s, %s, %s, %s, %s, current_timestamp)"
                 " RETURNING id", (user.id, destination_album.id, hash,
                                   file_extension, exif_datetime))
             photo_id = cur.fetchone()[0]
         except UniqueViolation:
             needs_update = True
         if needs_update:
             with getcursor() as cur:
                 cur.execute(
                     "UPDATE photos SET album = %s, exif_datetime = %s, flag = NULL, status = 'P'"
                     " WHERE owner = %s AND hash = %s"
                     " RETURNING id",
                     (destination_album.id, exif_datetime, user.id, hash))
                 photo_id = cur.fetchone()[0]
     thumbnail_url = Photo.get_presigned_url_tn(user, hash)
     fullsize_url = Photo.get_presigned_url_fs(user, hash)
     original_url = Photo.get_presigned_url_original(
         user, hash, file_extension)
     return Photo(photo_id, user.id, album, hash, file_extension, None,
                  exif_datetime, thumbnail_url, fullsize_url, original_url)