Exemplo n.º 1
0
def create_others():
    """
    Create other users for the test data set
    """
    p = Person(emplid=fake_emplid(), first_name="Susan", last_name="Kindersley", pref_first_name="sumo", userid="sumo")
    p.save()
    r = Role(person=p, role="GRAD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    p = Person(emplid=fake_emplid(), first_name="Danyu", last_name="Zhao", pref_first_name="Danyu", userid="dzhao")
    p.save()
    set_privacy_signed(p)
    r = Role(person=p, role="ADVS", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='dixon'), role="PLAN", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='ggbaker'), role="FAC", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='dixon'), role="FAC", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='diana'), role="FAC", unit=Unit.objects.get(slug='cmpt'))
    r.save()

    p = Person.objects.get(userid='ggbaker')
    set_privacy_signed(p)
    r = Role(person=p, role="GRAD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=p, role="ADMN", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=p, role="TAAD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=p, role="FUND", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='popowich'), role="GRPD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
Exemplo n.º 2
0
def create_others():
    """
    Create other users for the test data set
    """
    p = Person(emplid=fake_emplid(),
               first_name="Susan",
               last_name="Kindersley",
               pref_first_name="sumo",
               userid="sumo")
    p.save()
    r = Role(person=p, role="GRAD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    p = Person(emplid=fake_emplid(),
               first_name="Danyu",
               last_name="Zhao",
               pref_first_name="Danyu",
               userid="dzhao")
    p.save()
    set_privacy_signed(p)
    r = Role(person=p, role="ADVS", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='dixon'),
             role="PLAN",
             unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='ggbaker'),
             role="FAC",
             unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='dixon'),
             role="FAC",
             unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='diana'),
             role="FAC",
             unit=Unit.objects.get(slug='cmpt'))
    r.save()

    p = Person.objects.get(userid='ggbaker')
    set_privacy_signed(p)
    r = Role(person=p, role="GRAD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=p, role="ADMN", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=p, role="TAAD", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=p, role="FUND", unit=Unit.objects.get(slug='cmpt'))
    r.save()
    r = Role(person=Person.objects.get(userid='popowich'),
             role="GRPD",
             unit=Unit.objects.get(slug='cmpt'))
    r.save()
Exemplo n.º 3
0
    def personal_data(self):
        # get the objects that should already be there
        greg = Person.objects.get(userid='ggbaker')
        diana = Person.objects.get(userid='diana')
        brad = Person.objects.get(userid='bbart')
        tony = Person.objects.get(userid='dixon')
        danyu = Person.objects.get(userid='dzhao')
        farid = Person.objects.get(userid='mfgolnar')
        phillip = Person.objects.get(userid='phillip')
        editor = tony

        cmpt = Unit.objects.get(slug='cmpt')
        ensc = Unit.objects.get(slug='ensc')
        mse = Unit.objects.get(slug='mse')
        phil = Unit.objects.get(slug='phil')
        fas = Unit.objects.get(slug='fas')

        # create basic roles
        Role.objects.get_or_create(person=greg, unit=cmpt, role='FAC')
        Role.objects.get_or_create(person=brad, unit=cmpt, role='FAC')
        r,_ = Role.objects.get_or_create(person=diana, unit=cmpt, role='FAC')
        r.gone = True
        r.save()
        Role.objects.get_or_create(person=tony, unit=cmpt, role='FAC')
        Role.objects.get_or_create(person=tony, unit=ensc, role='FAC')
        Role.objects.get_or_create(person=farid, unit=mse, role='FAC')
        Role.objects.get_or_create(person=phillip, unit=phil, role='FAC')
        Role.objects.get_or_create(person=tony, unit=cmpt, role='ADMN')
        set_privacy_signed(tony)
        Role.objects.get_or_create(person=danyu, unit=fas, role='ADMN')
        set_privacy_signed(danyu)

        # create some events

        for person in [tony, diana, greg]:
            # appointment
            e, h = event_get_or_create(person=person, unit=cmpt, event_type='APPOINT', start_date=date(2000,9,1),
                                    status='A')
            e.config = {'spousal_hire': False, 'leaving_reason': 'HERE'}
            h.save(editor=editor)
            appt = e

            # teaching load
            e, h = event_get_or_create(person=person, unit=cmpt, event_type='NORM_TEACH', start_date=date(2000,9,1),
                                    status='A')
            e.config = {'load': 2}
            h.save(editor=editor)

            # annual salary updates
            for year in range(2000, 2014):
                e, h = event_get_or_create(person=person, unit=cmpt, event_type='SALARY', start_date=date(year,9,1),
                                        status='A')
                e.config = {'rank': 'SLEC' if year>2005 else 'LECT',
                            'step': year-1999,
                            'base_salary': 60000 + (year-2000)*2000,
                            'add_salary': 1000 if year>2005 else 0,
                            'add_pay': 500 if year<2005 else 0,
                            }
                h.save(editor=editor)

        # teaching credits
        e, h = event_get_or_create(person=greg, unit=cmpt, event_type='TEACHING', start_date=date(2012,9,1),
                                end_date=date(2012,12,31), status='A')
        e.config = {'category': 'RELEASE', 'teaching_credits': '1', 'reason': "We just couldn't say no!"}
        h.save(editor=editor)

        e, h = event_get_or_create(person=greg, unit=cmpt, event_type='TEACHING', start_date=date(2013,9,1),
                                end_date=date(2014,4,30), status='NA',
                                comments='Note that this is one teaching credit spread across two semesters.')
        e.config = {'category': 'BUYOUT', 'teaching_credits': '1/2', 'reason': "Somebody gave money."}
        h.save(editor=editor)

        # admin position
        e, h = event_get_or_create(person=greg, unit=cmpt, event_type='ADMINPOS', start_date=date(2008,9,1),
                                end_date=date(2010,8,31), status='A')
        e.config = {'position': 'UGRAD_DIRECTOR', 'teaching_credit': '1/2'}
        h.save(editor=editor)

        # admin position in other unit
        e, h = event_get_or_create(person=greg, unit=ensc, event_type='ADMINPOS', start_date=date(2010,9,1),
                                end_date=date(2011,8,31), status='A')
        e.config = {'position': 'UGRAD_DIRECTOR', 'teaching_credit': '0'}
        h.save(editor=editor)

        # a memo
        mt = MemoTemplate.objects.filter(event_type='APPOINT')[0]
        m, _ = Memo.objects.get_or_create(career_event=appt, unit=cmpt, sent_date=date(1999,8,15), to_lines='Greg Baker',
                cc_lines='The FAS Dean\nVancouver Sun', from_person=tony, from_lines='Tony Dixon, CMPT',
                subject='Appointment as lecturer', template=mt, created_by=tony)
        m.memo_text = ("We are pleased to appoint Gregory Baker to a new job.\n\n" +
                "Because we are so excited to hire him, we will be throwing a party. Date to be announced.")
        m.save()

        # some leaves etc to demo salary/fallout
        e, h = event_get_or_create(person=diana, unit=cmpt, event_type='LEAVE', start_date=date(2014,1,1),
                                end_date=date(2014,12,31), status='A')
        e.config = {'reason': 'MEDICAL', 'leave_fraction': '1/2', 'teaching_load_decrease': 1, 'teaching_credits': 0}
        h.save(editor=editor)

        e, h = event_get_or_create(person=tony, unit=cmpt, event_type='STUDYLEAVE', start_date=date(2013,9,1),
                                end_date=date(2014,8,31), status='A')
        e.config = {'pay_fraction': '4/5', 'teaching_decrease': 2, 'study_leave_credits': 24, 'credits_forward': 0}
        h.save(editor=editor)

        e, h = event_get_or_create(person=tony, unit=cmpt, event_type='FELLOW', start_date=date(2012,1,1),
                                end_date=None, status='A')
        e.config = {'position': 'BBYM', 'add_salary': 0, 'add_pay': 10000, 'teaching_credit': 0}
        h.save(editor=editor)


        # out-of-unit events: Dean's office staff should see MSE stuff
        e, h = event_get_or_create(person=farid, unit=mse, event_type='SALARY', start_date=date(2000,9,1),
                                status='A')
        e.config = {'step': 7,
                    'base_salary': 100000,
                    'add_salary': 17,
                    'add_pay': '6.50',
                    'rank': 'FULL',
                    }
        h.save(editor=editor)

        e, h = event_get_or_create(person=farid, unit=mse, event_type='NORM_TEACH', start_date=date(2000,9,1),
                                status='A')
        e.config = {'load': 1}
        h.save(editor=editor)

        # out-of-unit events: nobody should be seeing PHIL events
        e, h = event_get_or_create(person=phillip, unit=phil, event_type='SALARY', start_date=date(2000,9,1),
                                status='A')
        e.config = {'step': 7,
                    'base_salary': 1000000,
                    'add_salary': 17,
                    'add_pay': '6.50',
                    }
        h.save(editor=editor)

        e, h = event_get_or_create(person=phillip, unit=phil, event_type='NORM_TEACH', start_date=date(2000,9,1),
                                status='A')
        e.config = {'load': 2}
        h.save(editor=editor)


        # some grants
        tg, _ = TempGrant.objects.get_or_create(label="Cukierman startup", initial=4000, project_code='13-12345',
                                             creator=danyu)
        tg.config['cur_month'] = 500
        tg.config['ytd_actual'] = 1000
        tg.config['cur_balance'] = 1500
        tg.save()

        g, _ = Grant.objects.get_or_create(title="Baker startup grant", label='Baker startup', unit=cmpt,
                                        project_code='13-23456', start_date=date(2000,9,1), initial=4000, overhead=0)
        go, _ = GrantOwner.objects.get_or_create(grant=g, person=greg)
        go.save()

        gb, _ = GrantBalance.objects.get_or_create(grant=g, date=date(2000,9,30), balance=4000, actual=0, month=0)
        gb.save()
        gb, _ = GrantBalance.objects.get_or_create(grant=g, date=date(2001,9,10), balance=3000, actual=1000, month=250)
        gb.save()
        gb, _ = GrantBalance.objects.get_or_create(grant=g, date=date(2002,9,10), balance=0, actual=3000, month=0)
        gb.save()
Exemplo 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='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],
    )
