diff src/stdui/ui_contact_list.py @ 2071:c2fdee1bd908

core (stdui): fixed cancellation of ContactList forms
author Goffi <goffi@goffi.org>
date Sun, 11 Sep 2016 23:17:31 +0200
parents 2daf7b4c6756
children 90189f312fd3
line wrap: on
line diff
--- a/src/stdui/ui_contact_list.py	Sun Sep 11 11:03:25 2016 +0200
+++ b/src/stdui/ui_contact_list.py	Sun Sep 11 23:17:31 2016 +0200
@@ -22,7 +22,6 @@
 from sat.tools import xml_tools
 from twisted.words.protocols.jabber import jid
 from xml.dom.minidom import Element
-import re
 
 
 class ContactList(object):
@@ -209,9 +208,14 @@
         @param profile: %(doc_profile)s
         @return dict
         """
+        if C.bool(data.get('cancelled', 'false')):
+            return {}
         contact = data[xml_tools.formEscape('contact_jid')]
-        cb = lambda data, profile: self._deleteContact(jid.JID(contact), profile)
-        delete_id = self.host.registerCallback(cb, with_data=True, one_shot=True)
+        def delete_cb(data, profile):
+            if not C.bool(data.get('cancelled', 'false')):
+                self._deleteContact(jid.JID(contact), profile)
+            return {}
+        delete_id = self.host.registerCallback(delete_cb, with_data=True, one_shot=True)
         form_ui = xml_tools.XMLUI("form", title=D_("Delete contact"), submit_id=delete_id)
         form_ui.addText(D_("Are you sure you want to remove %s from your contact list?") % contact)
         return {'xmlui': form_ui.toXml()}
@@ -223,6 +227,8 @@
         @param profile: %(doc_profile)s
         @return dict
         """
+        if C.bool(data.get('cancelled', 'false')):
+            return {}
         contact_jid_s = data[xml_tools.formEscape('contact_jid')]
         try:
             contact_jid = jid.JID(contact_jid_s)
@@ -244,6 +250,8 @@
         @param profile: %(doc_profile)s
         @return dict
         """
+        if C.bool(data.get('cancelled', 'false')):
+            return {}
         contact_jid = jid.JID(data[xml_tools.formEscape('contact_jid')])
         # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted)
         groups = data[xml_tools.formEscape('groups_list')].split('\t')