Exemplo n.º 1
0
 def save_tutor_from_applications(applications, dry_run=False):
     for application in applications:
         try:
             tutor = Tutor.objects.get(
                 profile=application.profile,
                 year=application.year,
             )
         except Tutor.DoesNotExist:
             tutor = Tutor(
                 profile=application.profile,
                 year=application.year,
             )
             if not dry_run:
                 tutor.save()
         if not dry_run:
             tutor.groups = application.assigned_groups.all()
             tutor.save()
Exemplo n.º 2
0
def create_tutors(tp_dict):
    existing = {
        tutor.profile.studentnumber: tutor
        for tutor in Tutor.members(YEAR)
    }
    create = []
    for studentnumber, tp in tp_dict.items():
        if studentnumber in existing:
            continue
        t = Tutor(year=YEAR, profile=tp)
        create.append(t)
        existing[studentnumber] = t

    def save_tutors():
        for tutor in create:
            tutor.save()

    return existing, save_tutors
Exemplo n.º 3
0
    group_by_handle = {
        g.handle: g for g in TutorGroup.objects.filter(
            year=2016, handle__in=group_aliases.values())
    }

    new_tutor = []
    new_password = []
    new_groups = []
    group_leaders = []
    for entry in approved_entries:
        sn = entry['Årskortnummer']
        tp = tutorprofiles_by_sn[sn]
        entry['tutorprofile'] = tp
        if sn not in existing_sn:
            tu = Tutor(year=2016, profile=tp)
            new_tutor.append(tu)
            # print(new_tutor[-1])
            # tu.save()
            raise Exception("Did not exist")
        else:
            tu = existing_sn[sn]

        group_names = [entry['GRUPPE 1'], entry['GRUPPE 2']]
        group_names = [s for s in group_names if s != '-']
        group_handles = [group_aliases[g] for g in group_names]
        group_objects = [group_by_handle[g] for g in group_handles]

        for g in group_objects:
            new_groups.append((tu, g))