Beispiel #1
0
	def get(self):
		username = self.request.get('username')
		user = User.get_by_username(username)

		if user is not None:
			userdict = {
				'key': user.key.urlsafe(),
				'username': user.username,
				'email': user.email,
				'first_name': user.first_name,
				'last_name': user.last_name,
				'permissions': json.loads(user.permissions),
				'active': user.active,
				'notes': user.notes,
				'created': tools.datetime_to_str(user.created),
				'organization_creation_allowed': True,
			}
			message = 'Detalles de usuario encontrados.'
			status = 0
		else:
			userdict = {}
			message = 'Detalles de usuario no encontrados.'
			status = 1

	        self.response.headers['Content-Type'] = 'application/json'

		self.response.write(json.dumps({'status': status, 'message': message, 'user': userdict}))
Beispiel #2
0
	def get(self):

		self.response.headers['Content-Type'] = 'application/json'

		new = False
		custom = False
		if len(self.request.get('parent')) > 0:
			custom = True

		if len(self.request.get('operation')) > 0:
			if custom:
				operation = CustomOperation.get_by_key(self.request.get('operation'))
			else:
				operation = Operation.get_by_key(self.request.get('operation'))
			operation.updated = datetime.now()
		else:
			if custom:
				operation = CustomOperation()
				operation.target = ndb.Key(urlsafe = self.request.get('target'))
				operation.parent = ndb.Key(urlsafe = self.request.get('parent'))
				parent = Operation.get_by_key(operation.parent.urlsafe())
				operation.name = parent.name
				operation.target = parent.target
				operation.direction = parent.direction
				operation.amount = parent.amount
				operation.frequency = parent.frequency
				operation.cutoff_date = parent.cutoff_date
			else:
				operation = Operation()
			new = True

		if custom and len(self.request.get('notes')) > 0:
			operation.notes = self.request.get('notes')

		if not custom and new or len(self.request.get('direction')) > 0:
			operation.direction = self.request.get('direction')
		if not custom and new or len(self.request.get('name')) > 0:
			operation.name = self.request.get('name')
		if not custom and new or len(self.request.get('target')) > 0:
			operation.target = ndb.Key(urlsafe = self.request.get('target'))
		if not custom and new or len(self.request.get('amount')) > 0:
			operation.amount = float(self.request.get('amount'))
		if len(self.request.get('frequency')) > 0:
			operation.frequency = self.request.get('frequency')
		if len(self.request.get('delay_raise')) > 0:
			operation.frequency = float(self.request.get('delay_raise'))
		if not custom and new or len(self.request.get('cutoff_date')) > 0:
			daymonth_freq = ['bimonthly', 'yearly']
			cutoff_date = self.request.get('cutoff_date').split(',')
			cutofflist = []
			if operation.frequency in daymonth_freq:
				count  = 0
				cutoffdict = {}
				for cutoff in cutoff_date:
					count += 1
					logging.warning('DEBUG OperationSet - count modulo 2: %i' % (count % 2))
					if count % 2 != 0:
						cutoffdict['day'] = int(cutoff)
						logging.warning('DEBUG OperationSet - cutoffdict: %s' % str(cutoffdict))
					else:
						cutoffdict['month'] = int(cutoff)
						logging.warning('DEBUG OperationSet - cutoffdict: %s' % str(cutoffdict))
						cutofflist.append(cutoffdict)
						cutoffdict = {}
			else:
				for cutoff in cutoff_date:
					cutofflist.append({'day': int(cutoff)})
						
			operation.cutoff_date = json.dumps(cutofflist)

		operation.put()

		if custom:
			operationtype = 'custom'
		else:
			operationtype = 'standard'

		output = {'status': 0, 'message': 'Pago agregado.', 'operation': {'key': operation.key.urlsafe(), 'type': operationtype, 'name': operation.name, 'target': operation.target.urlsafe(), 'amount': operation.amount, 'frequency': operation.frequency, 'cutoff_date': operation.cutoff_date, 'created': tools.datetime_to_str(operation.created), 'updated': tools.datetime_to_str(operation.updated)}}

		logging.warning('DEBUG OperationSet - output: %s' % str(output))
		self.response.write(json.dumps(output))
