summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Mihai <smihai@entrouvert.com>2015-05-11 23:03:23 (GMT)
committerSerghei Mihai <smihai@entrouvert.com>2015-05-13 14:04:56 (GMT)
commit8bbd58a7ab8fba492987fb5551ffc33689c540a7 (patch)
tree934227124be89de15d377cac5223d1633ef29746
parent4de32236f037c1edda7134dfe5d7153539977698 (diff)
downloadcombo-8bbd58a7ab8fba492987fb5551ffc33689c540a7.zip
combo-8bbd58a7ab8fba492987fb5551ffc33689c540a7.tar.gz
combo-8bbd58a7ab8fba492987fb5551ffc33689c540a7.tar.bz2
wcs: use a generic KNOWN_SERVICES setting instead of COMBO_WCS_SITES (#6711)
-rw-r--r--combo/apps/wcs/README6
-rw-r--r--combo/apps/wcs/models.py24
-rw-r--r--combo/apps/wcs/utils.py5
-rw-r--r--tests/settings.py4
-rw-r--r--tests/test_wcs.py7
5 files changed, 24 insertions, 22 deletions
diff --git a/combo/apps/wcs/README b/combo/apps/wcs/README
index b4b638f..5b9eec1 100644
--- a/combo/apps/wcs/README
+++ b/combo/apps/wcs/README
@@ -3,6 +3,8 @@ Combo/wcs integration
INSTALLED_APPS += ('combo.apps.wcs',)
-COMBO_WCS_SITES = {
- 'default': {'title': 'wcs', 'url': 'http://wcs/'},
+KNOWN_SERVICES = {
+ 'wcs': {
+ 'default': {'title': 'wcs', 'url': 'http://wcs/'},
+ }
}
diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py
index d5254e0..30249dc 100644
--- a/combo/apps/wcs/models.py
+++ b/combo/apps/wcs/models.py
@@ -31,9 +31,8 @@ from combo.utils import NothingInCacheException
from .utils import get_wcs_json
-
def is_wcs_enabled(cls):
- return hasattr(settings, 'COMBO_WCS_SITES') and settings.COMBO_WCS_SITES
+ return hasattr(settings, 'KNOWN_SERVICES') and settings.KNOWN_SERVICES.get('wcs')
@register_cell_class
class WcsFormCell(CellBase):
@@ -54,7 +53,7 @@ class WcsFormCell(CellBase):
def save(self, *args, **kwargs):
if self.formdef_reference:
wcs_key, form_slug = self.formdef_reference.split(':')
- wcs_site = settings.COMBO_WCS_SITES.get(wcs_key)
+ wcs_site = settings.KNOWN_SERVICES.get('wcs', {}).get(wcs_key)
forms_response_json = get_wcs_json(wcs_site.get('url') + 'json')
for form in forms_response_json:
slug = form.get('slug')
@@ -90,7 +89,7 @@ class WcsCommonCategoryCell(CellBase):
def save(self, *args, **kwargs):
if self.category_reference:
wcs_key, category_slug = self.category_reference.split(':')
- wcs_site = settings.COMBO_WCS_SITES.get(wcs_key)
+ wcs_site = settings.KNOWN_SERVICES.get('wcs', {}).get(wcs_key)
categories_response_json = get_wcs_json(wcs_site.get('url') + 'categories')
for category in categories_response_json.get('data'):
slug = category.get('slug')
@@ -136,16 +135,15 @@ class WcsBlurpMixin(object):
def get_blurp_renderer(self, context):
if self.wcs_site:
try:
- wcs_sites = {self.wcs_site: settings.COMBO_WCS_SITES[self.wcs_site]}
+ wcs_sites = {self.wcs_site: settings.KNOWN_SERVICES['wcs'][self.wcs_site]}
except KeyError:
# in case of the site disappeared from settings
return cmsplugin_blurp.utils.create_renderer(self.variable_name, {
'class': 'cmsplugin_blurp.renderers.template.Renderer',
'template': ''
})
-
else:
- wcs_sites = settings.COMBO_WCS_SITES
+ wcs_sites = settings.KNOWN_SERVICES['wcs']
sources = []
for slug, wcs_site in wcs_sites.items():
@@ -197,10 +195,10 @@ class WcsDataBaseCell(CellBase, WcsBlurpMixin):
abstract = True
def get_default_form_class(self):
- if len(settings.COMBO_WCS_SITES) == 1:
+ if len(settings.KNOWN_SERVICES.get('wcs')) == 1:
return None
combo_wcs_sites = [('', _('All'))]
- combo_wcs_sites.extend([(x, y.get('title')) for x, y in settings.COMBO_WCS_SITES.items()])
+ combo_wcs_sites.extend([(x, y.get('title')) for x, y in settings.KNOWN_SERVICES.get('wcs', {}).items()])
return model_forms.modelform_factory(self.__class__,
fields=['wcs_site'],
widgets={'wcs_site': Select(choices=combo_wcs_sites)})
@@ -307,9 +305,9 @@ class TrackingCodeInputCell(CellBase):
verbose_name = _('Tracking Code Input')
def get_default_form_class(self):
- if len(settings.COMBO_WCS_SITES) == 1:
+ if len(settings.KNOWN_SERVICES.get('wcs')) == 1:
return None
- combo_wcs_sites = [(x, y.get('title')) for x, y in settings.COMBO_WCS_SITES.items()]
+ combo_wcs_sites = [(x, y.get('title')) for x, y in settings.KNOWN_SERVICES.get('wcs', {}).items()]
return model_forms.modelform_factory(self.__class__,
fields=['wcs_site'],
widgets={'wcs_site': Select(choices=combo_wcs_sites)})
@@ -317,6 +315,6 @@ class TrackingCodeInputCell(CellBase):
def render(self, context):
tmpl = template.loader.get_template(self.template_name)
if not self.wcs_site:
- self.wcs_site = settings.COMBO_WCS_SITES.keys()[0]
- context['url'] = settings.COMBO_WCS_SITES.get(self.wcs_site).get('url')
+ self.wcs_site = settings.KNOWN_SERVICES['wcs'].keys()[0]
+ context['url'] = settings.KNOWN_SERVICES['wcs'].get(self.wcs_site).get('url')
return tmpl.render(context)
diff --git a/combo/apps/wcs/utils.py b/combo/apps/wcs/utils.py
index d25aabf..47a6acf 100644
--- a/combo/apps/wcs/utils.py
+++ b/combo/apps/wcs/utils.py
@@ -28,8 +28,7 @@ def get_wcs_json(url):
def get_wcs_options(url):
references = []
- for wcs_key in settings.COMBO_WCS_SITES:
- wcs_site = settings.COMBO_WCS_SITES.get(wcs_key)
+ for wcs_key, wcs_site in settings.KNOWN_SERVICES.get('wcs', {}).iteritems():
site_title = wcs_site.get('title')
response_json = get_wcs_json(wcs_site.get('url') + url)
if type(response_json) is dict:
@@ -37,7 +36,7 @@ def get_wcs_options(url):
for element in response_json:
slug = element.get('slug')
title = element.get('title')
- if len(settings.COMBO_WCS_SITES) == 1:
+ if len(settings.KNOWN_SERVICES['wcs']) == 1:
label = title
else:
label = '%s : %s' % (site_title, title)
diff --git a/tests/settings.py b/tests/settings.py
index 8d3b71b..a4b49ac 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -2,11 +2,13 @@ INSTALLED_APPS += ('combo.apps.wcs',)
LANGUAGE_CODE = 'en-us'
-COMBO_WCS_SITES = {
+KNOWN_SERVICES = {
+ 'wcs': {
'default': {'title': 'test', 'url': 'http://127.0.0.1:8999/',
'secret': 'combo', 'orig': 'combo'},
'other': {'title': 'test2', 'url': 'http://127.0.0.2:8999/',
'secret': 'combo', 'orig': 'combo'},
+ }
}
import tempfile
diff --git a/tests/test_wcs.py b/tests/test_wcs.py
index 8a08de5..38e7c10 100644
--- a/tests/test_wcs.py
+++ b/tests/test_wcs.py
@@ -223,13 +223,14 @@ def test_current_forms_cell_setup():
try:
# check there is not wcs_site field if there's a single one defined in
# the configuration
- temp_settings = settings.COMBO_WCS_SITES.copy()
- settings.COMBO_WCS_SITES = {'default': settings.COMBO_WCS_SITES['default']}
+ temp_settings = settings.KNOWN_SERVICES.copy()
+ default = settings.KNOWN_SERVICES['wcs']['default']
+ settings.KNOWN_SERVICES = {'wcs': {'default': default}}
form_class = cell.get_default_form_class()
assert form_class is None
finally:
# restore original settings
- settings.COMBO_WCS_SITES = temp_settings
+ settings.KNOWN_SERVICES = temp_settings
@wcsctl_present
def test_current_forms_cell_render():