def getProperModelList(self, pagetype):
		if (pagetype == 'people'):
			return Person.all()
		elif (pagetype == 'organizations'):
			return Organization.all()
		elif (pagetype == 'crises'):
			return Crisis.all()	
	def getProperModelByKey(self,pagetype, link):
		if (pagetype == "person-refs"):
			return Person.get(link)
		elif (pagetype == "organization-refs"):
			return Organization.get(link)
		else:
			return Crisis.get(link)
	def test_getProperList2(self):
		pagetype = "organization-refs"
		key = db.get(db.Key.from_path("Organization","nyfd")).key()
		model = self.handler.getProperModelByKey(pagetype, key)
		pagetype = "crisis-refs"
		
		keys = self.handler.getProperList(pagetype, model)
		someModel = Crisis.get(keys[0])
		
		self.assert_(someModel != None)
		self.assert_(someModel.city == "New York")
	def processPageTypes(self, pagetype, mainTag):
		linkTypes = {"people":["crisis-refs", "organization-refs"], "organizations":[ "crisis-refs", "person-refs"], "crises":["organization-refs", "person-refs"]}
		pageType = SubElement(mainTag, pagetype)
		tags = []
		childType = ""
		if (pagetype == "people"):
			tags = Person.all()
			childType = "person"
		elif (pagetype == "organizations"):
			tags = Organization.all()
			childType = "organization"
		else:
			#print pagetype
			tags = Crisis.all()
			childType = "crisis"
	    	
		for t in tags:
		
			# element instantiation and unique id
			child = SubElement(pageType, childType)
			child.attrib['id'] = t.key().name()
		
			# general info block
			name = SubElement(child, 'name')
			name.text = str(t.name)
			
			if t.alternate_names != None :
				alternate_names = SubElement(child, 'alternate-names')
				alternate_names.text = t.alternate_names
				
			category = SubElement(child, 'kind')
			category.text = t.category
			description = SubElement(child, 'description')
			description.text = t.description
			
			
			# location block
			location = SubElement(child, 'location')
			if t.city != None :
				city = SubElement(location, 'city')
				city.text = str(t.city)
			if t.state != None :
				state = SubElement(location, 'state')
				state.text = str(t.state)
			country = SubElement(location, 'country')
			country.text = str(t.country)

			if t.latitude != None:
				latitude = SubElement(location, 'latitude')
				latitude.text = str(t.latitude)
			if (t.latitude != None):
				longitude = SubElement(location, 'longitude')
				longitude.text = str(t.longitude)
			# image block
			if t.image_source != None :
				images = SubElement(child, "images")
				c = 0
				for l in t.image_source :
					image = SubElement(images, "image")
					image_source = SubElement(image, 'source')
					image_source.text = str(l)
					i = 0
					for k in t.image_description :
						if i == c :
							image_description = SubElement(image, 'description')
							image_description.text = str(k)
						i += 1
					c += 1
			
			
			# map block
			if t.map_source != None :
				maps = SubElement(child, "maps")
				c = 0
				for l in t.map_source :
					map = SubElement(maps, "map")
					map_source = SubElement(map, 'source')
					map_source.text = str(l)
					i = 0
					for k in t.map_description :
						if i == c :
							map_description = SubElement(map, 'description')
							map_description.text = str(k)
						i += 1
					c += 1
			
			
			# videos block
			if t.videos_youtube != None or t.videos_vimeo != None:
				videos = SubElement(child, "videos")
				if t.videos_youtube != None :
					for l in t.videos_youtube :
						youtube = SubElement(videos, "youtube")
						youtube.text = str(l)
				
				if t.videos_vimeo != None :
					for l in t.videos_vimeo :
						vimeo = SubElement(videos, 'vimeo')
						vimeo.text = str(l)
			
				
			# social block
			if t.social_youtube != None or t.social_facebook != None or t.social_twitter != None:
				social = SubElement(child, "social")
				
				if t.social_facebook != None :
					for l in t.social_facebook :
						social_facebook = SubElement(social, 'facebook')
						social_facebook.text = str(l)
						
				if t.social_twitter != None :
					for l in t.social_twitter :
						social_twitter = SubElement(social, 'twitter')
						social_twitter.text = str(l)
				
				if t.social_youtube != None :
					for l in t.social_youtube :
						social_youtube = SubElement(social, 'youtube')
						social_youtube.text = str(l)
			
				
			# citation block
			if t.citation_source != None :
				citations = SubElement(child, "citations")
				c = 0
				for l in t.citation_source :
					citation = SubElement(citations, "citation")
					citation_source = SubElement(citation, 'source')
					citation_source.text = str(l)
					i = 0
					for k in t.citation_description :
						if i == c :
							citation_description = SubElement(citation, 'description')
							citation_description.text = k
						i += 1
					c += 1
			
			
			# external block
			if t.external_link_source != None :
				external_links = SubElement(child, "external-links")
				c = 0
				for l in t.external_link_source :
					external_link = SubElement(external_links, "external-link")
					external_link_source = SubElement(external_link, 'source')
					external_link_source.text = str(l)
					i = 0
					for k in t.external_link_description :
						if i == c :
							external_link_description = SubElement(external_link, 'description')
							external_link_description.text = k
						i += 1
					c += 1
			
			
			# individual details
			if (pagetype == "crises"):
				self.crisis_details(child, t)
			if (pagetype == "organizations"):
				self.organization_details(child, t)

			# id ref links
			for someLink in linkTypes[pagetype]:
				properLinkList = self.getProperList(someLink, t)
#				if ("Copiapo" in t.name and someLink == 'person-refs'):
#					print properLinkList
#					assert False
				if properLinkList != None and len(properLinkList) > 0:
					linkTag = SubElement(child, someLink)
					linkTag.text = ""
					for l in properLinkList :
				   		someLinkModel = self.getProperModelByKey(someLink, l)#Organization.get(l)
				   		linkTag.text += " " + str(someLinkModel.key().name())