def post(self): self.response.headers['Content-Type'] = 'text/plain; charset=utf-8' user = User() try: jsonUser = json.loads(self.request.body) user.parse(jsonUser) if user.isValid(): if user.isUnique(): user.created = datetime.today() user.save() # Save user in db! self.response.write('You are created!\n') else: self.response.write('We know you already.\n') # Trying to add notification ids. loaded_user = user.loadme() loaded_user_changed = False for reg_id in user.registration_ids: if reg_id not in loaded_user.registration_ids: loaded_user.registration_ids.append(reg_id) loaded_user_changed = True if loaded_user_changed: loaded_user.save() self.response.write('We updated your person.\n') self.response.write('Success!\n') else: self.response.write('Failed!\n') self.response.write('User not valid.\n') self.response.write(user.hash) self.response.write(user.type) except Exception, e: self.response.write('Failed!\n') self.response.write(e)
def post(self): eid = self.request.get('id', default_value='') self.response.write('<h1>'+eid+'</h1>') key = self.request.get('key', default_value='') if eid is not None and eid != '': msg = Message.get_by_id(int(eid)) elif key is not None and key != '': msg = ndb.Key(urlsafe=key).get() else: self.err('Neither id or key is passed!\n') return if msg is None: self.err('Loading message failed!\n') return # Send to phone notification! usr = User() usr.hash = msg.recipient usr = usr.loadme() if usr is None: self.err('User-Recipient not found!'); return data = {'type': 'message', 'sender': msg.sender} notfication = GCM('AIzaSyD-z2JuoBkD51RyRHG6ULoWX2gE84apP7M') response = notfication.json_request(registration_ids=usr.registration_ids, data=data, collapse_key=None, delay_while_idle=False, time_to_live=None, retries=5) self.response.headers['Content-Type'] = 'application/json; charset=utf-8' self.debug(response) # Mark message as pushed. msg.pushed = datetime.now() msg.put()