def post(self): user_id, user = self.get_user() if not user: self.redirect('/') return title = self.request.get('note-title') text = self.request.get('note-text') dt = datetime.datetime.now() logging.info('%s\n%s\n%s', title, text, dt) if not title or not text: msg = ( 'You must enter a title and some text to create a new note.' ) data = { 'page_title': 'Blank Note', 'user': user, 'error_msg': msg } self.render('error.html', **data) return new_note = Note( user=user.key, submit_date=dt, title=title, text=text, ) new_note.put() self.redirect('/notes')
def get(self): # req_json = json.loads(self.request.body) # user_email = req_json[IDENTIFIER_USER_EMAIL] user_email = self.request.get(IDENTIFIER_USER_EMAIL) # apt_name = req_json[IDENTIFIER_APT_NAME] apt_name = self.request.get(IDENTIFIER_APT_NAME) # description = req_json[IDENTIFIER_DESCRIPTION_NAME] description = self.request.get(IDENTIFIER_DESCRIPTION_NAME) apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() cur_apt = None for apt in apt_lst: if user_email in apt.user_email_lst: cur_apt = apt if cur_apt == None: response = {} response[ 'error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'we dont have notebook for the apt: ' + apt_name return self.respond(**response) cur_note_book = cur_note_book_lst[0] note_id = uuid.uuid4() note = Note(id=str(note_id), description=description, author_email=user_email, notebook_id=cur_note_book_id) cur_note_book.note_id_lst.append(str(note_id)) cur_note_book.put() note.put() self.respond(note_id=str(note_id), notebook_id=cur_note_book_id, status="Success")
def get(self): # req_json = json.loads(self.request.body) # user_email = req_json[IDENTIFIER_USER_EMAIL] user_email = self.request.get(IDENTIFIER_USER_EMAIL) # apt_name = req_json[IDENTIFIER_APT_NAME] apt_name = self.request.get(IDENTIFIER_APT_NAME) # description = req_json[IDENTIFIER_DESCRIPTION_NAME] description = self.request.get(IDENTIFIER_DESCRIPTION_NAME) apt_lst = Apartment.query(Apartment.apt_name == apt_name).fetch() cur_apt = None for apt in apt_lst: if user_email in apt.user_email_lst: cur_apt = apt if cur_apt == None: response = {} response['error'] = 'the apt: ' + apt_name + ' is not available for user: '******'error'] = 'we dont have notebook for the apt: ' + apt_name return self.respond(**response) cur_note_book = cur_note_book_lst[0] note_id = uuid.uuid4() note = Note(id = str(note_id), description = description, author_email = user_email, notebook_id = cur_note_book_id) cur_note_book.note_id_lst.append(str(note_id)) cur_note_book.put() note.put() self.respond(note_id = str(note_id), notebook_id = cur_note_book_id, status="Success")
def _handle_timeline_notification(self, data): """Handle timeline notification.""" for user_action in data.get('userActions', []): if user_action.get('type') == 'LAUNCH': item = self.mirror_service.timeline().get(id=data['itemId']).execute() text = item.get('text') creatorID = data.get('userToken') creatorName = StorageByKeyName(Credentials, creatorID, 'displayName').get() # If the contributor is approved, make the entry public: makePublic = StorageByKeyName(Credentials, creatorID, 'approved').get() newNote = Note(text=text, userId=creatorID, creatorName=creatorName, public=makePublic) newNote.put() logging.info('Reply received: %s' % text) break else: logging.info( "I don't know what to do with this notification: %s", user_action)