- Timestamp:
- 21 Jul 2010, 14:12:40 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.widgets.core/trunk/src/waeup/widgets/core/dictwidget.py
r5290 r5292 34 34 class DictWidget(SequenceWidget): 35 35 _type = dict 36 #grok.adapts(IDict, IField, IBrowserRequest)37 #grok.adapts(IDict, IBrowserRequest)38 #grok.provides(ISimpleInputWidget)39 36 template = ViewPageTemplateFile('dictwidget.pt') 40 41 37 42 38 def __init__(self, context, request, subwidget=None): … … 66 62 key_widget = getMultiAdapter( 67 63 (key_field, self.request), IInputWidget) 68 #key_widget.setPrefix('%s.key.%d.' % (self.name, i))69 64 key_widget.setPrefix('%s.key.%d.' % (self.name, i)) 70 65 … … 75 70 value_widget = getMultiAdapter( 76 71 (value_field, self.request), IInputWidget) 77 #value_widget.setPrefix('%s.value.%d.' % (self.name, i))78 72 value_widget.setPrefix('%s.value.%d.' % (self.name, i)) 79 #import pdb; pdb.set_trace() 73 80 74 if not self.preserve_widgets: 81 #return super(DictWidget, self)._getWidget(i)82 75 return (key_widget, value_widget) 83 76 self._widgets[i] = (key_widget, value_widget) 84 #return super(DictWidget, self)._getWidget(i)85 77 return self._widgets[i] 86 78 … … 133 125 # pre-populate 134 126 sequence = [(None, None)] * count 135 #sequence = [None] * count136 #sequence = dict()137 127 138 128 # now look through the request for interesting values … … 140 130 removing = self.name + ".remove" in self.request.form 141 131 for i in reversed(range(count)): 142 #widget = self._getWidget(i)143 132 key_widget, value_widget = self._getWidget(i) 144 133 key = None … … 148 137 try: 149 138 key = key_widget.getInputValue() 150 #sequence[i] = widget.getInputValue()151 139 except WidgetInputError, error: 152 140 self._error = error … … 156 144 try: 157 145 value = value_widget.getInputValue() 158 #sequence[i] = widget.getInputValue()159 146 except WidgetInputError, error: 160 147 self._error = error 161 148 raise self._error 162 149 sequence[i] = (key, value) 163 #if widget.hasValidInput():164 # # catch and set sequence widget errors to ``_error`` attribute165 # try:166 # sequence[i] = widget.getInputValue()167 # except WidgetInputError, error:168 # self._error = error169 # raise self._error170 150 171 151 remove_key = "%s.remove_%d" % (self.name, i) … … 196 176 sequence = super(DictWidget, self).getInputValue() 197 177 return sequence 198 return self._type(sequence)199 178 200 179 def _getRenderedValue(self): … … 202 181 if self._renderedValueSet(): 203 182 if self._data is self.context.missing_value: 204 #sequence = []205 183 sequence = dict() 206 184 else: 207 #sequence = list(self._data)208 185 sequence = dict(self._data) 209 186 elif self.hasInput(): 210 #sequence = self._generateSequence()211 187 sequence = dict(self._generateSequence()) 212 188 elif self.context.default is not None: 213 #sequence = self.context.default214 189 sequence = self.context.default 215 190 else: 216 #sequence = []217 191 seuence = dict() 218 # ensure minimum number of items in the form219 #while len(sequence) < self.context.min_length:220 # # Shouldn't this use self.field.value_type.missing_value,221 # # instead of None?222 # #sequence.append(None)223 # pass224 192 return sequence 225 193 … … 231 199 change = field.query(content, self) != value 232 200 if change: 233 print "SET: ", field, content, value234 201 field.set(content, value) 235 else:236 print "NO SET: ", field, content, value237 202 return change 238 203 … … 254 219 255 220 def __init__(self, context, request, subwidget=None): 256 # def __init__(self, context, field, request, subwidget=None):257 221 super(DictDisplayWidget, self).__init__(context, request) 258 222 self.subwidget = subwidget … … 260 224 def __call__(self): 261 225 # get the data to display: 262 #import pdb; pdb.set_trace()263 226 if self._renderedValueSet(): 264 227 data = self._data … … 269 232 if data == self.context.missing_value: 270 233 return translate(self._missingValueMessage, self.request) 271 #data = list(data)272 234 data = dict(data) 273 235 if not data: … … 275 237 276 238 parts = [] 277 # for i, item in enumerate(data):278 239 for i, item in enumerate(data.items()): 279 #widget = self._getWidget(i)280 240 key_widget, value_widget = self._getWidget(i) 281 241 key_widget.setRenderedValue(item[0]) 282 242 value_widget.setRenderedValue(item[1]) 283 #widget.setRenderedValue(item)284 #s = widget()285 243 s = "%s: %s" % (key_widget(), value_widget()) 286 244 if self.itemTag:
Note: See TracChangeset for help on using the changeset viewer.