Made including a new image optional when updating a template

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

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

Loading…
Cancel
Save