Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def import_categories(self, category_nodes):
self.stdout.write('Importing categories...')
categories = {}
for category_node in category_nodes:
title = category_node.find(u'{{{0:s}}}cat_name'.format(self.WP_NS)).text[:255]
slug = category_node.find(u'{{{0:s}}}category_nicename'.format(self.WP_NS)).text[:255]
try:
parent = category_node.find(u'{{{0:s}}}category_parent'.format(self.WP_NS)).text[:255]
except TypeError:
parent = None
self.stdout.write(u'\t\t{0:s}'.format(title))
category, created = PuputCategory.objects.update_or_create(name=title, defaults={
'slug': slug, 'parent': categories.get(parent)
})
categories[title] = category
return categories