def _make(self, source): data = { 'type': source.readString('type'), 'icon': source.readString('icon'), 'defaultIcon': source.readString('defaultIcon'), 'filters': [], 'showMore': { 'enabled': False, 'command': None } } message = html_translation(source.readString('message')) section = source['filters'] if section is None: section = {} for _, subSec in section.items(): data['filters'].append({ 'name': subSec.readString('name'), 'color': subSec.readString('color') }) section = source['showMore'] if section is not None: data['showMore'] = { 'enabled': section.readBool('enabled'), 'command': section.readString('command') } return _MessageTemplate(message, data)
def _make(self, source): sourceID = source.name data = { 'type': source.readString('type'), 'timestamp': -1, 'savedData': None, 'nyData': None, 'bgIcon': self._makeBgIconsData(source['bgIcon']), 'bgIconSizeAuto': source.readBool('bgIconSizeAuto'), 'icon': source.readString('icon'), 'defaultIcon': source.readString('defaultIcon'), 'filters': [], 'buttonsStates': {}, 'buttonsLayout': [], 'buttonsAlign': source.readString('buttonsAlign', default='left') } priority = source.readString('priority', NotificationPriorityLevel.MEDIUM) if priority not in NotificationPriorityLevel.RANGE: LOG_WARNING('Priority is invalid', sourceID, priority) priority = NotificationPriorityLevel.MEDIUM groupID = source.readString('groupID', NotificationGroup.INFO) if groupID not in NotificationGroup.ALL: LOG_WARNING('GroupID is invalid', sourceID, groupID) groupID = NotificationGroup.INFO message = html_translation(source.readString('message')) section = source['filters'] if section is None: section = {} for _, subSec in section.items(): data['filters'].append({ 'name': subSec.readString('name'), 'color': subSec.readString('color') }) section = source['buttonsLayout'] if section is not None: layout = data['buttonsLayout'] buttonTypes = set([]) for _, subSec in section.items(): button = self._makeButtonData(sourceID, subSec) if button is None: continue buttonType = button['type'] if buttonType in buttonTypes: LOG_WARNING('Duplicated type of button', sourceID, buttonType) continue buttonTypes.add(buttonType) layout.append(button) return _MessageTemplate(message, data, priority, groupID)
def _makeButtonData(self, sourceID, section): action = section.readString('action') if not action: LOG_WARNING('button/action is not defined', sourceID) return None else: label = html_translation(section.readString('label')) if not label: LOG_WARNING('button/label is not defined', sourceID) return None buttonType = section.readString('type') if not buttonType and buttonType not in ('submit', 'cancel'): LOG_WARNING('button/type is not defined or invalid', sourceID, buttonType) return None result = {'label': label, 'type': buttonType, 'action': action} width = section.readInt('width') if width > 0: result['width'] = width return result
def _makeButtonData(self, sourceID, section): action = section.readString('action') if not action: LOG_WARNING('button/action is not defined', sourceID) return None label = html_translation(section.readString('label')) if not label: LOG_WARNING('button/label is not defined', sourceID) return None buttonType = section.readString('type') if not buttonType and buttonType not in ('submit', 'cancel'): LOG_WARNING('button/type is not defined or invalid', sourceID, buttonType) return None result = {'label': label, 'type': buttonType, 'action': action} width = section.readInt('width') if width > 0: result['width'] = width return result
def _make(self, source): data = {'type': source.readString('type'), 'icon': source.readString('icon'), 'defaultIcon': source.readString('defaultIcon'), 'filters': [], 'showMore': {'enabled': False, 'command': None}} message = html_translation(source.readString('message')) section = source['filters'] if section is None: section = {} for _, subSec in section.items(): data['filters'].append({'name': subSec.readString('name'), 'color': subSec.readString('color')}) section = source['showMore'] if section is not None: data['showMore'] = {'enabled': section.readBool('enabled'), 'command': section.readString('command')} return _MessageTemplate(message, data)
def _make(self, source): sourceID = source.name data = {'type': source.readString('type'), 'timestamp': -1, 'savedData': None, 'bgIcon': self._makeBgIconsData(source['bgIcon']), 'icon': source.readString('icon'), 'defaultIcon': source.readString('defaultIcon'), 'filters': [], 'buttonsLayout': []} priority = source.readString('priority', NotificationPriorityLevel.MEDIUM) if priority not in NotificationPriorityLevel.RANGE: LOG_WARNING('Priority is invalid', sourceID, priority) priority = NotificationPriorityLevel.MEDIUM message = html_translation(source.readString('message')) section = source['filters'] if section is None: section = {} for _, subSec in section.items(): data['filters'].append({'name': subSec.readString('name'), 'color': subSec.readString('color')}) section = source['buttonsLayout'] if section is not None: layout = data['buttonsLayout'] buttonTypes = set([]) for _, subSec in section.items(): button = self._makeButtonData(sourceID, subSec) if button is None: continue buttonType = button['type'] if buttonType in buttonTypes: LOG_WARNING('Duplicated type of button', sourceID, buttonType) continue buttonTypes.add(buttonType) layout.append(button) return _MessageTemplate(message, data, priority)
def readNoEmptyI18nStr(xmlCtx, section, name, msg): return html_translation(readNoEmptyStr(xmlCtx, section, name, msg))