def processInput(self, values): """ """ values = BaseField.processInput(self, values) if type(values) == list: values = [asUnicode(v) for v in values] return values
def getFieldValue(self, form, doc=None, editmode_obsolete=False, creation=False, request=None): """ """ fieldValue = BaseField.getFieldValue(self, form, doc, editmode_obsolete, creation, request) mode = self.context.getFieldMode() if (mode == "EDITABLE" and request and ((doc is None and not (creation)) or request.has_key('Plomino_datagrid_rowdata'))): fieldname = self.context.id fieldValue = request.get(fieldname, fieldValue) if fieldValue and isinstance(fieldValue, basestring): fmt = self.format if not fmt: fmt = form.getParentDatabase().getDateTimeFormat() fieldValue = StringToDate(fieldValue, fmt) return fieldValue
def getFieldValue(self, form, doc, editmode, creation, request): """ """ fieldValue = BaseField.getFieldValue(self, form, doc, editmode, creation, request) mode = self.context.getFieldMode() if mode == "EDITABLE" and request: if (doc is None and not (creation) ) or request.has_key('Plomino_datagrid_rowdata'): fieldname = self.context.id fieldValue = request.get(fieldname, fieldValue) if fieldValue: format = self.format if not format: format = form.getParentDatabase().getDateTimeFormat() fieldValue = StringToDate(fieldValue, format) return fieldValue
def getFieldValue(self, form, doc=None, editmode_obsolete=False, creation=False, request=None): """Get date time field value""" fieldValue = BaseField.getFieldValue( self, form, doc, editmode_obsolete, creation, request) mode = self.context.field_mode if (mode == "EDITABLE" and request and ((doc is None and not(creation)) or 'Plomino_datagrid_rowdata' in request)): fieldname = self.context.id fieldValue = request.get(fieldname, fieldValue) if fieldValue and isinstance(fieldValue, basestring): fmt = self.format if not fmt: fmt = form.getParentDatabase().datetime_format fieldValue = StringToDate(fieldValue, fmt) return fieldValue
def getFieldValue(self, form, doc=None, editmode_obsolete=False, creation=False, request=None): """ """ fieldValue = BaseField.getFieldValue( self, form, doc, editmode_obsolete, creation, request) if not fieldValue: return fieldValue # if doc is not a PlominoDocument, no processing needed if not doc: return fieldValue rawValue = fieldValue or [] mapped_fields = [] if self.context.field_mapping: mapped_fields = [ f.strip() for f in self.context.field_mapping.split(',')] # item names is set by `PlominoForm.createDocument` item_names = doc.getItem(self.context.id + '_itemnames') if mapped_fields: if not item_names: item_names = mapped_fields # fieldValue is a array, where we must replace raw values with # rendered values child_form_id = self.context.associated_form if child_form_id: db = self.context.getParentDatabase() child_form = db.getForm(child_form_id) # zip is procrustean: we get the longest of mapped_fields or # fieldValue mapped = [] for row in fieldValue: if len(row) < len(item_names): row = (row + [''] * (len(item_names) - len(row))) row = dict(zip(item_names, row)) mapped.append(row) fieldValue = mapped fields = {} for f in mapped_fields + item_names: fields[f] = None fields = fields.keys() field_objs = [child_form.getFormField(f) for f in fields] # avoid bad field ids field_objs = [f for f in field_objs if f is not None] fields_to_render = [f.id for f in field_objs if f.field_mode in ["DISPLAY", ] or f.field_type not in ["TEXT", "RICHTEXT"]] if fields_to_render: rendered_values = [] for row in fieldValue: row['Form'] = child_form_id row['Plomino_Parent_Document'] = doc.id # We want a new TemporaryDocument for every row tmp = TemporaryDocument( db, child_form, row, real_doc=doc) tmp = tmp.__of__(db) for f in fields: if f in fields_to_render: row[f] = tmp.getRenderedItem(f) rendered_values.append(row) fieldValue = rendered_values if mapped_fields and child_form_id: mapped = [] for row in fieldValue: mapped.append([row[c] for c in mapped_fields]) fieldValue = mapped return {'rawdata': rawValue, 'rendered': fieldValue}
def lookup_member(self, member_name): return BaseField(db_field=member_name)