From 9a95684c7618e133e955c83e77480ea886ea0bc0 Mon Sep 17 00:00:00 2001 From: Tobin Date: Mon, 6 Apr 2015 11:28:52 -0500 Subject: [PATCH] added deleting comment or submission --- rtv/page.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/rtv/page.py b/rtv/page.py index d55b511..3b846da 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -251,6 +251,29 @@ class BasePage(object): else: show_notification(self.stdscr, ['Welcome {}'.format(username)]) + @BaseController.register('d') + def delete(self): + """ + Delete a submission or comment. + """ + data = self.content.get(self.nav.absolute_index) + if data['author'] == self.reddit.user.name: + prompt = 'Are you sure you want to delete this? (y/n):' + char = self.prompt_input(prompt) + if char == 'y': + try: + data['object'].delete() + show_notification(self.stdscr, ['Deleted']) + except praw.errors.APIException as e: + show_notification(self.stdscr, [e.message]) + else: + time.sleep(0.5) + self.refresh_content() + else: + show_notification(self.stdscr, ['Delete cancelled']) + else: + show_notification(self.stdscr, ['You can\'t delete this']) + def logout(self): "Prompt to log out of the user's account."