Made including a new image optional when updating a template

pull/443/head
Christopher Usher 2 weeks ago
parent 3ba01dda11
commit 1ba8597957

@ -644,9 +644,12 @@ def get_template_metadata(name):
logging.info('Thumbnail metadata of {} fetched'.format(name))
return json.dumps(row._asdict())
def validate_template(new_template):
def validate_template(new_template, require_image=True):
columns = ['name', 'description', 'attribution', 'crop', 'location']
if require_image or 'image' in new_template:
columns += ['image']
columns = ['name', 'image', 'description', 'attribution', 'crop', 'location']
#check for missing fields
missing = set(columns) - set(new_template)
if missing:
@ -656,6 +659,7 @@ def validate_template(new_template):
for extra in extras:
del new_template[extra]
if 'image' in columns:
#convert and validate template image
try:
new_template['image'] = base64.b64decode(new_template['image'])
@ -704,7 +708,7 @@ def add_template(artist=None):
@authenticate_artist
def update_template(name, artist=None):
"""Update a template in the database"""
columns, message, code = validate_template(flask.request.json)
columns, message, code = validate_template(flask.request.json, False)
if code != 200:
return message, code
new_template = message

Loading…
Cancel
Save