From 952c12bd60ce7912375ee12aeb4a118713b298fa Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 30 Oct 2008 17:34:46 -0400 Subject: [PATCH] Convert tool_form/tool_executed to mako (for performance) --- lib/galaxy/tools/__init__.py | 10 +- ...{tool_executed.tmpl => tool_executed.mako} | 39 ++-- templates/tool_form.mako | 194 ++++++++++++++++++ templates/tool_form.tmpl | 191 ----------------- 4 files changed, 215 insertions(+), 219 deletions(-) rename templates/{tool_executed.tmpl => tool_executed.mako} (61%) create mode 100644 templates/tool_form.mako delete mode 100644 templates/tool_form.tmpl diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 3c0eb30631c..81574a3986f 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -676,7 +676,7 @@ class Tool: # on the standard run form) or "URL" (a parameter provided by # external data source tools). if "runtool_btn" not in incoming and "URL" not in incoming: - return "tool_form.tmpl", dict( errors={}, tool_state=state, param_values={}, incoming={} ) + return "tool_form.mako", dict( errors={}, tool_state=state, param_values={}, incoming={} ) # Process incoming data if not( self.check_values ): # If `self.check_values` is false we don't do any checking or @@ -702,20 +702,20 @@ class Tool: # error messages if errors: error_message = "One or more errors were found in the input you provided. The specific errors are marked below." - return "tool_form.tmpl", dict( errors=errors, tool_state=state, incoming=incoming, error_message=error_message ) + return "tool_form.mako", dict( errors=errors, tool_state=state, incoming=incoming, error_message=error_message ) # If we've completed the last page we can execute the tool elif state.page == self.last_page: out_data = self.execute( trans, incoming=params ) - return 'tool_executed.tmpl', dict( out_data=out_data ) + return 'tool_executed.mako', dict( out_data=out_data ) # Otherwise move on to the next page else: state.page += 1 # Fill in the default values for the next page self.fill_in_new_state( trans, self.inputs_by_page[ state.page ], state.inputs ) - return 'tool_form.tmpl', dict( errors=errors, tool_state=state ) + return 'tool_form.mako', dict( errors=errors, tool_state=state ) else: # Just a refresh, render the form with updated state and errors. - return 'tool_form.tmpl', dict( errors=errors, tool_state=state ) + return 'tool_form.mako', dict( errors=errors, tool_state=state ) def update_state( self, trans, inputs, state, incoming, prefix="", context=None, update_only=False, old_errors={}, changed_dependencies={} ): diff --git a/templates/tool_executed.tmpl b/templates/tool_executed.mako similarity index 61% rename from templates/tool_executed.tmpl rename to templates/tool_executed.mako index fa9e98eaa18..9fd7ed1bc08 100644 --- a/templates/tool_executed.tmpl +++ b/templates/tool_executed.mako @@ -4,37 +4,31 @@ Galaxy - + @@ -43,14 +37,13 @@ -

The following job has been succesfully added to the queue:

-#for $data in $out_data.values -
$data.hid: $data.name
-#end for +%for data in out_data.values(): +
${data.hid}: ${data.name}
+%endfor

You can check the status of queued jobs and view the resulting @@ -59,9 +52,9 @@ the status will change from 'running' to 'finished' if completed succesfully or 'error' if problems were encountered.

-#if $tool.options.refresh -
-#end if +%if tool.options.refresh: +
+
${input.title_plural}
+ <% repeat_state = tool_state[input.name] %> + %for i in range( len( repeat_state ) ): +
+ <% + if input.name in errors: + rep_errors = errors[input.name][i] + else: + rep_errors = dict() + index = repeat_state[i]['__index__'] + %> +
${input.title} ${i + 1}
+ ${do_inputs( input.inputs, repeat_state[i], rep_errors, prefix + input.name + "_" + str(index) + "|", other_values )} +
+
+ %endfor +
+
+ %elif input.type == "conditional": + <% + group_state = tool_state[input.name] + group_errors = errors.get( input.name, {} ) + current_case = group_state['__current_case__'] + group_prefix = prefix + input.name + "|" + %> + ${row_for_param( group_prefix, input.test_param, group_state, group_errors, other_values )} + ${do_inputs( input.cases[current_case].inputs, group_state, group_errors, group_prefix, other_values )} + %else: + ${row_for_param( prefix, input, tool_state, errors, other_values )} + %endif + %endfor + + +<%def name="row_for_param( prefix, param, parent_state, parent_errors, other_values )"> + <% + if parent_errors.has_key( param.name ): + cls = "form-row form-row-error" + else: + cls = "form-row" + %> +
+ <% label = param.get_label() %> + %if label: + + %endif + <% + field = param.get_html_field( trans, parent_state[ param.name ], other_values ) + field.refresh_on_change = param.refresh_on_change + %> +
${field.get_html( prefix )}
+ %if parent_errors.has_key( param.name ): +
+
 ${parent_errors[param.name]}
