Moved check is_attract_project() to AttractExtension.
This commit is contained in:
@@ -111,6 +111,39 @@ class AttractExtension(PillarExtension):
|
||||
|
||||
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():
|
||||
"""Returns the Attract extension of the current application."""
|
||||
|
@@ -56,7 +56,6 @@ def attract_project_view(extra_project_projections=None, extension_props=False):
|
||||
:type extension_props: bool
|
||||
"""
|
||||
|
||||
from .node_types.task import node_type_task
|
||||
from . import EXTENSION_NAME
|
||||
|
||||
if callable(extra_project_projections):
|
||||
@@ -91,31 +90,14 @@ def attract_project_view(extra_project_projections=None, extension_props=False):
|
||||
{'projection': projections},
|
||||
api=api)
|
||||
|
||||
node_type_name = node_type_task['name']
|
||||
node_type = project.get_node_type(node_type_name)
|
||||
if not node_type:
|
||||
log.warning('createProject url=%s does not have node type %r',
|
||||
project_url, node_type_name)
|
||||
is_attract = current_attract.is_attract_project(project,
|
||||
test_extension_props=extension_props)
|
||||
if not is_attract:
|
||||
return error_project_not_setup_for_attract()
|
||||
|
||||
if extension_props:
|
||||
try:
|
||||
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()
|
||||
|
||||
pprops = project.extension_props.attract
|
||||
return wrapped(project, pprops, *args, **kwargs)
|
||||
|
||||
return wrapped(project, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
Reference in New Issue
Block a user