def toContentElement(element, content=None): '''Convert an element to a content element. Args: element: The XML element to convert. content: String to save as the element's content instead of the default. Returns: The converted element. ''' element.tag = 'item' if not content: content = 'Add content <b>here</b>...' util.et_sub(element, 'content', content) return element
def updateElem(element, item): '''Update the contents of the element with the contents of the item. Note: Everything in the element will be removed before saving the content from item. Args: element: The XML element to update. item: The source item with the data saved to the element. It must have: date, name, url, type, and filepath. Returns: The updated element. ''' if 'date' not in item or \ 'name' not in item or \ 'url' not in item or \ 'type' not in item or \ 'filepath' not in item: raise Exception('Dict parameter is missing required key') element.clear() for key, value in item.iteritems(): if value and not isinstance(value, basestring): value = ','.join(value) if key == 'tag': element.tag = value elif key != 'content': util.et_sub(element, key, value) # Defaults for optional arguments if 'title' not in item: util.et_sub(element, 'title', item['date']) if 'status' not in item: util.et_sub(element, 'status', 'hidden') return element