def get_all_warnings(self): """check the mnemonic groups for conflicts and summarize as a list of links""" table = self.user["users.langid"].replace("-", "_") request = "SELECT DISTINCT mnemonicgroup FROM %s WHERE mnemonicgroup >= 0" % table self.session.execute_query(request) rows = self.session.cursor.fetchall() # for each mnemonic group, make sure that each entry is unique conflict_found = False warning_links = [] for r in rows: group_id = r[0] # get the difference between the total items in the mnemonic group and the # distinct strings in the mnemonic group expr1 = """SELECT count(textstring) FROM %s WHERE mnemonicgroup = %d AND role="MNEMONIC" """ % (table, group_id) expr2 = """SELECT count(DISTINCT textstring) FROM %s WHERE mnemonicgroup = %d AND role="MNEMONIC" """ % (table, group_id) request = "SELECT (%s) - (%s) AS diff_rows" % (expr1, expr2) self.session.execute_query(request) # if the two sets are not the same length, there is a conflict somewhere if self.session.cursor.fetchone()[0] != 0: group_link = "group_%d" % group_id warning_links.append(group_link) if len(warning_links) == 0: return "" else: t = warnings.warnings() t.warning_links = warning_links return t.respond()
def get_all_warnings(self): """Look for accelerator key conflicts. This function checks all accelerators, not just the ones from the form, and it ignores Space because that one is used twice (play/pause) and is not allowed to be changed by the user.""" table = self.user["users.langid"].replace("-", "_") expr1 = "SELECT count(DISTINCT actualkeys) FROM %s WHERE role=\"ACCELERATOR\" and actualkeys != \"Space\"" % table expr2 = "SELECT count(*) FROM %s WHERE role=\"ACCELERATOR\" and actualkeys != \"Space\"" % table request = "SELECT (%s) - (%s) AS diff_rows" % (expr1, expr2) self.session.execute_query(request) # if there is a difference in the lengths of the two sets, there must be a conflict if self.session.cursor.fetchone()[0] != 0: warning_message = "There is a conflict because two commands are using the same keyboard shortcut." self.session.warn(warning_message) t = warnings.warnings() t.warning_links = None t.warning_message = warning_message return t.respond() else: return ""