From 23e3cfce20d4006e598b5d721e3b3e0c01463893 Mon Sep 17 00:00:00 2001 From: Christopher Usher Date: Fri, 30 Aug 2019 02:27:33 +0100 Subject: [PATCH] Added editor, edit_time and upload_time to thrimshim and cutter updates of the database --- common/common/database.py | 2 +- cutter/cutter/main.py | 5 +++-- thrimshim/thrimshim/main.py | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/common/database.py b/common/common/database.py index 8627245..fe65077 100644 --- a/common/common/database.py +++ b/common/common/database.py @@ -57,7 +57,7 @@ CREATE TABLE IF NOT EXISTS events ( video_link TEXT CHECK (state != 'DONE' OR video_link IS NOT NULL), editor TEXT CHECK (state = 'UNEDITED' OR editor IS NOT NULL), edit_time TIMESTAMP CHECK (state = 'UNEDITED' OR editor IS NOT NULL), - upload_time TIMESTAMP CHECK (state != 'DONE' OR upload_time IS NOT NULL), + upload_time TIMESTAMP CHECK (state != 'DONE' OR upload_time IS NOT NULL) ); diff --git a/cutter/cutter/main.py b/cutter/cutter/main.py index 60e8735..e116f6b 100644 --- a/cutter/cutter/main.py +++ b/cutter/cutter/main.py @@ -1,4 +1,5 @@ +import datetime import json import logging import os @@ -461,9 +462,9 @@ class TranscodeChecker(object): def mark_done(self, ids): result = query(self.conn, """ UPDATE events - SET state = 'DONE' + SET state = 'DONE', upload_time = %s WHERE id = ANY (%s::uuid[]) AND state = 'TRANSCODING' - """, ids.keys()) + """, datetime.datetime.utcnow(), ids.keys()) return result.rowcount diff --git a/thrimshim/thrimshim/main.py b/thrimshim/thrimshim/main.py index 39543f9..d59b5a7 100644 --- a/thrimshim/thrimshim/main.py +++ b/thrimshim/thrimshim/main.py @@ -151,6 +151,9 @@ def update_row(ident, new_row): return 'Invalid state {}'.format(new_row['state']), 400 new_row['uploader'] = None new_row['error'] = None + editor = '' # TODO replace with email form authentication + new_row['editor'] = editor + new_row['edit_time'] = datetime.datetime.utcnow() # actually update database build_query = sql.SQL(""" @@ -186,12 +189,14 @@ def manual_link(ident): return 'Row {} not found'.format(ident), 404 if old_row.state != 'UNEDITED' and not (old_row.state == 'DONE' and old_row.upload_location == 'manual'): return 'Invalid state {} for manual video link'.format(old_row.state), 403 - + editor = '' # TODO replace with email form authentication + now = datetime.datetime.utcnow() results = database.query(conn, """ UPDATE events - SET state='DONE', upload_location = 'manual', video_link = %s + SET state='DONE', upload_location = 'manual', video_link = %s, + editor = %s, edit_time = %s, upload_time = %s WHERE id = %s AND (state = 'UNEDITED' OR (state = 'DONE' AND - upload_location = 'manual'))""", link, ident) + upload_location = 'manual'))""", link, editor, now, now, ident) logging.info("Row {} video_link set to {}".format(ident, link)) return '' @@ -204,7 +209,7 @@ def reset_row(ident): results = database.query(conn, """ UPDATE events SET state='UNEDITED', error = NULL, video_id = NULL, video_link = NULL, - uploader = NULL + uploader = NULL, editor = NULL, edit_time = NULL, upload_time = NULL WHERE id = %s""", ident) if results.rowcount != 1: return 'Row id = {} not found'.format(ident), 404