def _make_resource(self, request_id, expected_request_types): requests = IListRequests(self._mlist) results = requests.get_request(request_id) if results is None: return None key, data = results resource = dict(key=key, request_id=request_id) # Flatten the IRequest payload into the JSON representation. resource.update(data) # Check for a matching request type, and insert the type name into the # resource. request_type = RequestType(resource.pop('_request_type')) if request_type not in expected_request_types: return None resource['type'] = request_type.name # This key isn't what you think it is. Usually, it's the Pendable # record's row id, which isn't helpful at all. If it's not there, # that's fine too. resource.pop('id', None) return resource
def _make_resource(self, request_id): resource = super(_HeldMessageBase, self)._make_resource( request_id, HELD_MESSAGE_REQUESTS) if resource is None: return None # Grab the message and insert its text representation into the # resource. XXX See LP: #967954 key = resource.pop('key') msg = getUtility(IMessageStore).get_message_by_id(key) resource['msg'] = msg.as_string() # Some of the _mod_* keys we want to rename and place into the JSON # resource. Others we can drop. Since we're mutating the dictionary, # we need to make a copy of the keys. When you port this to Python 3, # you'll need to list()-ify the .keys() dictionary view. for key in resource.keys(): if key in ('_mod_subject', '_mod_hold_date', '_mod_reason', '_mod_sender', '_mod_message_id'): resource[key[5:]] = resource.pop(key) elif key.startswith('_mod_'): del resource[key] # Also, held message resources will always be this type, so ignore # this key value. del resource['type'] return resource