def get_default_attributes(self, obj): """Returns the default attributes from the object to keep mapped against the SQL database """ portal_type = api.get_portal_type(obj) if portal_type not in self.get_multiplexed_types(): return [] def is_field_supported(field): if field.getName() in NON_SUPPORTED_FIELD_NAMES: return False if field.type in NON_SUPPORTED_FIELD_TYPES: return False return True # Grab only attributes that make sense! fields = api.get_fields(obj).values() fields = filter(is_field_supported, fields) # Get the ids of the fields to store attrs = map(lambda f: f.getName(), fields) if not attrs: return [] # Always keep the UID if "UID" not in attrs: attrs.append("UID") return attrs
def _extractFields(self, context): fragment = self._doc.createDocumentFragment() fields = api.get_fields(context) for name, field in fields.items(): # query the field adapter exporter = queryMultiAdapter((context, field, self.environ), INode) if not exporter: continue node = exporter.node if node is not None: fragment.appendChild(node) return fragment
def fields_to_dict(obj, skip_fields=None): """ Generates a dictionary with the field values of the object passed in, where keys are the field names. Skips computed fields """ data = {} obj = api.get_object(obj) for field_name, field in api.get_fields(obj).items(): if skip_fields and field_name in skip_fields: continue if field.type == "computed": continue data[field_name] = field.get(obj) return data
def _initFields(self, context, node): fields = api.get_fields(context) for child in node.childNodes: # we only handle filed nodes if child.nodeName != "field": continue name = child.getAttribute("name") field = fields.get(name) if field is None: self._logger.warning("Unrecognized field '{}'".format(name)) continue importer = queryMultiAdapter((context, field, self.environ), INode) if importer: importer.node = child
def widgets(self, mode=DISPLAY_MODE): """Return the widgets for the databox # https://stackoverflow.com/questions/8476781/how-to-access-z3c-form-widget-settings-from-browser-view """ widgets = [] fields = api.get_fields(self.context) for name, field in fields.items(): widget = getMultiAdapter((field, self.request), IFieldWidget) widget.mode = mode widget.context = self.context converter = IDataConverter(widget) value = field.get(self.context) widget.value = converter.toWidgetValue(value) widget.update() widgets.append(widget) return widgets
def create_partition(self, primary_uid, sampletype_uid, analyses_uids): """Create a new partition (AR) """ logger.info("*** CREATE PARTITION ***") ar = self.get_object_by_uid(primary_uid) sample = ar.getSample() record = { "PrimarySample": api.get_uid(sample), "InternalUse": True, "PrimaryAnalysisRequest": primary_uid, "SampleType": sampletype_uid, } for fieldname, field in api.get_fields(ar).items(): # if self.is_proxy_field(field): # logger.info("Skipping proxy field {}".format(fieldname)) # continue if self.is_computed_field(field): logger.info("Skipping computed field {}".format(fieldname)) continue if fieldname in PARTITION_SKIP_FIELDS: logger.info("Skipping field {}".format(fieldname)) continue fieldvalue = field.get(ar) record[fieldname] = fieldvalue logger.info("Update record '{}': {}".format( fieldname, repr(fieldvalue))) client = ar.getClient() # se assume to have analyses = map(self.get_object_by_uid, analyses_uids) services = map(lambda an: an.getAnalysisService(), analyses) ar = crar( client, self.request, record, analyses=services, specifications=self.get_specifications_for(ar) ) ar.Schema().getField("InternalUse").set(ar, True) return ar
def get_fields(self, portal_type=None): """Returns all schema fields of the selected query type IMPORTANT: Do not call from within `__init__` due to permissions """ obj = self._create_temporary_object(portal_type=portal_type) if obj is None: return [] fields = api.get_fields(obj) # drop ignored fields for field in IGNORE_FIELDS: fields.pop(field, None) # Inject Parent Field portal_type = api.get_portal_type(obj) parent_type = PARENT_TYPES.get(portal_type) if parent_type: field = ParentField(portal_type=parent_type) fields["Parent"] = field return fields
def create_partition(self, primary_uid, sampletype_uid, analyses_uids): """Create a new partition (AR) """ logger.info("*** CREATE PARTITION ***") ar = self.get_object_by_uid(primary_uid) record = { "InternalUse": True, "ParentAnalysisRequest": primary_uid, "SampleType": sampletype_uid, } for fieldname, field in api.get_fields(ar).items(): # if self.is_proxy_field(field): # logger.info("Skipping proxy field {}".format(fieldname)) # continue if self.is_computed_field(field): logger.info("Skipping computed field {}".format(fieldname)) continue if fieldname in PARTITION_SKIP_FIELDS: logger.info("Skipping field {}".format(fieldname)) continue fieldvalue = field.get(ar) record[fieldname] = fieldvalue logger.info("Update record '{}': {}".format( fieldname, repr(fieldvalue))) client = ar.getClient() analyses = map(self.get_object_by_uid, analyses_uids) services = map(lambda an: an.getAnalysisService(), analyses) partition = crar(client, self.request, record, analyses=services, specifications=self.get_specifications_for(ar)) # Reindex Parent Analysis Request # TODO Workflow - AnalysisRequest - Partitions creation ar.reindexObject(idxs=["isRootAncestor"]) return partition
def keys(self): fields = api.get_fields(self.instance).keys() return filter(lambda f: not f.startswith("_"), fields)