def post(self): key_id = self.request.get('key_id') vcode = self.request.get('vcode') rcpt_char = self.request.get('rcpt_char') rcpt_org = self.request.get('rcpt_org') rcpt_org2 = self.request.get('rcpt_org2') dest_email = self.request.get('dest_email') if not (key_id and vcode and rcpt_org and dest_email): self.response.out.write("Missing one or more fields.") return try: key_id = int(key_id) except (ValueError, TypeError): self.response.out.write("Key ID must be an integer.") return try: rcpt_char = int(rcpt_char) except (ValueError, TypeError): rcpt_char = self.get_entity_id(rcpt_char) try: rcpt_org = int(rcpt_org) except (ValueError, TypeError): rcpt_org = self.get_entity_id(rcpt_org) if not rcpt_org: self.response.out.write("Invalid organization name/id.") return if rcpt_org2: try: rcpt_org2 = int(rcpt_org2) except (ValueError, TypeError): rcpt_org2 = self.get_entity_id(rcpt_org2) if not rcpt_org2: self.response.out.write("Invalid organization #2 name/id.") return config = Configuration.all().get() if not config: config = Configuration( key_id=key_id, vcode=vcode, rcpt_char=rcpt_char, rcpt_org=rcpt_org, rcpt_org2=rcpt_org2, dest_email=dest_email, ) else: config.key_id = key_id config.vcode = vcode config.rcpt_char = rcpt_char config.rcpt_org = rcpt_org if rcpt_org2: config.rcpt_org2 = rcpt_org2 config.dest_email = dest_email config.put() memcache.set('config', config) self.response.out.write("Configuration saved.") return