示例#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}}))
示例#2
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}}))