def upsert_author(info): with db_session: a = Author.get(author_id=info['author_id']) if a: logger.debug('author has existed, author_id=%s', info['author_id']) return # logger.debug(info) author = Author(author_id=info['author_id']) author.name = info['name'] if info['name'] else '' author.image_url = info['image_url'] if info['image_url'] else '' author.organization = info['organization'] if info[ 'organization'] else '' author.home_page = info['home_page'] if info['home_page'] else '' author.paper_count = info['paper_count'] author.citied_count = info['cited_count'] for d in info['domains']: if d['id'] == '': continue ds = Domain.get(domain_id=d['id']) if ds: author.domains.add(ds) else: domain = Domain(domain_id=d['id']) domain.name = d['name'] author.domains.add(domain)
def _getFields(self, xml): if xml.nodeName != "table": raise ValueError("Is not a table") fields = [] for field in xml.getElementsByTagName("field"): tmp = Field() domain = Domain() for attributeName, attributeValue in field.attributes.items(): if attributeName.lower() == "name": tmp.name = attributeValue elif attributeName.lower() == "rname": tmp.rname = attributeValue elif attributeName == "domain": tmp.domain = attributeValue elif attributeName.lower() == "domain.name": domain.name = attributeValue elif attributeName.lower() == "domain.char_length": domain.char_length = attributeValue elif attributeName.lower() == "domain.precision": domain.precision = attributeValue elif attributeName.lower() == "domain.scale": domain.scale = attributeValue elif attributeName.lower() == "domain.type": domain.type = attributeValue elif attributeName.lower() == "description": tmp.description = attributeValue elif attributeName.lower() == "props": for prop in attributeValue.split(", "): if prop == "input": tmp.input = True elif prop == "edit": tmp.edit = True elif prop == "show_in_grid": tmp.show_in_grid = True elif prop == "show_in_details": tmp.show_in_details = True elif prop == "is_mean": tmp.is_mean = True elif prop == "autocalculated": tmp.autocalculated = True elif prop == "required": tmp.required = True else: raise ValueError( "Invalid format of props string: {}".format( attributeValue)) else: raise ValueError( "Incorrect attribute name \"{}\" in tag \"{}\" ". format(attributeName, field.nodeName)) if tmp.domain is None: tmp.domain = domain fields.append(tmp) return fields
def _getDomains(self): domains = [] for domain in self.xml.getElementsByTagName("domain"): tmp = Domain() for attributeName, attributeValue in domain.attributes.items(): if attributeName.lower() == "name": tmp.name = attributeValue elif attributeName.lower() == "description": tmp.description = attributeValue elif attributeName.lower() == "type": tmp.type = attributeValue tmp.type_id = postgres_utils.get_type_in_postgres(tmp) elif attributeName.lower() == "align": tmp.align = attributeValue elif attributeName.lower() == "width": tmp.width = attributeValue elif attributeName.lower() == "precision": tmp.precision = attributeValue elif attributeName.lower() == "props": for prop in attributeValue.split(", "): if prop == "show_null": tmp.show_null = True elif prop == "summable": tmp.summable = True elif prop == "case_sensitive": tmp.case_sensitive = True elif prop == "show_lead_nulls": tmp.show_lead_nulls = True elif prop == "thousands_separator": tmp.thousands_separator = True else: raise ValueError( "Invalid format of props string: {}".format( attributeValue)) elif attributeName.lower() == "char_length": tmp.char_length = attributeValue elif attributeName.lower() == "length": tmp.length = attributeValue elif attributeName.lower() == "scale": tmp.scale = attributeValue else: raise ValueError( "Incorrect attribute name \"{}\" in tag \"{}\" ". format(attributeName, domain.nodeName)) domains.append(tmp) return domains
def test_creating_new_domains(self): domain = Domain() domain.id = 42 domain.name = "Test VM" domain.state = domain.RUNNING domain.max_memory = 2*2024*2024 domain.memory = domain.max_memory domain.vcpu = 1 domain.save() all_domains_in_database = Domain.objects.all() self.assertEquals(len(all_domains_in_database), 1) only_domain_in_database = all_domains_in_database[0] self.assertEquals(only_domain_in_database, domain) self.assertEquals(only_domain_in_database.name, "Test VM")
def get_or_create_domain(domain_string): """ check in the instance of the specific domain is saved . If yes return an instance of domain, if not save an instance and return it Params domain_string - the domain name (ex. facebook.com): string Return an instance of domain object : Domain """ domain = db.Query(Domain).filter('name = ', domain_string).get() if not domain: domain = Domain() domain.name = domain_string db.put(domain) return domain