def convert_to_tag_array(tag_array, tag_category): from meta.models import Tag tags = [] for tag in tag_array: try: present_tag = Tag.objects.get(title=tag) tags.append(present_tag.id) except: # Create new tag and return it if tag_category: new_tag = Tag(title=tag, description='', category=tag_category) else: new_tag = Tag(title=tag, description='') new_tag.save() tags.append(new_tag.id) return tags
tag_raw = row if "CC" in tag_raw[0]: category = standards_category standard = re.sub("\.\.", ".", ".".join(tag_raw[:5])).upper() elif "M0" in tag_raw[0]: if tag_raw[4] == "": category = assessment_anchor_category standard = ".".join(tag_raw[:4]).upper() else: sub_standard = "-".join([".".join(tag_raw[:2]), tag_raw[2]]) if tag_raw[5] == "": category = anchor_descriptor_category standard = (sub_standard + "." + ".".join(tag_raw[3:5])).upper() else: category = eligible_content_category standard = (sub_standard + "." + ".".join(tag_raw[3:6])).upper() description = tag_raw[6].strip() try: tag = None tag = Tag.objects.get(title=standard) tag.category = category tag.save() except: tag = Tag(title=standard, description=description, category=category) tag.save()
counter = 0 standards_tc = TagCategory.objects.get(title='Standards') for (grade, grade_domains) in grades_map.items(): for (grade_domain_titles, grade_domain_exercises) in grade_domains.items(): for (standard, exercises) in grade_domain_exercises.items(): for exercise in exercises: r = Resource.objects.filter( user__username='******', title=exercise['title']).count() if r == 0: modified_standard = standard.replace('-', '.').upper() try: t = Tag.objects.get( title=modified_standard, category=standards_tc ) except: t = Tag( title=modified_standard, category=standards_tc ) t.save() build_resource_from_exercise(exercise['href'], modified_standard) """counter += 1 if counter > 100: sys.exit()"""