Changeset 6117
- Timestamp:
- 14/12/09 12:40:11 (11 years ago)
- Location:
- cows_wps/trunk/cows_wps
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cows_wps/trunk/cows_wps/lib/ui/proc_config.py
r5994 r6117 143 143 144 144 # Now render the inputs dict as a form 145 145 count = 0 146 146 for (name, input) in inputs: 147 resp += """<tr><td width="25%%"><b>%s</b></td><td width="60%%">\n""" % name 147 148 # Set colour style for row 149 count += 1 150 row_style = ("even_row", "odd_row")[count % 2] 151 152 # Start HTML for row 153 resp += """<tr class="%s"><td width="25%%"><b>%s</b></td><td width="30%%">\n""" % (row_style, name) 154 155 # Parse arguments from config 148 156 al = input["allowed_length"] 149 157 pv = input["possible_values"] 158 default = input.get("default", None) 159 opt = input.get("optional", False) 150 160 array_or_item = input["item_type"] 161 162 multiple = False 163 if array_or_item == "list": 164 multiple = True 165 151 166 tp = input["type"] 152 167 168 # Add a default instruction for this input type 169 instruction = "" 170 if opt == True: 171 instruction = "This input is optional." 172 173 # Now render them according to data type etc 153 174 if pv != None: 154 resp += fm.renderSelectList(name, values=pv) 175 resp += fm.renderSelectList(name, values=pv, optional=opt, multiple=multiple) 176 n_items = "an item" 177 if multiple == True: n_items = "one or more items" 178 instruction += " Please select %s from the list." % n_items 155 179 156 180 elif tp == "bool": 157 181 resp += fm.renderRadioButton(name, is_boolean=True) 182 instruction += " Please select either true or false." 158 183 159 elif tp in ("float", "int", "string"): 160 resp += fm.renderTextInput(name, dtype=tp) 184 elif tp in ("float", "int", "string", "datetime"): 185 if tp == "datetime": 186 if default: 187 # Ensure time formatted correctly 188 default = str(default).replace(" ", "T") 189 190 instruction += " Please insert a date/time field in the format <kbd><B>YYYY-MM-DDThh:mm:ss</B></kbd> such as <kbd>2009-01-01T00:00:00</kbd>." 191 else: 192 instruction += " Please insert a value of type: %s." % tp 193 194 resp += fm.renderTextInput(name, dtype=tp, optional=opt, default=default) 161 195 162 196 elif tp == "filepath": 163 197 base_dir = input["basedir"] 164 198 resp += fm.renderTypeAheadDirList(name, base_dir) 165 166 resp += "</td><td>%s</td></tr>\n" % "Eventually we'll put some useful advice here." 199 instruction += " Please type a file path on the CEDA file system. Click down to auto-fill with one of the options on the drop-down list." 200 201 elif tp == "bbox": 202 extent = input.get("extent", False) 203 resp += fm.renderBBox(name, extent) 204 csv_extent = extent.replace("|", ", ") 205 instruction += " Please select a valid bounding box with the following geographical extent: %s" % csv_extent 206 207 resp += "</td><td>%s</td></tr>\n" % instruction 167 208 168 209 resp += '<tr><td></td><td><input type="submit" value="Submit" /></td><td></td></table>\n</form>\n' -
cows_wps/trunk/cows_wps/process_handler/validate_arguments.py
r6111 r6117 46 46 return parseDateTime(item) 47 47 elif dtype in ("bbox",): 48 dtype = "float"48 return parseBBox(item) 49 49 50 50 transformer = dtype … … 147 147 date_time_value = dateutil.parser.parse("2008-02-23T12:12:12") 148 148 return date_time_value 149 150 151 def parseBBox(item): 152 """ 153 Checks bbox is valid floats. 154 """ 155 err_msg = "Invalid bounding box supplied: '%s'." % item 156 157 if not len(item) == 4: 158 raise Exception(err_msg) 159 160 try: 161 # can we convert all to floats 162 bbox_floats = [float(i) for i in item] 163 except: 164 raise Exception(err_msg) 165 166 # Must be physically valid 167 phys_err = "Value of '%s' (%s) is out of range in bounding box supplied: '%s'." 168 directions = ("north", "west", "south", "east") 169 ranges = [(-90, 90), (-360, 360), (-90, 90), (-360, 360)] 170 171 for i in range(4): 172 low, high = ranges[i] 173 value = bbox_floats[i] 174 direction = directions[i] 175 176 if value > high or value < low: 177 raise Exception(phys_err % (direction, value, bbox_floats)) 178 179 return bbox_floats 149 180 150 181 … … 171 202 new_dict = {} 172 203 173 # log.info("running validation")174 175 204 # Step through each arg testing for validity 176 205 arg_names = self.valids["DataInputs"].keys() … … 197 226 198 227 elif d.has_key('optional'): 199 200 228 if not d['optional']: 201 229 raise Exception("key %s does not exist in args (%s)" % (name, self.args.keys())) 202 203 230 else: 204 231 raise Exception("key %s does not exist in args (%s)" % (name, self.args.keys())) … … 208 235 # Test the value provided 209 236 value_given = self.args[name] 210 211 237 new_dict[name] = parseValue(value_given, d) 212 238 -
cows_wps/trunk/cows_wps/public/js/ui/validate.js
r5960 r6117 19 19 } 20 20 21 /* function: validateString(): 21 /* 22 function: validateTextInput(): 22 23 Validates a string input checking it conforms to a regext pattern. 23 24 Inputs: … … 38 39 var validators = new Array(); 39 40 /* Validator is a pseudo-class */ 40 function Validator(name, validation_type, regex_match, msg ) {41 function Validator(name, validation_type, regex_match, msg, optional) { 41 42 this.name = name; 42 43 this.validation_type = validation_type; 43 44 this.regex_match = regex_match; 44 45 this.msg = msg; 46 this.optional = optional; 45 47 } 46 48 … … 62 64 } 63 65 64 function addValidator(name, validation_type, regex_match, msg) { 65 var vdr = new Validator(name, validation_type, regex_match, msg); 66 /* 67 function addValidator 68 Inputs: 69 * name - in form 70 * which validation method 71 * regex_match - regex to test against 72 * msg - message to show if error 73 * optional - boolean to say that arg is optional or not 74 */ 75 function addValidator(name, validation_type, regex_match, msg, optional) { 76 var vdr = new Validator(name, validation_type, regex_match, msg, optional); 66 77 var this_arr = new Array(vdr); 67 78 validators = validators.concat(this_arr); … … 82 93 var regex_match = vdr.regex_match; 83 94 var msg = vdr.msg; 95 var optional = vdr.optional; 84 96 85 97 var fnc = vm.getFunction(validation_type); 86 98 87 99 var value = document.getElementById(name).value; 88 var res = fnc.call(this, value, regex_match, msg); 100 101 // If optional then we can return true if empty 102 var res = false; 103 if (optional == true) { 104 if (value == "") { 105 res = true; 106 } 107 } else { 108 res = fnc.call(this, value, regex_match, msg); 109 } 89 110 90 111 if (res == false) { -
cows_wps/trunk/cows_wps/public/style/wps_ui.css
r5958 r6117 115 115 height: 50px; 116 116 } 117 118 .odd_row { 119 background-color: #eeeeff; 120 } 121 122 .even_row { 123 background-color: #eeccff; 124 } -
cows_wps/trunk/cows_wps/renderer/form_renderer.py
r6111 r6117 33 33 return html 34 34 35 def renderTextInput(self, name, dtype ):35 def renderTextInput(self, name, dtype, optional=False, default=None): 36 36 """ 37 37 Returns HTML for text input including onChange validator. 38 optional is a boolean. 39 40 Populates with default value if not None. 38 41 """ 42 if default == None: default = "" 43 39 44 allowed_dtypes = ("float", "int", "string", "datetime") 45 js_opt = str(optional).lower() 40 46 41 47 if dtype not in allowed_dtypes: … … 49 55 (regex, msg) = validators[dtype] 50 56 51 html = """<input type="text" name="%s" id="%s" value=" " onChange="validateTextInput(this.value, %s, '%s');" /><br />\n""" % (name, name, regex, msg)52 html += """<script type="text/javascript">addValidator('%s', 'text', %s, '%s' );</script>\n""" % (name, regex, msg)57 html = """<input type="text" name="%s" id="%s" value="%s" onChange="validateTextInput(this.value, %s, '%s', %s);" /><br />\n""" % (name, name, default, regex, msg, js_opt) 58 html += """<script type="text/javascript">addValidator('%s', 'text', %s, '%s', %s);</script>\n""" % (name, regex, msg, js_opt) 53 59 return html 54 60 55 def renderSelectList(self, name, values ):61 def renderSelectList(self, name, values, optional=False, multiple=False): 56 62 """ 57 63 Returns HTML for select list. 64 65 If optional is True then add an extra option called "-- Please select --". 58 66 """ 59 html = """<select name="%s" id="%s">\n""" % (name, name) 60 67 if optional == True: 68 values.insert(0, "-- Please select --") 69 70 multiple_string = "" 71 if multiple == True: 72 multiple_string = 'multiple="multiple"' 73 74 html = """<select %s name="%s" id="%s">\n""" % (multiple_string, name, name) 75 76 selected = 'selected="selected"' 61 77 for value in values: 62 html += """ <option value="%s">%s</option>\n""" % (value, value) 78 html += """ <option %s value="%s">%s</option>\n""" % (selected, value, value) 79 selected = "" 63 80 64 81 return html 65 82 66 def renderBBox(self, name, extent): 83 def renderBBox(self, name, extent="90|-180|-90|180"): 84 """ 85 Renders a bounding box and N/W/S/E/ selectors. 86 """ 87 if extent == False: extent = "90|-180|-90|180" 88 89 (n, w, s, e) = extent.split("|") 90 91 html = """ <label for="_north">North:</label> <input type="text" id="_north" name="_north" value="%s" onChange="updateBBox('%s');" /><br> 92 <label for="_west">West:</label> <input type="text" id="_west" name="_west" value="%s" onChange="updateBBox('%s');" /><br> 93 <label for="_south">South:</label> <input type="text" id="_south" name="_south" value="%s" onChange="updateBBox('%s');" /><br> 94 <label for="_east">East:</label> <input type="text" id="_east" name="_east" value="%s" onChange="updateBBox('%s');" /><br> 95 <input type="hidden" id="%s" name="%s" value="%s" /> 96 """ % (n, name, w, name, s, name, e, name, name, name, extent) 97 98 return html 99 100 101 def renderBBoxOLD(self, name, extent): 67 102 """ 68 103 Renders a bounding box and N/W/S/E selectors.
Note: See TracChangeset
for help on using the changeset viewer.