def import_categories(self, category_nodes):
self.write_out(self.style.STEP('<STR_LIT>'))<EOL>categories = {}<EOL>for category_node in category_nodes:<EOL><INDENT>title = category_node.find('<STR_LIT>' % WP_NS).text[:<NUM_LIT:255>]<EOL>slug = category_node.find(<EOL>'<STR_LIT>' % WP_NS).text[:<NUM_LIT:255>]<EOL>try:<EOL><INDENT>parent = category_node.find(<EOL>'<STR_LIT>' % WP_NS).text[:<NUM_LIT:255>]<EOL><DEDENT>except TypeError:<EOL><INDENT>parent = None<EOL><DEDENT>self.write_out('<STR_LIT>' % title)<EOL>category, created = Category.objects.get_or_create(<EOL>slug=slug, defaults={'<STR_LIT:title>': title,<EOL>'<STR_LIT>': categories.get(parent)})<EOL>categories[title] = category<EOL>self.write_out(self.style.ITEM('<STR_LIT>'))<EOL><DEDENT>return categories<EOL>
Import all the categories from 'wp:category' nodes,
because categories in 'item' nodes are not necessarily
all the categories and returning it in a dict for
database optimizations.