Exemple #1
0
    def create(workflow, new_order):
        # Validation: all id's and orders exist and orders are in range 0..n-1
        wfms = WfModule.objects.filter(workflow=workflow)

        ids = [wfm.id for wfm in wfms]
        for record in new_order:
            if not isinstance(record, dict):
                raise ValueError(
                    'JSON data must be an array of {id:x, order:y} objects')
            if 'id' not in record:
                raise ValueError('Missing WfModule id')
            if record['id'] not in ids:
                raise ValueError('Bad WfModule id')
            if 'order' not in record:
                raise ValueError('Missing WfModule order')

        orders = [record['order'] for record in new_order]
        orders.sort()
        if orders != list(range(0, len(orders))):
            raise ValueError('WfModule orders must be in range 0..n-1')

        # Looks good, let's reorder
        delta = Delta.create_impl(ReorderModulesCommand,
                                  workflow=workflow,
                                  old_order=json.dumps([{
                                      'id': wfm.id,
                                      'order': wfm.order
                                  } for wfm in wfms]),
                                  new_order=json.dumps(new_order),
                                  command_description='Reordered modules')

        notify_client_workflow_version_changed(workflow)
        return delta
Exemple #2
0
    def create(parameter_val, value):
        workflow = parameter_val.wf_module.workflow
        pspec = parameter_val.parameter_spec

        # We don't create a Delta for derived_data parameter. Such parameters are essentially caches,
        # (e.g. chart output image) and are created either during module render() or in the front end
        # Instead, we just set the value -- and trust that undo-ing the other parameters will also set
        # the derived_data parameters.
        if pspec.derived_data:
            parameter_val.set_value(value)
            return None

        # Not derived data, we're doing this.
        description = \
            'Changed parameter \'' + pspec.name + '\' of \'' + parameter_val.wf_module.get_module_name() + '\' module'

        delta = Delta.create_impl(ChangeParameterCommand,
                                  parameter_val=parameter_val,
                                  new_value=value,
                                  old_value=parameter_val.get_value(),
                                  workflow=workflow,
                                  command_description=description)

        # Clear wf_module errors, on the theory that user might have fixed them. The next render()
        # or event() will re-create the errors if there is still a problem. The only other place
        # errors are cleared is when an event is dispatched.
        parameter_val.wf_module.set_ready(notify=False)

        # increment workflow version number, triggers global re-render if this parameter can effect output
        notify = not pspec.ui_only
        if notify:
            notify_client_workflow_version_changed(workflow)

        return delta
Exemple #3
0
    def create(workflow, name):
        old_name = workflow.name
        description = 'Changed workflow name from ' + old_name + ' to ' + name

        delta = Delta.create_impl(ChangeWorkflowTitleCommand,
                                  workflow=workflow,
                                  new_value=name,
                                  old_value=old_name,
                                  command_description=description)

        return delta
Exemple #4
0
    def create(wf_module, notes):
        old_value = wf_module.notes if wf_module.notes else ''
        description = 'Changed workflow module note from ' + old_value + ' to ' + notes

        delta = Delta.create_impl(ChangeWfModuleNotesCommand,
                                  workflow=wf_module.workflow,
                                  wf_module=wf_module,
                                  new_value=notes,
                                  old_value=old_value,
                                  command_description=description)

        return delta
Exemple #5
0
    def create(workflow, name):
        old_name = workflow.name
        description = 'Changed workflow name from ' + old_name + ' to ' + name

        delta = Delta.create_impl(ChangeWorkflowTitleCommand,
                                  workflow=workflow,
                                  new_value=name,
                                  old_value=old_name,
                                  command_description=description)

        # don't notify client b/c client has already updated UI

        return delta
Exemple #6
0
    def create(wf_module, version):
        description = \
            'Changed \'' + wf_module.get_module_name() + '\' module data version to ' + str(version)

        delta = Delta.create_impl(
            ChangeDataVersionCommand,
            wf_module=wf_module,
            new_version=version,
            old_version=wf_module.get_fetched_data_version(),
            workflow=wf_module.workflow,
            command_description=description)

        return delta
Exemple #7
0
    def create(parameter_val, value):
        workflow = parameter_val.wf_module.workflow
        pspec = parameter_val.parameter_spec

        description = \
            'Changed parameter \'' + pspec.name + '\' of \'' + parameter_val.wf_module.get_module_name() + '\' module'

        delta = Delta.create_impl(ChangeParameterCommand,
                                  parameter_val=parameter_val,
                                  new_value=value,
                                  old_value=parameter_val.get_value(),
                                  workflow=workflow,
                                  command_description=description)

        return delta
Exemple #8
0
    def create(wf_module, auto_update_data, next_update, update_interval):
        description = 'Changed workflow update settings'

        delta = Delta.create_impl(
            ChangeWfModuleUpdateSettingsCommand,
            workflow=wf_module.workflow,
            wf_module=wf_module,
            old_auto=wf_module.auto_update_data,
            new_auto=auto_update_data,
            old_next_update=wf_module.next_update,
            new_next_update=next_update,
            old_update_interval=wf_module.update_interval,
            new_update_interval=update_interval,
            command_description=description)

        return delta
Exemple #9
0
    def create(workflow, module_version, insert_before):
        with workflow.cooperative_lock():
            newwfm = WfModule.objects.create(workflow=None,
                                             module_version=module_version,
                                             order=insert_before,
                                             is_collapsed=False)
            newwfm.create_default_parameters()

            description = 'Added \'' + module_version.module.name + '\' module'
            delta = Delta.create_impl(AddModuleCommand,
                                      workflow=workflow,
                                      wf_module=newwfm,
                                      order=insert_before,
                                      command_description=description)

        return delta
Exemple #10
0
    def create(wf_module):

        # critical section to make double delete check work correctly
        with delete_lock:
            workflow = wf_module.workflow
            if workflow is None:
                return None  # this wfm was already deleted, do nothing

            description = 'Deleted \'' + wf_module.get_module_name(
            ) + '\' module'
            delta = Delta.create_impl(
                DeleteModuleCommand,
                workflow=workflow,
                wf_module=wf_module,
                selected_wf_module=workflow.selected_wf_module,
                command_description=description)
            notify_client_workflow_version_changed(workflow)
            return delta
Exemple #11
0
    def create(wf_module, auto_update_data, next_update, update_interval):
        description = 'Changed workflow update settings'

        delta = Delta.create_impl(
            ChangeWfModuleUpdateSettingsCommand,
            workflow=wf_module.workflow,
            wf_module=wf_module,
            old_auto=wf_module.auto_update_data,
            new_auto=auto_update_data,
            old_next_update=wf_module.next_update,
            new_next_update=next_update,
            old_update_interval=wf_module.update_interval,
            new_update_interval=update_interval,
            command_description=description)

        # No notification needed as client will do update
        # notify_client_workflow_version_changed(wf_module.workflow)

        return delta
Exemple #12
0
    def create(workflow, module_version, insert_before):
        with workflow.cooperative_lock():
            newwfm = WfModule.objects.create(workflow=None,
                                             module_version=module_version,
                                             order=insert_before,
                                             is_collapsed=False)
            newwfm.create_default_parameters()

            # start EditCells collapsed, just this one module for now
            if (module_version.module.id_name == 'editcells'):
                newwfm.is_collapsed = True

            description = 'Added \'' + module_version.module.name + '\' module'
            delta = Delta.create_impl(AddModuleCommand,
                                      workflow=workflow,
                                      wf_module=newwfm,
                                      order=insert_before,
                                      command_description=description)

        return delta