+
+ %endif + + %if param.help: +
+ ${param.help} +
+ %endif + +
+ +
+ + +%if add_frame.from_noframe: +
+ Welcome to Galaxy +
+ It appears that you found this tool from a link outside of Galaxy. + If you're not familiar with Galaxy, please consider visiting the + welcome page. + To learn more about what Galaxy is and what it can do for you, please visit + the Galaxy wiki. +
+
+%endif + +
+ %if tool.has_multiple_pages: +
${tool.name} (step ${tool_state.page+1} of ${tool.npages})
+ %else: +
${tool.name}
+ %endif +
+
+ + + + %if tool.display_by_page[tool_state.page]: + ${trans.fill_template_string( tool.display_by_page[tool_state.page], other_values=tool.get_param_html_map( trans, tool_state.page, tool_state.inputs ) )} + + + %else: + +
+ %if tool_state.page == tool.last_page: + + %else: + + %endif +
+ ${do_inputs( tool.inputs_by_page[ tool_state.page ], tool_state.inputs, errors, "" )} +
+ %if tool_state.page == tool.last_page: + + %else: + + %endif +
+ + %endif + +
+
+
+ +%if tool.help: +
+
+ %if tool.has_multiple_pages: + ${tool.help_by_page[tool_state.page]} + %else: + ${tool.help} + %endif +
+
+%endif + + + + + + diff --git a/templates/tool_form.tmpl b/templates/tool_form.tmpl deleted file mode 100644 index 86f359e0849..00000000000 --- a/templates/tool_form.tmpl +++ /dev/null @@ -1,191 +0,0 @@ - - - -#from galaxy.util.expressions import ExpressionContext - - - - -Galaxy - - - - - - - - -## #if $getVar( 'error_message', None ) -##
$error_message
-##

-## #end if - -#def do_inputs( $inputs, $tool_state, $errors, $prefix, $context=None ) - #set $context = ExpressionContext( $tool_state, $context ) - #for $input_index, $input in enumerate( $inputs.itervalues() ) - #if $input.type == "repeat" -
-
${input.title_plural}
- #set repeat_state = $tool_state[$input.name] - #for i in range( len( $repeat_state ) ): -
- #if $input.name in errors - #set rep_errors = $errors[$input.name][$i] - #else - #set rep_errors = dict() - #end if - #set index = $repeat_state[$i]['__index__'] -
${input.title} ${i + 1}
- $do_inputs( $input.inputs, $repeat_state[$i], $rep_errors, $prefix + $input.name + "_" + str($index) + "|", $context ) -
-
- #end for -
-
- #elif $input.type == "conditional" - #set group_state = $tool_state[$input.name] - #set group_errors = $errors.get( $input.name, {} ) - #set current_case = $group_state['__current_case__'] - #set group_prefix = $prefix + $input.name + "|" - $row_for_param( $group_prefix, $input.test_param, $group_state, $group_errors, $context ) - $do_inputs( $input.cases[$current_case].inputs, $group_state, $group_errors, $group_prefix, $context ) - #else - $row_for_param( $prefix, $input, $tool_state, $errors, $context ) - #end if - #end for -#end def - -#def row_for_param( $prefix, $param, $parent_state, $parent_errors, $context ) - #if $parent_errors.has_key( $param.name ): - #set cls = "form-row form-row-error" - #else - #set cls = "form-row" - #end if -
- #set label = $param.get_label() - #if $label: - - #end if - #set field = $param.get_html_field( $caller, $parent_state[ $param.name ], $context ) - #set $field.refresh_on_change = $param.refresh_on_change -
$field.get_html( $prefix )
- #if $parent_errors.has_key( $param.name ): -
-
 $parent_errors[$param.name]
-
- #elif $param.help - ##
$param.help
- #end if - - #if $param.help -
- $param.help -
- - #end if - -
- -
-#end def - -#if $add_frame.from_noframe -
- Welcome to Galaxy -
- It appears that you found this tool from a link outside of Galaxy. If you're not familiar with Galaxy, please consider visiting the welcome page. To learn more about what Galaxy is and what it can do for you, please visit the Galaxy wiki. -
-
-#end if - -
- #if $tool.has_multiple_pages -
$tool.name (step #echo $tool_state.page+1 # of $tool.npages)
- #else -
$tool.name
- #end if -
-
- - - - #if $tool.display_by_page[$tool_state.page] - - $caller.fill_template_string( $tool.display_by_page[$tool_state.page], context=$tool.get_param_html_map( $caller, $tool_state.page, $tool_state.inputs ) ) - - - #else - -
- #if $tool_state.page == $tool.last_page - - #else - - #end if -
- $do_inputs( $tool.inputs_by_page[ $tool_state.page ], $tool_state.inputs, $errors, "" ) -
- #if $tool_state.page == $tool.last_page - - #else - - #end if -
- - #end if - -
-
-
- -#if $tool.help -
-
- #if $tool.has_multiple_pages - $tool.help_by_page[$tool_state.page] - #else - $tool.help - #end if -
-
-#end if - - - - - -