def find_material(row): #print row[0] new_isbn = convert_10_to_13(row[0]) try: m = LearningMaterial.objects.get(isbn=new_isbn) return m except LearningMaterial.DoesNotExist: m = LearningMaterial(isbn=new_isbn, title=row[1], publisher=Publisher.objects.get(name='Unknown')) m.save() print 'made a new material' return m
def iterate_through_data(data, publisher, grade_curriculum, vendor, default, empowerment, is_empowerment, is_default): for row in data: ordering_code = row[1].strip() if len(row[2]) > 1: title = row[0].strip().replace('*', '') try: if ordering_code == '': print title material = LearningMaterial.objects.get(title=title) print 'Empty ISBN' else: material = LearningMaterial.objects.get( ordering_code=ordering_code) material.title = title material.save() print 'Material title updated to ' + title print 'Found material ' + material.title if row[4] == 'TRUE': material.isTeacherEdition = True material.save() print 'Updated as Teacher\'s edition' if row[5] != '': material.quantity = int(row[5]) material.save() print material.quantity except LearningMaterial.DoesNotExist: print 'Creating material' m_type = row[3] if row[4] == 'TRUE': teachers = True print 'This is a teacher\'s edition' else: teachers = False if row[5] != '': q = row[5] else: q = 1 material = LearningMaterial(ordering_code=ordering_code, title=title, publisher=publisher, material_type=m_type, isTeacherEdition=teachers, quantity=q) material.save() print 'Material created: ' + material.title try: if ordering_code == '': grade_curriculum.materials.get(title=material.title) else: grade_curriculum.materials.get( ordering_code=material.ordering_code) print 'Looks like we already added this one to the curriculum!' except LearningMaterial.DoesNotExist: grade_curriculum.materials.add(material) grade_curriculum.save() print 'Material added to grade curriculum' # if '$' in row[2]: price = float(re.sub('[\$,]', '', row[2])) try: n = NegotiatedPrice.objects.get(value=price, material=material) print 'We have a price for this :)' except NegotiatedPrice.DoesNotExist: n = NegotiatedPrice(value=price, vendor=vendor, material=material) n.save() print 'Created the price' print material.title + ' has a price of ' + str(n.value) if is_default: n.negotiated_for_school_type.add(default) print 'Priced for default' if is_empowerment: n.negotiated_for_school_type.add(empowerment) print 'Priced for empowerment'
def iterate_through_data(data, publisher, grade_curriculum, vendor, default, empowerment, is_empowerment, is_default): for row in data: ordering_code = row[1].strip() if len(row[2]) > 1: title = row[0].strip().replace('*', '') try: if ordering_code == '': print title material = LearningMaterial.objects.get(title=title) print 'Empty ISBN' else: material = LearningMaterial.objects.get(ordering_code=ordering_code) material.title = title material.save() print 'Material title updated to ' + title print 'Found material ' + material.title if row[4] == 'TRUE': material.isTeacherEdition = True material.save() print 'Updated as Teacher\'s edition' if row[5] != '': material.quantity = int(row[5]) material.save() print material.quantity except LearningMaterial.DoesNotExist: print 'Creating material' m_type = row[3] if row[4] == 'TRUE': teachers = True print 'This is a teacher\'s edition' else: teachers = False if row[5] != '': q = row[5] else: q = 1 material = LearningMaterial(ordering_code=ordering_code, title=title, publisher=publisher, material_type=m_type, isTeacherEdition=teachers, quantity=q) material.save() print 'Material created: ' + material.title try: if ordering_code == '': grade_curriculum.materials.get(title=material.title) else: grade_curriculum.materials.get(ordering_code=material.ordering_code) print 'Looks like we already added this one to the curriculum!' except LearningMaterial.DoesNotExist: grade_curriculum.materials.add(material) grade_curriculum.save() print 'Material added to grade curriculum' # if '$' in row[2]: price = float(re.sub('[\$,]', '', row[2])) try: n = NegotiatedPrice.objects.get(value=price, material=material) print 'We have a price for this :)' except NegotiatedPrice.DoesNotExist: n = NegotiatedPrice(value=price, vendor=vendor, material=material) n.save() print 'Created the price' print material.title + ' has a price of ' + str(n.value) if is_default: n.negotiated_for_school_type.add(default) print 'Priced for default' if is_empowerment: n.negotiated_for_school_type.add(empowerment) print 'Priced for empowerment'