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))