Esempio n. 1
0
def refresh_departments(cursor):
    
    depts = cursor.execute("""
        SELECT Code, Description
        FROM pom.Departments;""").fetchall()
    
    total = created = 0
    
    for deptrow in depts:
        if _is_requirement_area(deptrow.Code):
            try:
                ra = RequirementArea.objects.get(code=deptrow.Code)
            except RequirementArea.DoesNotExist:
                ra = RequirementArea(code=deptrow.Code)
                created += 1
            
            ra.name = deptrow.Description
            ra.campus = CAMPUSES[int(deptrow.Code[0]) - 1][0] # CAMPUSES is 0-indexed
            ra.save()
        else:
            try:
                dept = Department.objects.get(code=deptrow.Code)
            except Department.DoesNotExist:
                dept = Department(code=deptrow.Code)
                created += 1
            
            dept.name = deptrow.Description
            dept.save()
        total += 1
    
    logger.info("Updated {0} departments and requirement areas, creating {1}"
                " new records".format(total, created))
 def handle(self, *args, **options):
     from aspc.data.scraped_requirement_areas import requirement_areas
     for code, name in requirement_areas:
         self.stdout.write('trying "%s"... ' % code)
         name = name.replace('&', '&')
         ra_campus = CAMPUSES[int(code[0]) - 1][0] # first char of ra code is 1-indexed college id
         try:
             newra = RequirementArea.objects.get(code=code)
             self.stdout.write('exists, updating\n')
         except RequirementArea.DoesNotExist:
             self.stdout.write('adding')
             newra = RequirementArea(code=code)
         newra.name = name
         newra.campus = ra_campus
         newra.save()
         self.stdout.write('Successfully updated "%s"\n' % code)