Exemplo n.º 1
0
	def get(self):
	        self.response.headers['Content-Type'] = 'application/json'
		user = User.get_by_username(self.request.get('username'))
		organization = Organization.get_by_key(self.request.get('organization'))
		organizationUser = OrganizationUser()
		organizationUser.user = user.key
		organizationUser.organization = organization.key
		organizationUser.put()

		self.response.write(json.dumps({'status': 0, 'message': 'El usuario %s fue agregado a la escuela %s.' % (user.first_name + ' ' + user.last_name, organization.name), 'organization': {'key': organization.key.urlsafe(), 'name': organization.name, 'address1': organization.address1, 'address2': organization.address2, 'zipcode': organization.zipcode, 'state': organization.state, 'country': organization.country, 'notes': organization.notes}, 'user': {'key': user.key.urlsafe(), 'first_name': user.first_name, 'last_name': user.last_name}}))
Exemplo n.º 2
0
	def get(self):
	        self.response.headers['Content-Type'] = 'application/json'
		key = ndb.Key(urlsafe = self.request.get('entity'))

		if key.kind() == 'Organization':
			entity = Organization.get_by_key(key.urlsafe())
		elif key.kind() == 'OU':
			entity = OU.get_by_key(key.urlsafe())
		elif key.kind() == 'CN':
			entity = CN.get_by_key(key.urlsafe())
		logging.warning('DEBUG OrganizationTree - key.kind(): %s' % key.kind())

		if key.kind() in ['Organization', 'OU']:
			name = entity.name
		else:
			name = entity.first_name + ' ' + entity.last_name

		treedict = {'key': entity.key.urlsafe(), 'name': name, 'kind': key.kind()}

		level = treedict

		# Ascending tree
		while key.kind() != 'Organization':
			parent = entity.parent
			if parent.kind() == 'Organization':
				entity = Organization.query(Organization.key == parent).get()
			else:
				entity = OU.query(OU.key == parent).get()
			key = entity.key

			logging.warning('DEBUG OrganizationTree - parent: %s - entity: %s' % (parent, str(entity)))
			entitydict = {'key': entity.key.urlsafe(), 'name': entity.name, 'kind': parent.kind()}
			level['parent'] = entitydict
			level = level['parent']

		children = []
		ouchildren = OU.query(OU.parent == key).fetch()
		for ouchild in ouchildren:
			oudict = {'key': ouchild.key.urlsafe(), 'name': ouchild.name, 'kind': ouchild.key.kind()}
			children.append(oudict)
		cnchildren = CN.query(CN.parent == key).fetch()
		for cnchild in cnchildren:
			cndict = {'key': cnchild.key.urlsafe(), 'name': cnchild.first_name + ' ' + cnchild.last_name, 'kind': cnchild.key.kind()}
			children.append(cndict)

		treedict['child'] = pop_list(treedict)

		self.response.write(json.dumps(treedict))
Exemplo n.º 3
0
	def get(self):
	        self.response.headers['Content-Type'] = 'application/json'

		user = User.get_by_username(self.request.get('username'))
		organizationUser = OrganizationUser.fetch_organizations_by_user(user.key)

		organizationlist = []
		for organizationU in organizationUser:
			organization = Organization.get_by_key(organizationU.organization.urlsafe())

			# Fix the issue if an organization's owner is not defined
			if organization.owner is None:
				organization.owner = user.key
				organization.put()

			organizationdict = {'status': 0, 'message': 'Organization list.', 'organization': {'key': organization.key.urlsafe(), 'owner': organization.owner.urlsafe(), 'name': organization.name, 'address1': organization.address1, 'address2': organization.address2, 'zipcode': organization.zipcode, 'state': organization.state, 'country': organization.country, 'notes': organization.notes}}
			organizationlist.append(organizationdict)
		self.response.write(json.dumps(organizationlist))
Exemplo n.º 4
0
    def get(self):
        self.response.headers['Content-Type'] = 'application/json'

	user = User.get_by_username(self.request.get('username'))
	new = False
	if len(self.request.get('organization')) > 0:
		organization = Organization.get_by_key(self.request.get('organization'))
	else:
		new = True
		organization = Organization()
		organization.owner = user.key

	if new or len(self.request.get('name')) > 0:
		organization.name = self.request.get('name')
	if new or len(self.request.get('owner')) > 0:
		organization.owner = self.request.get('owner')
	if new or len(self.request.get('address1')) > 0:
		organization.address1 = self.request.get('address1')
	if new or len(self.request.get('address2')) > 0:
		organization.address2 = self.request.get('address2')
	if new or len(self.request.get('city')) > 0:
		organization.city = self.request.get('city')
	if new or len(self.request.get('zipcode')) > 0:
		organization.zipcode = self.request.get('zipcode')
	if new or len(self.request.get('state')) > 0:
		organization.state = self.request.get('state')
	if new or len(self.request.get('country')) > 0:
		organization.country = self.request.get('country')
	if new or len(self.request.get('phone')) > 0:
		organization.phone = self.request.get('phone')
	if new or len(self.request.get('notes')) > 0:
		organization.notes = self.request.get('notes')
	organization.put()

	if OrganizationUser.get_combo(user.key, organization.key) is None:
		organizationUser = OrganizationUser()
		organizationUser.user = user.key
		organizationUser.organization = organization.key
		organizationUser.put()

	self.response.write(json.dumps({'status': 0, 'message': 'La escuela fue agregada/modificada.', 'organization': {'key': organization.key.urlsafe(), 'name': organization.name, 'address1': organization.address1, 'address2': organization.address2, 'zipcode': organization.zipcode, 'state': organization.state, 'country': organization.country, 'notes': organization.notes}}))