Beispiel #3
0
	def get(self):
		self.response.headers['Content-Type'] = 'application/json'
		target = self.request.get('target')

		url = '%s%s/api/organization/tree?entity=%s' % (config.PROTOCOL, config.APP_HOSTNAME, target)
		result = urlfetch.fetch(url)
		if result.status_code == 200:
			orgtree = json.loads(result.content)
		else:
			orgtree = None

		logging.warning('DEBUG OperationList - orgtree: %s' % str(orgtree))

		key = ndb.Key(urlsafe = target)
		operationlist = []
		replaced = []
		has_parent = True
		if orgtree is not None:
			while has_parent:
				if key.kind() == 'CN':
					entity = CN.get_by_key(key.urlsafe())
					operations = CustomOperation.fetch_by_target(entity.key.urlsafe())
				if key.kind() == 'OU':
					entity = OU.get_by_key(key.urlsafe())
					operations = Operation.fetch_by_target(entity.key.urlsafe())
				if key.kind() == 'Organization':
					entity = Organization.get_by_key(key.urlsafe())
					operations = Operation.fetch_by_target(entity.key.urlsafe())
					has_parent = False
				
				for operation in operations:
					operationdict = {'key': operation.key.urlsafe(), 'name': operation.name, 'target': operation.target.urlsafe(), 'target_kind': key.kind(), 'direction': operation.direction, 'amount': operation.amount, 'frequency': operation.frequency, 'cutoff_date': json.loads(operation.cutoff_date), 'delay_raise': operation.delay_raise, 'created': tools.datetime_to_str(operation.created), 'updated': tools.datetime_to_str(operation.updated)}

					if key.kind() == 'CN':
						operationdict['parent'] = operation.parent.urlsafe()
						replaced.append(operation.parent.urlsafe())

					operationlist.append(operationdict)

				if has_parent:
					key = entity.parent

		index = 0
		operationlist_clone = operationlist[:]
		for operation in operationlist_clone:
			logging.warning('DEBUG OperationList multidirectional - replaced: %s - operation[key]: %s- in: %s' % (str(replaced), operation['key'], str(operation['key'] in replaced)))
			if operation['key'] in replaced:
				operationlist.pop(index)
			else:
				index += 1
			logging.warning('operationlist(%i) - operationlist_clone(%i)' % (len(operationlist), len(operationlist_clone)))

		if self.request.get('direction') in ['in', 'out']:
			index = 0
			oplist_clone = operationlist[:]
			logging.warning('DEBUG OperationList unidirectional - operationlist(%i): %s' % (len(oplist_clone), str(operationlist)))
			for op in oplist_clone:
				if op['direction'] != self.request.get('direction'):
					operationlist.pop(index)
				else:
					index += 1
				logging.warning('operationlist(%i) - operationlist_clone(%i)' % (len(operationlist), len(oplist_clone)))

		self.response.write(json.dumps(operationlist))
Beispiel #4
0
	def get(self):
		self.response.headers['Content-Type'] = 'application/json'
		target = self.request.get('target')

		deposits = Deposit.fetch_by_target(target)
		depositlist = []
		for deposit in deposits:
			depositdict = {'key': deposit.key.urlsafe(), 'target': deposit.target.urlsafe(), 'method': deposit.method, 'amount': deposit.amount, 'date': tools.datetime_to_str(deposit.date), 'date_unix': time.mktime(deposit.date.timetuple()), 'notes': deposit.notes}
			depositlist.append(depositdict)

		self.response.write(json.dumps(depositlist))
Beispiel #5
0
	def get(self):

		self.response.headers['Content-Type'] = 'application/json'

		new = False
		if len(self.request.get('deposit')) > 0:
			deposit = Deposit.get_by_key(self.request.get('deposit'))
			deposit.updated = datetime.now()
		else:
			deposit = Deposit()
			deposit.target = ndb.Key(urlsafe = self.request.get('target'))
			new = True

		if new or len(self.request.get('amount')) > 0:
			deposit.amount = float(self.request.get('amount'))
		if new or len(self.request.get('method')) > 0:
			deposit.method = self.request.get('method')
		if len(self.request.get('notes')) > 0:
			deposit.notes = self.request.get('notes')

		deposit.put()

		output = {'status': 0, 'message': 'Deposito agregado.', 'deposit': {'key': deposit.key.urlsafe(), 'target': deposit.target.urlsafe(), 'method': deposit.method, 'amount': deposit.amount, 'date': tools.datetime_to_str(deposit.date), 'notes': deposit.notes}}

		logging.warning('DEBUG DepositSet - output: %s' % str(output))
		self.response.write(json.dumps(output))