|
|
@ -3,8 +3,6 @@ from functools import wraps
|
|
|
|
import json
|
|
|
|
import json
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
import signal
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import argh
|
|
|
|
import argh
|
|
|
|
import flask
|
|
|
|
import flask
|
|
|
@ -213,6 +211,12 @@ def update_row(ident, editor=None):
|
|
|
|
'sheet_name', 'event_start', 'event_end',
|
|
|
|
'sheet_name', 'event_start', 'event_end',
|
|
|
|
'category', 'description', 'notes', 'tags',
|
|
|
|
'category', 'description', 'notes', 'tags',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
# These columns may be modified when a video is in state 'DONE',
|
|
|
|
|
|
|
|
# and are a subset of edit_columns.
|
|
|
|
|
|
|
|
modifiable_columns = [
|
|
|
|
|
|
|
|
'video_title', 'video_description', 'video_tags',
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
assert set(modifiable_columns) - set(edit_columns) == set()
|
|
|
|
|
|
|
|
|
|
|
|
# Check vital edit columns are in new_row
|
|
|
|
# Check vital edit columns are in new_row
|
|
|
|
wanted = set(non_null_columns + ['state'] + sheet_columns)
|
|
|
|
wanted = set(non_null_columns + ['state'] + sheet_columns)
|
|
|
@ -274,7 +278,10 @@ def update_row(ident, editor=None):
|
|
|
|
return 'Row {} not found'.format(ident), 404
|
|
|
|
return 'Row {} not found'.format(ident), 404
|
|
|
|
assert old_row['id'] == ident
|
|
|
|
assert old_row['id'] == ident
|
|
|
|
|
|
|
|
|
|
|
|
if old_row['state'] not in ['UNEDITED', 'EDITED', 'CLAIMED']:
|
|
|
|
if new_row['state'] == 'MODIFIED':
|
|
|
|
|
|
|
|
if old_row['state'] not in ['DONE', 'MODIFIED']:
|
|
|
|
|
|
|
|
return 'Video is in state {} and cannot be modified'.format(old_row['state']), 403
|
|
|
|
|
|
|
|
elif old_row['state'] not in ['UNEDITED', 'EDITED', 'CLAIMED']:
|
|
|
|
return 'Video already published', 403
|
|
|
|
return 'Video already published', 403
|
|
|
|
|
|
|
|
|
|
|
|
# check whether row has been changed in the sheet since editing has begun
|
|
|
|
# check whether row has been changed in the sheet since editing has begun
|
|
|
@ -293,6 +300,27 @@ def update_row(ident, editor=None):
|
|
|
|
if changes and not override_changes:
|
|
|
|
if changes and not override_changes:
|
|
|
|
return 'Sheet columns have changed since editing has begun. Please review changes\n' + changes, 409
|
|
|
|
return 'Sheet columns have changed since editing has begun. Please review changes\n' + changes, 409
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if new_row['state'] == 'MODIFIED':
|
|
|
|
|
|
|
|
# Modifying published rows is more limited, we ignore all other fields.
|
|
|
|
|
|
|
|
for column in set(modifiable_columns) & set(non_null_columns):
|
|
|
|
|
|
|
|
if new_row[column] is None:
|
|
|
|
|
|
|
|
missing.append(column)
|
|
|
|
|
|
|
|
if missing:
|
|
|
|
|
|
|
|
return 'Fields {} must be non-null for modified video'.format(', '.join(missing)), 400
|
|
|
|
|
|
|
|
build_query = sql.SQL("""
|
|
|
|
|
|
|
|
UPDATE events
|
|
|
|
|
|
|
|
SET last_modified = NOW(), error = NULL, state = 'MODIFIED', {}
|
|
|
|
|
|
|
|
WHERE id = %(id)s AND state IN ('DONE', 'MODIFIED')
|
|
|
|
|
|
|
|
""").format(sql.SQL(", ").join(
|
|
|
|
|
|
|
|
sql.SQL("{} = {}").format(
|
|
|
|
|
|
|
|
sql.Identifier(column), database.get_column_placeholder(column),
|
|
|
|
|
|
|
|
) for column in modifiable_columns
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
result = database.query(conn, build_query, id=ident, **new_row)
|
|
|
|
|
|
|
|
if result.rowcount != 1:
|
|
|
|
|
|
|
|
return 'Video changed state while we were updating - maybe it was reset?', 403
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
# handle state columns
|
|
|
|
# handle state columns
|
|
|
|
if new_row['state'] == 'EDITED':
|
|
|
|
if new_row['state'] == 'EDITED':
|
|
|
|
missing = []
|
|
|
|
missing = []
|
|
|
@ -386,7 +414,8 @@ def reset_row(ident, editor=None):
|
|
|
|
query = """
|
|
|
|
query = """
|
|
|
|
UPDATE events
|
|
|
|
UPDATE events
|
|
|
|
SET state='UNEDITED', error = NULL, video_id = NULL, video_link = NULL,
|
|
|
|
SET state='UNEDITED', error = NULL, video_id = NULL, video_link = NULL,
|
|
|
|
uploader = NULL, editor = NULL, edit_time = NULL, upload_time = NULL
|
|
|
|
uploader = NULL, editor = NULL, edit_time = NULL, upload_time = NULL,
|
|
|
|
|
|
|
|
last_modified = NULL
|
|
|
|
WHERE id = %s {}
|
|
|
|
WHERE id = %s {}
|
|
|
|
""".format(
|
|
|
|
""".format(
|
|
|
|
"" if force else "AND state IN ('UNEDITED', 'EDITED', 'CLAIMED')",
|
|
|
|
"" if force else "AND state IN ('UNEDITED', 'EDITED', 'CLAIMED')",
|
|
|
|