diff --git a/oml/meta/__init__.py b/oml/meta/__init__.py index 3db506d..7e7fb21 100644 --- a/oml/meta/__init__.py +++ b/oml/meta/__init__.py @@ -13,6 +13,8 @@ from . import worldcat from . import google from . import duckduckgo +from oml import settings + import logging logger = logging.getLogger(__name__) @@ -84,6 +86,9 @@ def lookup(key, value): data[k] = [] if v not in data[k]: data[k].append(v) + 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]] return data def isvalid_id(key, value): diff --git a/oml/metaremote.py b/oml/metaremote.py index b6f6c77..81ca973 100644 --- a/oml/metaremote.py +++ b/oml/metaremote.py @@ -7,6 +7,8 @@ from urllib.parse import urlencode from ox.cache import read_url +import settings + import logging logger = logging.getLogger(__name__) @@ -28,4 +30,8 @@ def find(query): def lookup(key, value): logger.debug('lookup %s %s', key, value) - return request('getMetadata', {key: value}) + data = request('getMetadata', {key: value}) + 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]] + return data diff --git a/oml/settings.py b/oml/settings.py index 2f82b9e..bb9c423 100644 --- a/oml/settings.py +++ b/oml/settings.py @@ -5,8 +5,8 @@ import json import os import ed25519 -from pdict import pdict -from utils import get_user_id +from oml.pdict import pdict +from oml.utils import get_user_id base_dir = os.path.normpath(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')) static_path = os.path.join(base_dir, 'static') @@ -34,7 +34,7 @@ else: preferences = pdict(os.path.join(config_path, 'preferences.json'), config['user']['preferences']) ui = pdict(os.path.join(config_path, 'ui.json'), config['user']['ui']) -lists_cache = pdict(os.path.join(config_path, 'lists_cache.json'), {}) +list_cache = pdict(os.path.join(config_path, 'list_cache.json'), {}) server = pdict(os.path.join(config_path, 'server.json')) server_defaults = { diff --git a/oml/user/models.py b/oml/user/models.py index cc6134d..01e1bf0 100644 --- a/oml/user/models.py +++ b/oml/user/models.py @@ -302,8 +302,8 @@ class List(db.Model): def items_count(self): key = self.find_id - if key in settings.lists_cache: - value = settings.lists_cache[key] + if key in settings.list_cache: + value = settings.list_cache[key] else: from item.models import Item if self._query: @@ -311,7 +311,7 @@ class List(db.Model): value = Parser(Item).find({'query': data}).count() else: value = len(self.items) - settings.lists_cache[key] = value + settings.list_cache[key] = value return value def json(self):