Commit af4fc321 authored by Jerome Mariette's avatar Jerome Mariette

better handle of date types

parent b1ed50d4
......@@ -67,7 +67,7 @@
$this.$element.html("");
$.tmpl($this.options.template, {workflow: workflow, display_run_button: $this.options.displayRunButton,
display_reset_button: $this.options.displayResetButton}).appendTo($this.$element);
$('#dp3').datepicker();
$('.date').datepicker().on('changeDate', function(ev){ $('.date').datepicker('hide');} );
if ($this.options.displayRunButton) {
$("#wfform_run_btn").click(function() { $this.run(); })
}
......@@ -119,8 +119,8 @@
' </select>',
// if param is a date
' {{else param.type == "date"}}',
' <div class="input-append date" id="dp3" data-date="12-02-2012" data-date-format="dd-mm-yyyy">',
' <input name="${param.name}" class="input-xlarge span2" type="text" value="12-02-2012">',
' <div class="input-append date" data-date="${param.default}" data-date-format="dd-mm-yyyy">',
' <input name="${param.name}" class="input-xlarge span2" type="text" value="${param.default}">',
' <button class="btn" type="button"><i class="icon-calendar"></i></button>',
' </div>',
// else a simple text input
......
......@@ -100,25 +100,6 @@ class JFlowServer (object):
return status
def extend_parameters(self, workflow_class, kwargs):
extended_kwargs = {}
workflow = self.wfmanager.get_workflow_by_class(workflow_class)
for param in workflow.parameters:
# if it's an append parameter, the result should be a list
if param.action == "append":
if kwargs.has_key(param.name):
value = kwargs[param.name].encode('ascii','ignore')
extended_kwargs[param.name] = value.split(",")
else:
extended_kwargs[param.name] = []
else:
if kwargs.has_key(param.name):
value = kwargs[param.name].encode('ascii','ignore')
extended_kwargs[param.name] = value
else:
extended_kwargs[param.name] = param.default
return extended_kwargs
@cherrypy.expose
@jsonify
def get_available_workflows(self, **kwargs):
......@@ -142,8 +123,7 @@ class JFlowServer (object):
@cherrypy.expose
@jsonify
def run_workflow(self, **kwargs):
args = self.extend_parameters(kwargs["workflow_class"], kwargs)
workflow = self.wfmanager.run_workflow(kwargs["workflow_class"], args)
workflow = self.wfmanager.run_workflow(kwargs["workflow_class"], kwargs)
return self.jsonify_workflow_status(workflow, True)
@cherrypy.expose
......
......@@ -81,19 +81,20 @@ class Workflow(threading.Thread):
self.engine_arguments = ''
self.component_nameids_is_init = False
self.component_nameids = {}
self.args = args
# try to parse engine arguments
try:
type, options = self.jflow_config_reader.get_batch()
if type: self.engine_arguments += ' -T ' + type
if options : self.engine_arguments += ' -B "' + options + '"'
except: self.engine_arguments = None
#try:
# Add config information
self.name, self.description, self.parameters = self._get_from_config()
#except:
# raise IOError(self.__class__.__name__ + " workflow property file not found or invalid.")
try:
# Add config information
self.name, self.description, self.parameters = self._get_from_config()
except:
raise IOError(self.__class__.__name__ + " workflow property file not found or invalid.")
self.id = id
self.args = self._extend_and_format_args(args)
if self.id is not None:
self.directory = self.manager.get_workflow_directory(self.name, self.id)
if not os.path.isdir(self.directory):
......@@ -190,6 +191,32 @@ class Workflow(threading.Thread):
self.end_time = time.time()
self._serialize()
def _extend_and_format_args(self, args):
extended_args = {}
for param in self.parameters:
try: args[param.name] = args[param.name].encode('ascii','ignore')
except: pass
# if this parameter has been modified by the user
if args.has_key(param.name):
# if it's an append parameter, the result should be a list
if param.action == "append":
try: value = args[param.name].split(",")
except: value = args[param.name]
extended_args[param.name] = value
# if it's a date
elif param.type == date:
if isinstance(args[param.name], str):
extended_args[param.name] = date(args[param.name])
else:
extended_args[param.name] = args[param.name]
else:
extended_args[param.name] = args[param.name]
# otherwise use the default
else:
extended_args[param.name] = param.default
return extended_args
def _get_from_config(self):
reader = ConfigParser()
reader.read(self._get_property_path())
......@@ -205,18 +232,29 @@ class Workflow(threading.Thread):
params[cparam] = {ckey: cvalue}
else:
params[cparam][ckey] = cvalue
# Then build params
for param in params:
name = params[param]["name"]
flag = params[param]["flag"]
help = params[param]["help"]
try: default = params[param]["default"]
except: default = None
# handle default values
try:
# if it's a date and there is no default value, use today as default value
if params[param]["type"] == "date" and not params[param].has_key("default"):
today = datetime.date.today()
default = today.strftime('%d-%m-%Y')
elif params[param].has_key("action"):
if params[param]["action"] == "append": default = []
else:
default = params[param]["default"]
except:
default = None
# handle type values
try:
if params[param]["type"] == "date":
type = date
metavar = "datetime"
metavar = "date"
else:
type = eval(params[param]["type"])
metavar = params[param]["type"]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment