Moved check is_attract_project() to AttractExtension.

This commit is contained in:
2016-10-11 16:34:31 +02:00
parent 3c2a00b086
commit 300d31b119
2 changed files with 37 additions and 22 deletions

View File

@@ -111,6 +111,39 @@ class AttractExtension(PillarExtension):
return projects return projects
def is_attract_project(self, project, test_extension_props=True):
"""Returns whether the project is set up for Attract.
Requires the task node type and Attract extension properties.
Testing the latter can be skipped with test_extension_props=False.
"""
from .node_types.task import node_type_task
node_type_name = node_type_task['name']
node_type = project.get_node_type(node_type_name)
if not node_type:
return False
if not test_extension_props:
return True
try:
pprops = project.extension_props[EXTENSION_NAME]
except AttributeError:
self._log.warning("is_attract_project: Project url=%r doesn't have any "
"extension properties.", project['url'])
if self._log.isEnabledFor(logging.DEBUG):
import pprint
self._log.debug('Project: %s', pprint.pformat(project.to_dict()))
return False
if pprops is None:
self._log.warning("is_attract_project: Project url=%r doesn't have Attract"
" extension properties.", project['url'])
return False
return True
def _get_current_attract(): def _get_current_attract():
"""Returns the Attract extension of the current application.""" """Returns the Attract extension of the current application."""

View File

@@ -56,7 +56,6 @@ def attract_project_view(extra_project_projections=None, extension_props=False):
:type extension_props: bool :type extension_props: bool
""" """
from .node_types.task import node_type_task
from . import EXTENSION_NAME from . import EXTENSION_NAME
if callable(extra_project_projections): if callable(extra_project_projections):
@@ -91,31 +90,14 @@ def attract_project_view(extra_project_projections=None, extension_props=False):
{'projection': projections}, {'projection': projections},
api=api) api=api)
node_type_name = node_type_task['name'] is_attract = current_attract.is_attract_project(project,
node_type = project.get_node_type(node_type_name) test_extension_props=extension_props)
if not node_type: if not is_attract:
log.warning('createProject url=%s does not have node type %r',
project_url, node_type_name)
return error_project_not_setup_for_attract() return error_project_not_setup_for_attract()
if extension_props: if extension_props:
try:
pprops = project.extension_props.attract pprops = project.extension_props.attract
except AttributeError:
log.warning("attract_project_view(%s): Project url=%r doesn't have any"
" extension properties.", wrapped, project_url)
if log.isEnabledFor(logging.DEBUG):
import pprint
log.debug('Project: %s', pprint.pformat(project.to_dict()))
return error_project_not_setup_for_attract()
if pprops is None:
log.warning("attract_project_view(%s): Project url=%r doesn't have Attract"
" extension properties.", wrapped, project_url)
return error_project_not_setup_for_attract()
return wrapped(project, pprops, *args, **kwargs) return wrapped(project, pprops, *args, **kwargs)
return wrapped(project, *args, **kwargs) return wrapped(project, *args, **kwargs)
return wrapper return wrapper