def computeValue(self): # First lookup the request ignoreRequest = getValue(self.component, 'ignoreRequest', self.form) if not ignoreRequest: extractor = self.form.widgetFactory.extractor(self.component) if extractor is not None: value = extractor.extractRaw() if value: return self.prepareRequestValue(value, extractor) # After, the context ignoreContent = getValue(self.component, 'ignoreContent', self.form) if not ignoreContent: data = self.form.getContentData() try: value = data.get(self.component.identifier) # XXX: Need review if value is None: value = NO_VALUE return self.prepareContentValue(value) except KeyError: # No value on the content for field, continue. pass # Take any default value value = self.component.getDefaultValue(self.form) return self.prepareContentValue(value)
def computeValue(self): field = self._field if not getValue(self.component, 'ignoreRequest', self.form): if 'marker_' + self._key in self.request: return field._get_default(self._key, None, self.request) if not getValue(self.component, 'ignoreContent', self.form): if self.form.getContent() is not None: data = self.form.getContentData() try: return data.get(self.component.identifier) except KeyError: pass return field.get_value('default')
def process(self, form, request): assert interfaces.ITableFormCanvas.providedBy(form) one_selected = False ready = False for action in self: extractor = component.getMultiAdapter( (action, form, request), IWidgetExtractor) value, error = extractor.extract() if value is not NO_VALUE: isPostOnly = getValue(action, 'postOnly', form) if isPostOnly and request.method != 'POST': form.errors.append( Error('This form was not submitted properly.', form.prefix)) return form, None, FAILURE if not ready: form.updateLines(mark_selected=True) ready = True for line in form.lines: if not line.selected: continue one_selected = True try: if action.validate(form): content = line.getContentData().getContent() action(form, content, line) except ActionError, e: line.errors.append(Error(e.args[0], line.prefix)) if not one_selected: form.errors.append( Error(_(u"You didn't select any item!"), None)) return form, action, FAILURE return form, action, SUCCESS
def process(self, form, request): assert interfaces.ITableFormCanvas.providedBy(form) selected_lines = [] unselected_lines = [] ready = False for action in self: extractor = component.getMultiAdapter( (action, form, request), IWidgetExtractor) value, error = extractor.extract() if value is not NO_VALUE: isPostOnly = getValue(action, 'postOnly', form) if isPostOnly and request.method != 'POST': form.errors.append( Error('This form was not submitted properly.', form.prefix)) return form, None, FAILURE if not ready: form.updateLines(mark_selected=True) for line in form.lines: if line.selected: selected_lines.append(line) else: unselected_lines.append(line) ready = True try: if action.validate(form): return form, action, action( form, selected_lines, unselected_lines) except ActionError, e: form.errors.append(Error(e.args[0], form.prefix)) return form, action, FAILURE
def widget(self, field): """Create a widget for the given field. """ if not field.available(self.form): return None mode = str(getValue(field, 'mode', self.form)) return component.getMultiAdapter( (field, self.form, self.request), interfaces.IWidget, name=mode)
def process(self, form, request): assert interfaces.ITableFormCanvas.providedBy(form) selected_lines = [] deselected_lines = [] unchanged_lines = [] # mark selected by request form.updateLines(mark_selected=True) for line in form.lines: data = line.getContentData() content_selected = data.get(line.selectedField.identifier) if content_selected: if line.selected: unchanged_lines.append(line) else: deselected_lines.append(line) else: if line.selected: selected_lines.append(line) else: unchanged_lines.append(line) status = NOTHING_DONE for action in self: extractor = component.getMultiAdapter( (action, form, request), IWidgetExtractor) value, error = extractor.extract() if value is NO_VALUE: continue isPostOnly = getValue(action, 'postOnly', form) if isPostOnly and request.method != 'POST': form.errors.append( Error('This form was not submitted properly.', form.prefix)) return form, None, FAILURE try: if action.validate(form): return form, action, action( form, selected_lines, deselected_lines, unchanged_lines) except ActionError, e: form.errors.append(Error(e.args[0], form.prefix)) return form, action, FAILURE
def extractor(self, field): """Create a widget extractor for the given field. """ mode = getValue(field, 'mode', self.form) # The field mode should be extractable or we skip it. if (IModeMarker.providedBy(mode) and mode.extractable is False): return None extractor = component.queryMultiAdapter( (field, self.form, self.request), interfaces.IWidgetExtractor, name=str(mode)) if extractor is not None: return extractor # Default to the default extractor return component.getMultiAdapter( (field, self.form, self.request), interfaces.IWidgetExtractor)