def content(self): self.creator = None self.num = 1 # don't let this shit to distract you global session self.user = session.get_user() if self.user.posts: # show posts disp = lib.Displayer(self.user.posts, UpdatePostPage.page, UpdatePostPage.ppp) disp.show(author=False, content=False, id_=True) # Number of pages self.num = disp.get_page_amount() lib.print_alert('Number of pages: %s\nCurrent Page: %s' % \ (self.num, UpdatePostPage.page)) if UpdatePostPage.is_typing: print('Type in id of post you want to update:') self.select = -1 ids = [post.id for post in self.user.posts] while 1: try: self.select = int(input(settings.promt)) except ValueError: print("Not an integer!") continue else: if self.select in ids: break else: print('Enter correct id!') continue self.creator = PostCreator() self.creator.create() # allow same name for title self.oldpost = ramdb.get_by_id('posts', self.select) if self.oldpost.title == self.creator.title: errmsg = 'Post with such title already exists!' if self.creator.response.get_message() == errmsg: # forcing to be a valid post self.creator.response['is_valid'] = True else: print('You have not any posts yet!')
def actions_handler(self): action = input(settings.action_promt) if action == '1': if self.creator.response.is_valid(): alrt = 'Post is created!' alerter = session.get_alerter() alerter.schedule_alert(alrt) ramdb.save(self.creator.newpost) return pp.PostPage() else: lib.print_alert(self.creator.response.get_message()) return self.actions_handler() elif action == '2': return pp.PostPage() else: print('Invalid input!') return self.actions_handler()
def content(self): self.num = 1 # don't let this self.select = -1 # distract you global session self.user = session.get_user() if self.user.posts: disp = lib.Displayer(self.user.posts, self.currentpage, self.postsperpage) disp.show(author=False, content=False, id_=True) # Number of pages self.num = disp.get_page_amount() lib.print_alert('Number of pages: %s\nCurrent Page: %s' % \ (self.num, self.currentpage)) if self.is_typing: print('Type in id of post you want to delete:') ids = [post.id for post in self.user.posts] while 1: try: self.select = int(input(settings.promt)) except ValueError: print("Not an integer!") continue else: if self.select in ids: break else: print('Enter correct id!') continue # Warn user print('ID of post you have selected is %d' % self.select) print( 'If you delete this post, you will lose your post forever!' ) else: print('You have not any posts yet!')
def actions_handler(self): action = input(settings.action_promt) if action == '1': UpdatePostPage.is_typing = False if UpdatePostPage.page != 1: UpdatePostPage.page -= 1 return 'UPDATE_POST' elif action == '2': UpdatePostPage.is_typing = False if UpdatePostPage.page != self.num: UpdatePostPage.page += 1 return 'UPDATE_POST' elif action == '3': UpdatePostPage.is_typing = False if self.user.posts: UpdatePostPage.is_typing = True else: print('There is no posts!') return self.actions_handler() return 'UPDATE_POST' elif action == '4': UpdatePostPage.is_typing = False if self.user.posts and self.creator: if self.creator.response.is_valid(): self.oldpost.title = self.creator.get_post().title self.oldpost.content = self.creator.get_post().content alerter = session.get_alerter() alerter.schedule_alert('Post was updated!') return 'POST_PAGE' else: lib.print_alert(self.creator.response.get_message()) return self.actions_handler() print('Nothing to save!') return self.actions_handler() elif action == '5': UpdatePostPage.is_typing = False return 'POST_PAGE' else: print('Invalid input!') return self.actions_handler()
def actions_handler(self): action = input(settings.action_promt) if action == '1': if self.currentpage != 1: self.currentpage -= 1 return up.UpdatePostPage(currentpage=self.currentpage) elif action == '2': if self.currentpage != self.num: self.currentpage += 1 return up.UpdatePostPage(currentpage=self.currentpage) elif action == '3': if self.user.posts: self.is_typing = True else: print('There is no posts!') return self.actions_handler() return up.UpdatePostPage(currentpage=self.currentpage, is_typing=self.is_typing) elif action == '4': if self.user.posts and self.creator: if self.creator.response.is_valid(): ramdb.update(self.creator.get_post(), self.oldpost) alerter = session.get_alerter() alerter.schedule_alert('Post was updated!') return pp.PostPage() else: lib.print_alert(self.creator.response.get_message()) return self.actions_handler() print('Nothing to save!') return self.actions_handler() elif action == '5': return pp.PostPage() else: print('Invalid input!') return self.actions_handler()
def open(self, page_name): print(settings.long_border) page = map_.Map.next_page(page_name) while 1: try: # show alert message (at the top of terminal's space) alerter = session.session.get_alerter() if alerter.has_message(): lib.print_alert(alerter.get_alert()) next_page_name = page.show() system('clear') page = map_.Map.next_page(next_page_name) except exceptions.PageNotCompletedError as e: print(e.message) print('Terminating app...') break # handle it better yo!!! except EOFError: # define a way of terminating!!! print() lib.print_alert('Good bye!') break
def content(self): global session user = session.get_user() lib.print_alert('Showing posts written by %s' % user.username) posts = user.posts posts = posts[::-1] # from new to old # Posts if posts: disp = lib.Displayer(posts, self.currentpage, self.postsperpage) disp.show(author=False) # Number of pages self.num = disp.get_page_amount() lib.print_alert('Number of pages: %s\nCurrent Page: %s' % \ (self.num, self.currentpage)) else: self.num = 1 lib.print_alert('Number of pages: %s\nCurrent Page: %s' % \ (self.num, self.currentpage))
def content(self): # User info global session lib.print_alert('Logged in as %s' % session.get_username()) # Posts posts = session.get_posts() posts = posts[::-1] # show from new to old if posts: disp = lib.Displayer(posts, self.currentpage, self.postsperpage) disp.show() # Number of pages self.num = disp.get_page_amount() lib.print_alert('Number of pages: %s\nCurrent Page: %s' % \ (self.num, self.currentpage)) else: self.num = 1 lib.print_alert('Number of pages: %s\nCurrent Page: %s' % \ (self.num, self.currentpage))
def content(self): # Provide detailed user info global session hidden_password = '******' * 8 lib.print_alert('Username: %s\nPassword: %s' % \ (session.get_username(), hidden_password))