Ejemplo n.º 1
0
def get_import_offerings_tasks():
    """
    Get all of the offerings to import, and build tasks (in groups) to do the work.

    Doesn't actually call the jobs: just returns celery tasks to be called.
    """
    #offerings = importer.import_offerings(extra_where="ct.subject='CMPT' and ct.catalog_nbr IN (' 383', ' 470')")
    #offerings = importer.import_offerings()
    offerings = importer.import_offerings(cancel_missing=True)
    offerings = list(offerings)
    offerings.sort()

    offering_groups = _grouper(offerings, 10)
    slug_groups = ([o.slug for o in offerings] for offerings in offering_groups)

    #tasks = [import_offering_group.si(slugs) for slugs in slug_groups]
    #return tasks

    offering_import_chain = chain(*[import_offering_group.si(slugs) for slugs in slug_groups])
    return offering_import_chain
Ejemplo n.º 2
0
def get_import_offerings_tasks():
    """
    Get all of the offerings to import, and build tasks (in groups) to do the work.

    Doesn't actually call the jobs: just returns celery tasks to be called.
    """
    #offerings = importer.import_offerings(extra_where="ct.subject='CMPT' and ct.catalog_nbr IN (' 383', ' 470')")
    #offerings = importer.import_offerings()
    offerings = importer.import_offerings(cancel_missing=True)
    offerings = list(offerings)
    offerings.sort()

    offering_groups = _grouper(offerings, 10)
    slug_groups = ([o.slug for o in offerings] for offerings in offering_groups)

    #tasks = [import_offering_group.si(slugs) for slugs in slug_groups]
    #return tasks

    offering_import_chain = chain(*[import_offering_group.si(slugs) for slugs in slug_groups])
    return offering_import_chain
Ejemplo n.º 3
0
def create_coredata():
    """
    Create enough of the coredata.models stuff to run basic tests
    """
    create_units()

    # restore ggbaker's real emplid so import_offerings will match
    p = find_person('ggbaker')
    p.emplid = find_emplid('ggbaker')

    # import a few more people we definitely need later
    find_person('popowich')
    find_person('dixon')
    find_person('diana')
    find_person('dzhao')
    find_person('pba7')

    # import a limited set of course offerings
    offerings = import_offerings(
        import_semesters=import_strms,
        extra_where="(subject='CMPT' AND (catalog_nbr LIKE '%% 12%%')) "
        "OR (subject='CMPT' AND (catalog_nbr LIKE '%% 16%%')) "
        "OR (subject='ENSC' AND (catalog_nbr LIKE '%% 10%%')) ")
    offerings = list(offerings)
    offerings.sort()

    if not CourseOffering.objects.filter(slug=TEST_COURSE_SLUG):
        o = CourseOffering.objects.filter(subject='CMPT', semester__name=import_strms()[0]) \
            .order_by('number', 'section').first()
        raise ValueError, "courselib.testing.TEST_COURSE_SLUG isn't an offering we have. Maybe use '%s'." % (
            o.slug)

    # import instructors
    for o in offerings:
        import_offering_members(o, students=False)

    # try to guess instructors' userids
    for p in Person.objects.filter(userid__isnull=True):
        p.userid = guess_userid(p.emplid)
        p.save()

    fake_emplids()

    # use/import no real emplids after this

    # create some fake undergrad/grad students
    for i in range(20):
        userid = "0aaa%i" % (i)
        fname = randname(8)
        p = random.randint(1, 2)
        if p == 1:
            pref = fname[:4]
        else:
            pref = fname
        p = Person(emplid=300000300 + i,
                   userid=userid,
                   last_name='Student',
                   first_name=fname,
                   middle_name=randname(6),
                   pref_first_name=pref)
        p.save()

        userid = "0ggg%i" % (i)
        fname = randname(8)
        p = random.randint(1, 2)
        if p == 1:
            pref = fname[:4]
        else:
            pref = fname
        p = Person(emplid=300000500 + i,
                   userid=userid,
                   last_name='Grad',
                   first_name=fname,
                   middle_name=randname(6),
                   pref_first_name=pref)
        p.config['gender'] = random.choice(('M', 'F', 'U'))
        p.config['gpa'] = round(random.triangular(0.0, 4.33, 2.33), 2)
        p.config['visa'] = random.choice([x for x, _ in VISA_STATUSES])
        p.config['citizen'] = random.choice(('Canadian', 'OtherCountrian'))
        p.save()

    # some memberships/roles/etc assumed by tests
    o = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
    ensure_member(Person.objects.get(userid='ggbaker'), o, "INST", 0, "AUTO",
                  "NONS")
    ensure_member(Person.objects.get(userid='0ggg0'), o, "TA", 0, "AUTO",
                  "NONS")
    ensure_member(Person.objects.get(userid='0aaa0'), o, "STUD", 3, "AUTO",
                  "UGRD")
    ensure_member(Person.objects.get(userid='0aaa1'), o, "STUD", 3, "AUTO",
                  "UGRD")

    d = Person.objects.get(userid='dzhao')
    set_privacy_signed(d)
    u = Unit.objects.get(slug='cmpt')
    r1 = Role(person=d, role='ADVS', unit=u, expiry=role_expiry)
    r1.save()
    r2 = Role(person=d, role='ADMN', unit=u, expiry=role_expiry)
    r2.save()
    r3 = Role(person=Person.objects.get(userid='pba7'),
              role='SYSA',
              unit=Unit.objects.get(slug='univ'),
              expiry=role_expiry)
    r3.save()
    r4 = Role(person=d, role='INV', unit=u, expiry=role_expiry)
    r4.save()
    r5 = Role(person=d, role='OUTR', unit=u, expiry=role_expiry)
    r5.save()

    # ensures course appears in menu for students
    a = NumericActivity(offering=o,
                        name=u'Assignmenț 1',
                        short_name='A1',
                        status='URLS',
                        position=1,
                        percent=10,
                        max_grade=10,
                        due_date=(o.semester.start +
                                  datetime.timedelta(days=60)))
    a.save()

    return itertools.chain(
        SemesterWeek.objects.filter(semester__name__gt=SEMESTER_CUTOFF),
        Unit.objects.all(),
        Course.objects.all(),
        CourseOffering.objects.all(),
        Person.objects.order_by('emplid'),
        Member.objects.all(),
        [r1, r2, r3, r4, r5, a.activity_ptr, a],
    )
