예제 #1
0
def populate_crisis(root):
    """
	Finds instances of Crisis in root's tree and saves them to the database

	@type root:  Element
	@param root: root of the ElementTree passed in to populate_models()
	@rtype:      N/A
	@return:     function does not return
	"""
    for crisis in root.findall("Crisis"):
        temp_crisis = Crisis()
        temp_crisis.crisis_ID = crisis.get("ID")
        temp_crisis.name = crisis.get("Name")

        if crisis.find("Kind") is not None:
            temp_crisis.kind = crisis.find("Kind").text
        if crisis.find("Date") is not None:
            temp_crisis.date = crisis.find("Date").text
        if crisis.find("Time") is not None:
            temp_crisis.time = crisis.find("Time").text
        #populating people
        for person in crisis.iter("Person") or []:
            temp_relations = Relations()
            check = Relations.objects.filter(crisis_ID=crisis.get("ID"),
                                             person_ID=person.get("ID"))
            if len(check) == 0:
                temp_relations.populate(c_id=crisis.get("ID"),
                                        p_id=person.get("ID"))
                temp_relations.save()
        #populating organizations
        for org in crisis.iter("Org") or []:
            temp_relations = Relations()
            check = Relations.objects.filter(crisis_ID=crisis.get("ID"),
                                             org_ID=org.get("ID"))
            if len(check) == 0:
                temp_relations.populate(c_id=crisis.get("ID"),
                                        o_id=org.get("ID"))
                temp_relations.save()

        populate_li(crisis, crisis.get("ID"), "Locations")
        populate_li(crisis, crisis.get("ID"), "HumanImpact")
        populate_li(crisis, crisis.get("ID"), "EconomicImpact")
        populate_li(crisis, crisis.get("ID"), "ResourcesNeeded")
        populate_li(crisis, crisis.get("ID"), "WaysToHelp")

        populate_common(crisis, crisis.get("ID"), temp_crisis)
        temp_crisis.save()
예제 #2
0
def populate_crisis(root) :
	"""
	Finds instances of Crisis in root's tree and saves them to the database

	@type root:  Element
	@param root: root of the ElementTree passed in to populate_models()
	@rtype:      N/A
	@return:     function does not return
	"""
	for crisis in root.findall("Crisis"):
		temp_crisis           =                 Crisis()
		temp_crisis.crisis_ID =         crisis.get("ID")
		temp_crisis.name      =       crisis.get("Name")
		
		if crisis.find("Kind") is not None :
			temp_crisis.kind      = crisis.find("Kind").text
		if crisis.find("Date") is not None :
			temp_crisis.date      = crisis.find("Date").text
		if crisis.find("Time") is not None :
			temp_crisis.time      = crisis.find("Time").text
		#populating people
		for person in crisis.iter("Person") or [] :
			temp_relations = Relations()
			check = Relations.objects.filter(crisis_ID = crisis.get("ID"), person_ID = person.get("ID"))
			if len(check) == 0:
				temp_relations.populate(c_id = crisis.get("ID"), p_id = person.get("ID"))
				temp_relations.save()
		#populating organizations
		for org in crisis.iter("Org") or [] :
			temp_relations = Relations()
			check = Relations.objects.filter(crisis_ID = crisis.get("ID"), org_ID = org.get("ID"))
			if len(check) == 0:
				temp_relations.populate(c_id = crisis.get("ID"), o_id = org.get("ID"))
				temp_relations.save()

		populate_li(crisis, crisis.get("ID"), "Locations")
		populate_li(crisis, crisis.get("ID"), "HumanImpact")
		populate_li(crisis, crisis.get("ID"), "EconomicImpact")
		populate_li(crisis, crisis.get("ID"), "ResourcesNeeded")
		populate_li(crisis, crisis.get("ID"), "WaysToHelp")

		populate_common(crisis, crisis.get("ID"), temp_crisis)
		temp_crisis.save()
예제 #3
0
def populate_org(root):
    """
	Finds instances of Org in root's tree and saves them to the database

	@type root:  Element
	@param root: root of the ElementTree passed in to populate_models()
	@rtype:      N/A
	@return:     function does not return
	"""
    for org in root.findall("Organization"):
        temp_org = Org()
        temp_org.org_ID = org.get("ID")
        temp_org.name = org.get("Name")
        if org.find("Kind") is not None:
            temp_org.kind = org.find("Kind").text
        if org.find("Location") is not None:
            temp_org.location = org.find("Location").text

        for crisis in org.iter("Crisis"):
            temp_relations = Relations()
            check = Relations.objects.filter(crisis_ID=crisis.get("ID"),
                                             org_ID=org.get("ID"))
            if len(check) == 0:
                temp_relations.populate(c_id=crisis.get("ID"),
                                        o_id=org.get("ID"))
                temp_relations.save()

        for person in org.iter("Person"):
            temp_relations = Relations()
            check = Relations.objects.filter(org_ID=org.get("ID"),
                                             person_ID=person.get("ID"))
            if len(check) == 0:
                temp_relations.populate(p_id=person.get("ID"),
                                        o_id=org.get("ID"))
                temp_relations.save()

        populate_li(org, org.get("ID"), "History")
        populate_li(org, org.get("ID"), "ContactInfo")

        populate_common(org, org.get("ID"), temp_org)
        temp_org.save()
예제 #4
0
def populate_org(root) :
	"""
	Finds instances of Org in root's tree and saves them to the database

	@type root:  Element
	@param root: root of the ElementTree passed in to populate_models()
	@rtype:      N/A
	@return:     function does not return
	"""
	for org in root.findall("Organization") :
		temp_org          =                     Org()
		temp_org.org_ID   =             org.get("ID")
		temp_org.name     =           org.get("Name")
		if org.find("Kind") is not None :
			temp_org.kind     =     org.find("Kind").text
		if org.find("Location") is not None :
			temp_org.location = org.find("Location").text

		for crisis in org.iter("Crisis") :
			temp_relations = Relations()
			check = Relations.objects.filter(crisis_ID = crisis.get("ID"), org_ID = org.get("ID"))
			if len(check) == 0:
				temp_relations.populate(c_id = crisis.get("ID"), o_id = org.get("ID"))
				temp_relations.save()

		for person in org.iter("Person") :
			temp_relations = Relations()
			check = Relations.objects.filter(org_ID = org.get("ID"), person_ID = person.get("ID"))
			if len(check) == 0:
				temp_relations.populate(p_id = person.get("ID"), o_id = org.get("ID"))
				temp_relations.save()

		populate_li(org, org.get("ID"), "History")
		populate_li(org, org.get("ID"), "ContactInfo")

		populate_common(org, org.get("ID"), temp_org)
		temp_org.save()