def validate_headers(self, workbook, skip_resourceid_col=False, resource_type=None): if resource_type != 'relations': q = Entity().get_mapping_schema(resource_type) result = {'success': True, 'errors': []} for sheet in workbook.worksheets: if sheet.title == 'RELATIONS': restypenodes = RELATION_HEADER else: restypenodes = set(q.keys()) for header in sheet.iter_cols(max_row=1): nodename = header[0].value if nodename is not None: if skip_resourceid_col == True and header[ 0].value == 'RESOURCEID': continue if not nodename in restypenodes: msg = "{} is not a valid {} node name".format( nodename, resource_type) result['errors'].append(msg) if result['errors']: result['success'] = False return result
def test_form_classes(self): print "\n\n==== TESTING ALL FORM CLASSES ====" # These are considered exceptions because they are often included # in a resource type but actually enter data for a different resource # type. So they will throw errors below, even if they are valid. form_exceptions = [ 'man-made', 'man-made-component', 'related-files', 'related-resources', 'file-upload' ] for restype in sorted(settings.RESOURCE_TYPE_CONFIGS()): print "\n\n--- {} FORMS ---".format(restype) q = Entity().get_mapping_schema(restype) restypenodes = set(q.keys()) res = Resource({"entitytypeid": restype}) for group in res.form_groups: for form in group['forms']: invalid_nodes = [] fclass = form['class'] formid = fclass.get_info()['id'] if formid in form_exceptions: continue print "\nFORM:", formid template_errors = self.test_template(formid, restypenodes) print "{} invalid node{} in the template".format( len(template_errors), "s" if len(template_errors) != 1 else "") if len(template_errors) > 0: print " ", template_errors a = res.get_form(formid) try: a.load("en-US") except Exception as e: print "ERROR LOADING THIS FORMS.PY CLASS" print traceback.print_exc() continue for key in a.data: if not key in restypenodes and "." in key: invalid_nodes.append(key) domains = a.data[key].get('domains', []) for domainnode in domains: if not domainnode in restypenodes: invalid_nodes.append(domainnode) print "{} invalid node{} in the forms.py class".format( len(invalid_nodes), "s" if len(invalid_nodes) != 1 else "") if len(invalid_nodes) > 0: print " ", invalid_nodes
def make_full_value_lookup(self, restype): q = Entity().get_mapping_schema(restype) restypenodes = set(q.keys()) outdict = {} for node_name in restypenodes: node_obj = EntityTypes.objects.get(pk=node_name) if node_obj.businesstablename == "domains": outdict[node_name] = self.get_label_lookup( node_obj.conceptid_id, return_entity=True) with open("full_label_lookup.json", 'wb') as out: json.dump(outdict, out, indent=1) return outdict