Ejemplo n.º 4
0
def create_coredata():
    """
    Create enough of the coredata.models stuff to run basic tests
    """
    create_units()

    # restore ggbaker's real emplid so import_offerings will match
    p = find_person('ggbaker')
    p.emplid = find_emplid('ggbaker')

    # import a few more people we definitely need later
    find_person('popowich')
    find_person('dixon')
    find_person('diana')
    find_person('dzhao')
    find_person('pba7')

    # import a limited set of course offerings
    offerings = import_offerings(import_semesters=import_strms, extra_where=
        "(subject='CMPT' AND (catalog_nbr LIKE '%% 12%%')) "
        "OR (subject='ENSC' AND (catalog_nbr LIKE '%% 10%%')) "
        )
    offerings = list(offerings)
    offerings.sort()

    if not CourseOffering.objects.filter(slug=TEST_COURSE_SLUG):
        o = CourseOffering.objects.filter(subject='CMPT', semester__name=import_strms()[0]) \
            .order_by('number', 'section').first()
        raise ValueError, "courselib.testing.TEST_COURSE_SLUG isn't an offering we have. Maybe use '%s'." % (o.slug)

    # import instructors
    for o in offerings:
        import_offering_members(o, students=False)

    # try to guess instructors' userids
    for p in Person.objects.filter(userid__isnull=True):
        p.userid = guess_userid(p.emplid)
        p.save()

    fake_emplids()

    # use/import no real emplids after this

    # create some fake undergrad/grad students
    for i in range(20):
        userid = "0aaa%i" % (i)
        fname = randname(8)
        p = random.randint(1,2)
        if p == 1:
            pref = fname[:4]
        else:
            pref = fname
        p = Person(emplid=300000300+i, userid=userid, last_name='Student', first_name=fname, middle_name=randname(6), pref_first_name=pref)
        p.save()

        userid = "0ggg%i" % (i)
        fname = randname(8)
        p = random.randint(1,2)
        if p == 1:
            pref = fname[:4]
        else:
            pref = fname
        p = Person(emplid=300000500+i, userid=userid, last_name='Grad', first_name=fname, middle_name=randname(6), pref_first_name=pref)
        p.config['gender'] = random.choice(('M','F','U'))
        p.config['gpa'] = round(random.triangular(0.0, 4.33, 2.33), 2)
        p.config['visa'] = random.choice([x for x,_ in VISA_STATUSES])
        p.config['citizen'] = random.choice(('Canadian', 'OtherCountrian'))
        p.save()

    # some memberships/roles/etc assumed by tests
    o = CourseOffering.objects.get(slug=TEST_COURSE_SLUG)
    ensure_member(Person.objects.get(userid='ggbaker'), o, "INST", 0, "AUTO", "NONS")
    ensure_member(Person.objects.get(userid='0ggg0'), o, "TA", 0, "AUTO", "NONS")
    ensure_member(Person.objects.get(userid='0aaa0'), o, "STUD", 3, "AUTO", "UGRD")
    ensure_member(Person.objects.get(userid='0aaa1'), o, "STUD", 3, "AUTO", "UGRD")

    d = Person.objects.get(userid='dzhao')
    set_privacy_signed(d)
    r1 = Role(person=d, role='ADVS', unit=Unit.objects.get(slug='cmpt'))
    r1.save()
    r2 = Role(person=d, role='ADMN', unit=Unit.objects.get(slug='cmpt'))
    r2.save()
    r3 = Role(person=Person.objects.get(userid='pba7'), role='SYSA', unit=Unit.objects.get(slug='univ'))
    r3.save()

    # ensures course appears in menu for students
    a = NumericActivity(offering=o, name='Assignment 1', short_name='A1', status='URLS', position=1, percent=10,
        max_grade=10, due_date=(o.semester.start + datetime.timedelta(days=60)))
    a.save()

    return itertools.chain(
        SemesterWeek.objects.filter(semester__name__gt=SEMESTER_CUTOFF),
        Unit.objects.all(),
        Course.objects.all(),
        CourseOffering.objects.all(),
        Person.objects.order_by('emplid'),
        Member.objects.all(),
        [r1, r2, r3, a.activity_ptr, a],
    )