def get_file(file_id, ptype): a = select('SELECT * FROM files WHERE file_id=?', file_id) if len(a) == 0: return None p = a[0] p['path'] = photo_file.get_path(file_id) if ptype == 'thumb': p['path'] = photo_file.make_thubnail(file_id, 300) return p
def get_file(file_id, ptype): # データベースから基本情報を得る a = select('SELECT * FROM files WHERE file_id=?', file_id) if len(a) == 0: return None p = a[0] p['path'] = photo_file.get_path(file_id) # サムネイル画像の指定であれば作成する --- (*10) if ptype == 'thumb': p['path'] = photo_file.make_thumbnail(file_id, 300) return p
def save_file(user_id, upfile, album_id): if not re.search(r'\.(jpg|jpeg)$', upfile.filename): print('JPEGではない:', upfile.filename) return 0 if album_id == 0: a = select('SELECT * FROM albums WHERE user_id=? AND name=?', user_id, '未分類') if len(a) == 0: album_id = exec('INSERT INTO albums (user_id, name) VALUES (?,?)', user_id, '未分類') else: album_id = a[0]['album_id'] file_id = exec( ''' INSERT INTO files (user_id, filename, album_id) VALUES (?,?,?) ''', user_id, upfile.filename, album_id) upfile.save(photo_file.get_path(file_id)) return file_id
def save_file(user_id, upfile, album_id): # JPEGファイルだけを許可 if not re.search(r'\.(jpg|jpeg)$', upfile.filename): print('JPEGではない:', upfile.filename) return 0 # アルバム未指定の場合、未分類アルバムを自動的に作る if album_id == 0: a = select('SELECT * FROM albums WHERE user_id=? AND name=?', user_id, '未分類') if len(a) == 0: album_id = exec('INSERT INTO albums (user_id, name) VALUES(?, ?)', user_id, '未分類') else: album_id = a[0]['album_id'] # ファイル情報を保存 file_id = exec( ''' INSERT INTO files(user_id, filename, album_id) VALUES(?, ?, ?)''', user_id, upfile.filename, album_id) # ファイルを保存 upfile.save(photo_file.get_path(file_id)) return file_id
def delete_picture(file_id): path = photo_file.get_path(file_id) t_path = photo_file.get_path(file_id, '-thumb') a = photo_file.delete_pic(path) b = photo_file.delete_pic(t_path) return a, b