Example #1
0
	def create_categories(sheet, start_index, end_index):
		"""
			First row entry of every section will contain parent_category name.
		"""
		categories = sheet.row_values(start_index)
		parent_category = None
		parent_category_list = BlogParentCategory.objects.filter(title=categories[PARENT_CATEGORY_INDEX])
		if len(parent_category_list) == 0:
			parent_category_string = categories[PARENT_CATEGORY_INDEX]
			parent_category_string = parent_category_string.replace('/', '')
			parent_category = BlogParentCategory(slug=slugify(parent_category_string))
			parent_category.title = parent_category_string
			parent_category.save()
		else:
			parent_category = parent_category_list[0]

		sub_categories = sheet.col_values(SUB_CATEGORIES_INDEX, start_rowx=start_index, end_rowx=end_index)

		for sub_category in sub_categories:
			if sub_category == '':
				sub_category = parent_category.title
				
			sub_category = sub_category.replace('/','')
			sub_category_list = BlogCategory.objects.filter(title=sub_category)
			if len(sub_category_list) == 0:
				sub_category_obj = BlogCategory(slug=slugify(sub_category), title=sub_category)
				sub_category_obj.save()
				sub_category_obj.parent_category.add(parent_category)
			else:
				sub_category_obj = sub_category_list[0]
				sub_category_obj.parent_category.add(parent_category)
				print sub_category_obj.title, "is now listed under: ", sub_category_obj.parent_category.all(), "\n"
Example #2
0
		# add the category if it doesn't already exists
		#xml_tags = root.findall('.//%stag' % wp_name_space, namespaces)
		xml_tags = root.findall('.//%stag' % wp_name_space)
		for xml_tag in xml_tags:
			xml_tag.findall('.//%stag' % wp_name_space)
			tag = {
					'id': 	xml_tag.find('%sterm_id' % wp_name_space).text,
					'slug': xml_tag.find('%stag_slug' % wp_name_space).text,
					'name': xml_tag.find('%stag_name' % wp_name_space).text,
					}
			tags[tag['id']] = tag
			
			# add the category if it doesn't already exists
			if tag['slug'] not in categories:
				print '\tAdd new %s to Mezzanine: %s' % (model_name, tag['slug'], )
				category = CatOrKwd(slug=tag['slug'], title=tag['name'], site_id=1)
				if not self.is_dry_run():
					category.save()
				categories[category.slug] = category
				
		print '%d tags in Wordpress' % len(xml_tags)
			
		# Tag the posts
		#
		# <item>
		#	<title>Text, Image and the Digital Research Environment</title>
		#	<category domain="post_tag" nicename="about-digipal"><![CDATA[About DigiPal]]></category>
		#
		xml_items = {}
		for xml_item in tree.findall('.//item'):
			xml_items[xml_item.find('title').text] = xml_item
Example #3
0
def create_category(request, s):
    tmp = BlogCategory(title=s)
    if tmp.save():
        return HttpResponse("Success")
    else:
        return HttpResponse("Fail")
Example #4
0
		# add the category if it doesn't already exists
		#xml_tags = root.findall('.//%stag' % wp_name_space, namespaces)
		xml_tags = root.findall('.//%stag' % wp_name_space)
		for xml_tag in xml_tags:
			xml_tag.findall('.//%stag' % wp_name_space)
			tag = {
					'id': 	xml_tag.find('%sterm_id' % wp_name_space).text,
					'slug': xml_tag.find('%stag_slug' % wp_name_space).text,
					'name': xml_tag.find('%stag_name' % wp_name_space).text,
					}
			tags[tag['id']] = tag
			
			# add the category if it doesn't already exists
			if tag['slug'] not in categories:
				print '\tAdd new %s to Mezzanine: %s' % (model_name, tag['slug'], )
				category = CatOrKwd(slug=tag['slug'], title=tag['name'], site_id=1)
				if not self.is_dry_run():
					category.save()
				categories[category.slug] = category
				
		print '%d tags in Wordpress' % len(xml_tags)
			
		# Tag the posts
		#
		# <item>
		#	<title>Text, Image and the Digital Research Environment</title>
		#	<category domain="post_tag" nicename="about-digipal"><![CDATA[About DigiPal]]></category>
		#
		xml_items = {}
		for xml_item in tree.findall('.//item'):
			xml_items[xml_item.find('title').text] = xml_item