Exemplo n.º 5
0
    def personal_data(self):
        # get the objects that should already be there
        greg = Person.objects.get(userid='ggbaker')
        diana = Person.objects.get(userid='diana')
        brad = Person.objects.get(userid='bbart')
        tony = Person.objects.get(userid='dixon')
        danyu = Person.objects.get(userid='dzhao')
        farid = Person.objects.get(userid='mfgolnar')
        phillip = Person.objects.get(userid='phillip')
        editor = tony

        cmpt = Unit.objects.get(slug='cmpt')
        ensc = Unit.objects.get(slug='ensc')
        mse = Unit.objects.get(slug='mse')
        phil = Unit.objects.get(slug='phil')
        fas = Unit.objects.get(slug='fas')

        # create basic roles
        Role.objects.get_or_create(person=greg, unit=cmpt, role='FAC')
        Role.objects.get_or_create(person=brad, unit=cmpt, role='FAC')
        r, _ = Role.objects.get_or_create(person=diana, unit=cmpt, role='FAC')
        r.gone = True
        r.save()
        Role.objects.get_or_create(person=tony, unit=cmpt, role='FAC')
        Role.objects.get_or_create(person=tony, unit=ensc, role='FAC')
        Role.objects.get_or_create(person=farid, unit=mse, role='FAC')
        Role.objects.get_or_create(person=phillip, unit=phil, role='FAC')
        Role.objects.get_or_create(person=tony, unit=cmpt, role='ADMN')
        set_privacy_signed(tony)
        Role.objects.get_or_create(person=danyu, unit=fas, role='ADMN')
        set_privacy_signed(danyu)

        # create some events

        for person in [tony, diana, greg]:
            # appointment
            e, h = event_get_or_create(person=person,
                                       unit=cmpt,
                                       event_type='APPOINT',
                                       start_date=date(2000, 9, 1),
                                       status='A')
            e.config = {'spousal_hire': False, 'leaving_reason': 'HERE'}
            h.save(editor=editor)
            appt = e

            # teaching load
            e, h = event_get_or_create(person=person,
                                       unit=cmpt,
                                       event_type='NORM_TEACH',
                                       start_date=date(2000, 9, 1),
                                       status='A')
            e.config = {'load': 2}
            h.save(editor=editor)

            # annual salary updates
            for year in range(2000, 2014):
                e, h = event_get_or_create(person=person,
                                           unit=cmpt,
                                           event_type='SALARY',
                                           start_date=date(year, 9, 1),
                                           status='A')
                e.config = {
                    'rank': 'SLEC' if year > 2005 else 'LECT',
                    'step': year - 1999,
                    'base_salary': 60000 + (year - 2000) * 2000,
                    'add_salary': 1000 if year > 2005 else 0,
                    'add_pay': 500 if year < 2005 else 0,
                }
                h.save(editor=editor)

        # teaching credits
        e, h = event_get_or_create(person=greg,
                                   unit=cmpt,
                                   event_type='TEACHING',
                                   start_date=date(2012, 9, 1),
                                   end_date=date(2012, 12, 31),
                                   status='A')
        e.config = {
            'category': 'RELEASE',
            'teaching_credits': '1',
            'reason': "We just couldn't say no!"
        }
        h.save(editor=editor)

        e, h = event_get_or_create(
            person=greg,
            unit=cmpt,
            event_type='TEACHING',
            start_date=date(2013, 9, 1),
            end_date=date(2014, 4, 30),
            status='NA',
            comments=
            'Note that this is one teaching credit spread across two semesters.'
        )
        e.config = {
            'category': 'BUYOUT',
            'teaching_credits': '1/2',
            'reason': "Somebody gave money."
        }
        h.save(editor=editor)

        # admin position
        e, h = event_get_or_create(person=greg,
                                   unit=cmpt,
                                   event_type='ADMINPOS',
                                   start_date=date(2008, 9, 1),
                                   end_date=date(2010, 8, 31),
                                   status='A')
        e.config = {'position': 'UGRAD_DIRECTOR', 'teaching_credit': '1/2'}
        h.save(editor=editor)

        # admin position in other unit
        e, h = event_get_or_create(person=greg,
                                   unit=ensc,
                                   event_type='ADMINPOS',
                                   start_date=date(2010, 9, 1),
                                   end_date=date(2011, 8, 31),
                                   status='A')
        e.config = {'position': 'UGRAD_DIRECTOR', 'teaching_credit': '0'}
        h.save(editor=editor)

        # a memo
        mt = MemoTemplate.objects.filter(event_type='APPOINT')[0]
        m, _ = Memo.objects.get_or_create(
            career_event=appt,
            unit=cmpt,
            sent_date=date(1999, 8, 15),
            to_lines='Greg Baker',
            cc_lines='The FAS Dean\nVancouver Sun',
            from_person=tony,
            from_lines='Tony Dixon, CMPT',
            subject='Appointment as lecturer',
            template=mt,
            created_by=tony)
        m.memo_text = (
            "We are pleased to appoint Gregory Baker to a new job.\n\n" +
            "Because we are so excited to hire him, we will be throwing a party. Date to be announced."
        )
        m.save()

        # some leaves etc to demo salary/fallout
        e, h = event_get_or_create(person=diana,
                                   unit=cmpt,
                                   event_type='LEAVE',
                                   start_date=date(2014, 1, 1),
                                   end_date=date(2014, 12, 31),
                                   status='A')
        e.config = {
            'reason': 'MEDICAL',
            'leave_fraction': '1/2',
            'teaching_load_decrease': 1,
            'teaching_credits': 0
        }
        h.save(editor=editor)

        e, h = event_get_or_create(person=tony,
                                   unit=cmpt,
                                   event_type='STUDYLEAVE',
                                   start_date=date(2013, 9, 1),
                                   end_date=date(2014, 8, 31),
                                   status='A')
        e.config = {
            'pay_fraction': '4/5',
            'teaching_decrease': 2,
            'study_leave_credits': 24,
            'credits_forward': 0
        }
        h.save(editor=editor)

        e, h = event_get_or_create(person=tony,
                                   unit=cmpt,
                                   event_type='FELLOW',
                                   start_date=date(2012, 1, 1),
                                   end_date=None,
                                   status='A')
        e.config = {
            'position': 'BBYM',
            'add_salary': 0,
            'add_pay': 10000,
            'teaching_credit': 0
        }
        h.save(editor=editor)

        # out-of-unit events: Dean's office staff should see MSE stuff
        e, h = event_get_or_create(person=farid,
                                   unit=mse,
                                   event_type='SALARY',
                                   start_date=date(2000, 9, 1),
                                   status='A')
        e.config = {
            'step': 7,
            'base_salary': 100000,
            'add_salary': 17,
            'add_pay': '6.50',
            'rank': 'FULL',
        }
        h.save(editor=editor)

        e, h = event_get_or_create(person=farid,
                                   unit=mse,
                                   event_type='NORM_TEACH',
                                   start_date=date(2000, 9, 1),
                                   status='A')
        e.config = {'load': 1}
        h.save(editor=editor)

        # out-of-unit events: nobody should be seeing PHIL events
        e, h = event_get_or_create(person=phillip,
                                   unit=phil,
                                   event_type='SALARY',
                                   start_date=date(2000, 9, 1),
                                   status='A')
        e.config = {
            'step': 7,
            'base_salary': 1000000,
            'add_salary': 17,
            'add_pay': '6.50',
        }
        h.save(editor=editor)

        e, h = event_get_or_create(person=phillip,
                                   unit=phil,
                                   event_type='NORM_TEACH',
                                   start_date=date(2000, 9, 1),
                                   status='A')
        e.config = {'load': 2}
        h.save(editor=editor)

        # some grants
        tg, _ = TempGrant.objects.get_or_create(label="Cukierman startup",
                                                initial=4000,
                                                project_code='13-12345',
                                                creator=danyu)
        tg.config['cur_month'] = 500
        tg.config['ytd_actual'] = 1000
        tg.config['cur_balance'] = 1500
        tg.save()

        g, _ = Grant.objects.get_or_create(title="Baker startup grant",
                                           label='Baker startup',
                                           unit=cmpt,
                                           project_code='13-23456',
                                           start_date=date(2000, 9, 1),
                                           initial=4000,
                                           overhead=0)
        go, _ = GrantOwner.objects.get_or_create(grant=g, person=greg)
        go.save()

        gb, _ = GrantBalance.objects.get_or_create(grant=g,
                                                   date=date(2000, 9, 30),
                                                   balance=4000,
                                                   actual=0,
                                                   month=0)
        gb.save()
        gb, _ = GrantBalance.objects.get_or_create(grant=g,
                                                   date=date(2001, 9, 10),
                                                   balance=3000,
                                                   actual=1000,
                                                   month=250)
        gb.save()
        gb, _ = GrantBalance.objects.get_or_create(grant=g,
                                                   date=date(2002, 9, 10),
                                                   balance=0,
                                                   actual=3000,
                                                   month=0)
        gb.save()
Exemplo n.º 6
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],
    )