avoid ['']

This commit is contained in:
j 2016-01-13 10:11:31 +05:30
parent 0bb44fc4ef
commit 1efe02c87c
2 changed files with 9 additions and 2 deletions

View file

@ -251,7 +251,7 @@ def findMetadata(data):
j = items[m.data_hash]
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in j and not isinstance(j[key], list):
j[key] = [j[key]]
j[key] = [j[key]] if j[key] else []
else:
items[m.data_hash]['users'].append(m.user_id)
response['items'] = list(items.values())
@ -279,7 +279,7 @@ def getMetadata(data):
response.update(models.Metadata.load(key, value))
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in response and not isinstance(response[key], list):
response[key] = [response[key]]
response[key] = [response[key]] if response[key] else []
return response
actions.register(getMetadata)

View file

@ -16,6 +16,7 @@ from . import txt
from . import opf
from meta.utils import decode_html_data, to_isbn13
import settings
def get_id(f=None, data=None):
if data:
@ -106,5 +107,11 @@ def metadata(f, from_=None):
if not data['title'].strip():
del data['title']
data = decode_html_data(data)
for key in list(data):
if not data[key]:
del data[key]
for key in [k['id'] for k in settings.config['itemKeys'] if isinstance(k['type'], list)]:
if key in data and not isinstance(data[key], list):
data[key] = [data[key]] if data[key] else []
return data