[27277] in Source-Commits

home help back first fref pref prev next nref lref last post

discuss-ng commit: Implement deletion and undeletion in ndsc

daemon@ATHENA.MIT.EDU (Victor Vasiliev)
Sat Sep 14 22:41:58 2013

Date: Sat, 14 Sep 2013 22:41:51 -0400
From: Victor Vasiliev <vasilvv@MIT.EDU>
Message-Id: <201309150241.r8F2fp1d025361@drugstore.mit.edu>
To: source-commits@MIT.EDU

https://github.com/mit-athena/discuss-ng/commit/edc6671e734dd6fd147d3bcde665fd5e95506846
commit edc6671e734dd6fd147d3bcde665fd5e95506846
Author: Victor Vasiliev <vasilvv@mit.edu>
Date:   Sat Sep 14 20:56:32 2013 -0400

    Implement deletion and undeletion in ndsc
    
    Use 'x' to delete the selected transaction and 'u' to undelete
    previously deleted transactions (in same ndsc session).

 ndsc |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/ndsc b/ndsc
index fb3fd2c..59b8ac6 100755
--- a/ndsc
+++ b/ndsc
@@ -12,6 +12,7 @@ from __future__ import print_function
 import curses, discuss  # discuss always comes with curses
 
 import argparse
+import bisect
 import locale
 import signal
 import sys
@@ -20,6 +21,7 @@ import sys
 pos_cur = 0
 pos_top = 0
 viewed_transaction = None
+delete_stack = []
 
 # Functions
 
@@ -198,6 +200,36 @@ def handle_transaction_view():
     viewed_transaction.text = viewed_transaction.get_text()
     textpos_y = textpos_x = 0
 
+def handle_transaction_delete():
+    # Do not allow the meeting to become empty
+    if len(transactions) < 2:
+        return
+
+    trn = transactions[pos_cur]
+
+    trn.delete()
+    del transactions[pos_cur]
+
+    delete_stack.append(trn)
+
+def handle_transaction_undelete():
+    if not delete_stack:
+        return
+
+    trn = delete_stack.pop()
+
+    try:
+        trn.meeting.undelete_transaction(trn.number)
+    except discuss.DiscussError as err:
+        # If transaction was expunged, there is nothing we can do, but this should
+        # not crash the client
+        if err.code == discuss.constants.EXPUNGED_TRN:
+            return
+        else:
+            raise err
+
+    transactions.insert(bisect.bisect_left(transactions, trn), trn)
+
 def main_loop():
     global pos_cur, pos_top, viewed_transaction
     global textpos_y, textpos_x
@@ -235,6 +267,10 @@ def main_loop():
                 pos_top = pos_cur - rows
             if ch == ord('\n'):
                 handle_transaction_view()
+            if ch == ord('x'):
+                handle_transaction_delete()
+            if ch == ord('u'):
+                handle_transaction_undelete()
         else:
             if ch == ord('q'):
                 viewed_transaction = None

home help back first fref pref prev next nref lref last post