Home | Trees | Indices | Help |
|
---|
|
1 """ Pyjamas Django Forms Integration 2 3 Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 4 5 """ 6 7 from pyjamas.ui.TextBox import TextBox 8 from pyjamas.ui.Grid import Grid 9 from pyjamas.ui.FormPanel import FormPanel 10 #from pyjamas.ui.Composite import Composite 11 from pyjamas.log import writebr 12 13 from pyjamas.ui.TextBox import TextBox 143117 TextBox.__init__(self) 18 self.max_length = kwargs.get('max_length', None) 19 self.min_length = kwargs.get('min_length', None) 20 self.required = kwargs.get('required', None) 21 if kwargs.get('initial'): 22 self.setValue(kwargs['initial'])23 2830 return self.getText()4834 #writebr("MAKING INTEGERFIELD from kwargs: %s" % kwargs) 35 TextBox.__init__(self) 36 self.required = kwargs.get('required', None) 37 if kwargs.get('initial'): 38 self.setValue(kwargs['initial'])39 4465 66 widget_factory = {'CharField': CharField, 67 'IntegerField': IntegerField, 68 'FloatField': FloatField 69 } 7051 TextBox.__init__(self) 52 self.max_length = kwargs.get('max_length', None) 53 self.min_length = kwargs.get('min_length', None) 54 self.required = kwargs.get('required', None) 55 if kwargs.get('initial'): 56 self.setValue(kwargs['initial'])57 6264 return self.getText()72 758577 78 method = request_info.method 79 80 writebr(repr(response)) 81 writebr("%d" % len(response)) 82 writebr("%s" % repr(response.keys())) 83 84 self.sink.save_respond(response)87 9010492 93 method = request_info.method 94 95 writebr(method) 96 writebr(repr(response)) 97 writebr("%d" % len(response)) 98 writebr("%s" % repr(response.keys())) 99 100 self.sink.do_get(response)101103 writebr("Server Error or Invalid Response: ERROR %d" % code + " - " + message + ' - Remote method : ' + request_info.method)106 109 116119118 writebr("Server Error or Invalid Response: ERROR %d" % code + " - " + message + ' - Remote method : ' + request_info.method)121248123 124 self.describe_listeners = [] 125 if kwargs.has_key('listener'): 126 listener = kwargs.pop('listener') 127 self.addDescribeListener(listener) 128 129 if kwargs.has_key('data'): 130 data = kwargs.pop('data') 131 else: 132 data = None 133 134 FormPanel.__init__(self, **kwargs) 135 self.svc = svc 136 self.grid = Grid() 137 self.grid.resize(0, 3) 138 self.add(self.grid) 139 self.describer = FormDescribeGrid(self) 140 self.saver = FormSaveGrid(self) 141 self.getter = FormGetGrid(self) 142 self.formsetup(data)143145 self.describe_listeners.append(l)146148 """ adds a widget, with error rows interspersed 149 """ 150 151 num_rows = self.grid.getRowCount() 152 self.grid.resize((num_rows+1), 3) 153 self.grid.setHTML(num_rows, 0, description) 154 self.grid.setWidget(num_rows, 1, widget)155 159161 self.clear_errors() 162 if data is None: 163 data = self.getValue() 164 self.data = data 165 writebr(repr(self.data)) 166 self.svc(data, {'save': None}, self.saver)167169 170 if not response['success']: 171 errors = response['errors'] 172 self.set_errors(errors) 173 for l in self.describe_listeners: 174 l.onErrors(self, errors) 175 return 176 177 for l in self.describe_listeners: 178 l.onSaveDone(self, response)179181 182 if data is None: 183 data = {} 184 self.data = data 185 self.svc(data, {'describe': None}, self.describer)186 191193 194 offsets = {} 195 for idx, fname in enumerate(self.fields): 196 offsets[fname] = idx 197 for k, err in errors.items(): 198 err = "<br />".join(err) 199 idx = offsets[k] 200 self.grid.setHTML(idx, 2, err)201203 if data is not None: 204 self.data = data 205 206 for idx, fname in enumerate(self.fields): 207 val = None 208 if self.data.has_key(fname): 209 val = self.data[fname] 210 w = self.grid.getWidget(idx, 1) 211 w.setValue(val)212214 fields = response.get('instance', None) 215 if fields: 216 self.update_values(fields) 217 for l in self.describe_listeners: 218 l.onRetrieveDone(self, fields)219221 222 self.fields = fields.keys() 223 for idx, fname in enumerate(self.fields): 224 field = fields[fname] 225 if self.data and self.data.has_key(fname): 226 field['initial'] = self.data[fname] 227 field_type = field['type'] 228 widget_kls = widget_factory.get(field_type, CharField) 229 fv = {} 230 for (k, v) in field.items(): 231 fv[str(k)] = v 232 w = widget_kls(**fv) 233 self.add_widget(field['label'], w) 234 235 for l in self.describe_listeners: 236 l.onDescribeDone(self)237
Home | Trees | Indices | Help |
|
---|
http://epydoc.sourceforge.net |