def migrate_saved_data(ploneformgen, easyform): for data_adapter in ploneformgen.objectValues('FormSaveDataAdapter'): actions = get_actions(easyform) action = actions.get(data_adapter.getId()) schema = get_schema(easyform) if ISaveData.providedBy(action): cols = data_adapter.getColumnNames() for idx, row in enumerate(data_adapter.getSavedFormInput()): if len(row) != len(cols): logger.warning( 'Number of columns does not match. Skipping row %s in ' 'data adapter %s/%s', idx, '/'.join(easyform.getPhysicalPath()), data_adapter.getId()) continue data = {} for key, value in zip(cols, row): field = schema.get(key) value = value.decode('utf8') if IFromUnicode.providedBy(field): value = field.fromUnicode(value) elif IDatetime.providedBy(field) and value: value = DateTime(value).asdatetime() elif IDate.providedBy(field) and value: value = DateTime(value).asdatetime().date() elif ISet.providedBy(field): try: value = set(literal_eval(value)) except ValueError: pass elif INamedBlobFileField.providedBy(field): value = None data[key] = value action.addDataRow(data)
def testGetSaveDataAdaptersView(self): ''' test the @@get_save_data_adapters view ''' self.createSaver() view = self.ff1.restrictedTraverse('@@get_save_data_adapters') results = view() self.assertEqual(len(results), 1) saver = results[0] self.assertTrue(ISaveData.providedBy(saver))
def __call__(self, *args, **kwargs): """return all contained save data adapters""" view = EasyFormForm(self.context, self.request) form = view.context adapters = [] actions = get_actions(form) for action_id in actions: action = actions[action_id] if ISaveData.providedBy(action): adapters.append(action) return adapters
def items(self): items = [ (name, action.__doc__) for name, action in getFieldsInOrder(get_actions(self.context)) if ISaveData.providedBy(action) ] if len(items) == 1: url = "{0}/actions/{1}/@@data".format( self.context.absolute_url(), items[0][0], ) self.request.response.redirect(url) return items
def __init__(self, **kw): for i, f in ISaveData.namesAndDescriptions(): setattr(self, i, kw.pop(i, f.default)) super(SaveData, self).__init__(**kw)
def items(self): return [ (name, action.__doc__) for name, action in getFieldsInOrder(get_actions(self.context)) if ISaveData.providedBy(action) ]
def items(self): return [(name, action.__doc__) for name, action in getFieldsInOrder(get_actions(self.context)) if ISaveData.providedBy(action)]