def fillFormFromItem(self): """Automatically fill the form fields using the values from the catalog item fields. """ catalogItem = self._catalogItem for field in catalogItem.__class__: fieldName = field.name fieldValue = catalogItem[field] widget = getattr(self, fieldName, None) if widget: forms.setValue(widget, fieldValue)
def onSave(self): """Called when save button is pressed. """ catalogItem = self._catalogItem self.fillItemFromForm() catalogItem.save() # update item id and timestamp on the form idWidget = getattr(self, 'id', None) if idWidget: forms.setValue(idWidget, catalogItem.id) timestampWidget = getattr(self, 'timestamp', None) if timestampWidget: forms.setValue(timestampWidget, catalogItem.timestamp) print('save!')