当前位置: 首页>>代码示例>>Python>>正文


Python Member.save方法代码示例

本文整理汇总了Python中coredata.models.Member.save方法的典型用法代码示例。如果您正苦于以下问题:Python Member.save方法的具体用法?Python Member.save怎么用?Python Member.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coredata.models.Member的用法示例。


在下文中一共展示了Member.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_select_components

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_select_components(self):
        """
        Test submission component classes: subclasses, selection, sorting.
        """
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date="2010-04-01")
        a1.save()
        a2 = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=course, position=1, max_grade=15, due_date="2010-03-01")
        a2.save()

        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()

        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1, title="Archive File", position=1, max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c3.save()
        comps = select_all_components(a1)
        self.assertEqual(len(comps), 3)
        self.assertEqual(comps[0].title, 'Archive File') # make sure position=1 is first
        self.assertEqual(str(comps[1].Type), "submission.models.code.Code")
        self.assertEqual(str(comps[2].Type), "submission.models.url.URL")
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:27,代码来源:tests.py

示例2: test_course_page

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_course_page(self):
        """
        Check out a course front-page
        """
        _, c = create_offering()
        
        client = Client()
        # not logged in: should be redirected to login page
        response = client.get(c.get_absolute_url())
        self.assertEqual(response.status_code, 302)

        # log in as student "0aaa0"
        client.login_user("0aaa0")
        p = Person.objects.get(userid="0aaa0")

        # not in the course: should get 403 Forbidden
        response = client.get(c.get_absolute_url())
        self.assertEqual(response.status_code, 403)
        
        # add to course and try again
        m = Member(person=p, offering=c, role="STUD", credits=3, career="UGRD", added_reason="UNK")
        m.save()
        response = client.get(c.get_absolute_url())
        self.assertEqual(response.status_code, 200)
        validate_content(self, response.content, c.get_absolute_url())

        # dropped students should be forbidden
        m.role="DROP"
        m.save()
        response = client.get(c.get_absolute_url())
        self.assertEqual(response.status_code, 403)
开发者ID:sfu-fas,项目名称:coursys,代码行数:33,代码来源:tests.py

示例3: create_grades

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
def create_grades():
    """
    Test data for grades, marking, submission, groups
    """
    undergrads = list(Person.objects.filter(last_name='Student'))
    grads = list(Person.objects.filter(last_name='Grad').exclude(userid='0ggg0'))
    for o in CourseOffering.objects.all():
        # TA
        m = Member(person=random.choice(grads), role='TA', offering=o, credits=0, career='NONS', added_reason='TAC')
        m.config['bu'] = 5
        m.save()

        # students
        if o.slug == TEST_COURSE_SLUG:
            # there are some specific students we need in this offering for the marking/testfiles/* imports
            students = set(random.sample(undergrads, 6) + list(Person.objects.filter(userid__in=['0aaa0', '0aaa1', '0aaa2'])))
        else:
            students = random.sample(undergrads, 4)

        for p in students:
            Member.objects.get_or_create(person=p, role='STUD', offering=o, credits=3, career='UGRD', added_reason='AUTO')

    return itertools.chain(
        Holiday.objects.filter(semester__name__gt=SEMESTER_CUTOFF),
        MeetingTime.objects.all(),
        Member.objects.filter(role__in=['TA', 'STUD']),
        create_test_offering(),
    )
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:30,代码来源:devtest_importer.py

示例4: test_sort_letter

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_sort_letter(self):
        """
        Test sorting letter grades
        """
        s, c = create_offering()
        
        a = LetterActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, due_date=None, group=False)
        a.save()

        ms = []
        for i in range(10):
            p = Person.objects.get(userid="0aaa%i"%i)
            m = Member(person=p, offering=c, role="STUD", added_reason="UNK")
            m.save()
            ms.append(m)
        
        g = LetterGrade(activity=a, member=ms[0], letter_grade="B+", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[1], letter_grade="A", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[2], letter_grade="D", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[3], letter_grade="B-", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[4], letter_grade="P", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[5], letter_grade="GN", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[6], letter_grade="F", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[7], letter_grade="DE", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[8], letter_grade="C-", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[9], letter_grade="N", flag="GRAD")
        g.save(entered_by='ggbaker')
        
        g_objs = LetterGrade.objects.filter(activity=a)
        gs = [g.letter_grade for g in g_objs]
        gs_sort = sorted_letters(gs)
        self.assertEquals(gs_sort, ['A', 'B+', 'B-', 'C-', 'D', 'P', 'F', 'DE', 'N', 'GN'])
        
        # pre-sort by userid for median testing (so we know which subsets we're grabbing)
        gs = [(int(g.member.person.userid[4:]), g.letter_grade) for g in g_objs]
        gs.sort()
        gs = [g for u,g in gs]

        # odd-length case
        self.assertEquals(median_letters(sorted_letters(gs[0:5])), "B-")
        # even length with median at boundary
        self.assertEquals(median_letters(sorted_letters(gs[0:6])), "B-/D")
        # empty list
        self.assertEquals(median_letters([]), u"\u2014")
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:55,代码来源:tests.py

示例5: test_group_submission_view

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_group_submission_view(self):
        """
        test if group submission can be viewed by group member and non group member
        """
        now = datetime.datetime.now()
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date=now, group=True)
        a1.save()
        a2 = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=course, position=1, max_grade=15, due_date=now, group=True)
        a2.save()
        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()
        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1, title="Archive File", position=1, max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c3.save()

        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        for u in [userid1, userid2,userid3]:
            p = Person.objects.get(userid=u)
            m = Member(person=p, offering=course, role="STUD", credits=3, career="UGRD", added_reason="UNK")
            m.save()
        m = Member.objects.get(person__userid=userid1, offering=course)
        g = Group(name="Test Group", manager=m, courseoffering=course)
        g.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        m = Member.objects.get(person__userid=userid2, offering=course)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        m = Member.objects.get(person__userid=userid3, offering=course)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()

        client = Client()
        # login as "0aaa0", member of group : test_group for assignment1 and assgnment2
        client.login_user("0aaa0")

        #submission page for assignment 1
        url = reverse('submission.views.show_components', kwargs={'course_slug': course.slug,'activity_slug':a1.slug})
        response = basic_page_tests(self, client, url)
        self.assertContains(response, "This is a group submission. You will submit on behalf of the group Test Group.")
        self.assertContains(response, "You haven't made a submission for this component.")
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:54,代码来源:tests.py

示例6: test_upload

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_upload(self):
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date=datetime.datetime.now() + datetime.timedelta(hours=1), group=False)
        a1.save()
        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()
        c = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c.save()

        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        for u in [userid1, userid2,userid3]:
            p = Person.objects.get(userid=u)
            m = Member(person=p, offering=course, role="STUD", credits=3, career="UGRD", added_reason="UNK")
            m.save()
        
        # submit as student
        client = Client()
        client.login_user("0aaa0")
        url = reverse('submission.views.show_components', kwargs={'course_slug': course.slug,'activity_slug':a1.slug})
        response = basic_page_tests(self, client, url)

        # submit a file
        tmpf = tempfile.NamedTemporaryFile(suffix=".py", delete=False)
        codecontents = 'print "Hello World!"\n'
        tmpf.write(codecontents)
        tmpf.close()

        try:
            fh = open(tmpf.name, "r")
            data = {"%i-code" % (c.id): fh}
            response = client.post(url, data)
            self.assertEquals(response.status_code, 302)
            
        finally:
            os.unlink(tmpf.name)

        # make sure it's there and correct
        subs = StudentSubmission.objects.all()
        self.assertEquals(len(subs), 1)
        sub = subs[0]
        self.assertEquals(sub.member.person.userid, '0aaa0')
            
        codes = SubmittedCode.objects.all()
        self.assertEquals(len(codes), 1)
        code = codes[0]
        code.code.open()
        self.assertEquals(code.code.read(), codecontents)
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:52,代码来源:tests.py

示例7: fill_courses

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
def fill_courses():
    """
    Put 10 students and a TA in each course.
    """
    global all_students
    for crs in CourseOffering.objects.exclude(component="CAN"):
        lett = random.choice(string.ascii_lowercase)
        for i in range(10):
            userid = "0%s%i" % (lett*3, i)
            m = Member(person=all_students[userid], offering=crs, role="STUD", credits=3, career="UGRD", added_reason="AUTO")
            m.save()

        # and the TA
        userid = "0%sgrad" % (lett*3)
        m = Member(person=all_students[userid], offering=crs, role="TA", credits=0, career="NONS", added_reason="AUTO")
        m.save()
开发者ID:sfu-fas,项目名称:coursys,代码行数:18,代码来源:demodata_importer.py

示例8: test_activity_pages

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_activity_pages(self):
        """
        Test pages around activities
        """
        s, c = create_offering()

        # add some assignments and members
        a = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, max_grade=15, percent=10)
        a.save()
        a1=a
        a = NumericActivity(name="Assignment 2", short_name="A2", status="URLS", offering=c, position=6, max_grade=20, group=True)
        a.save()
        p = Person.objects.get(userid="ggbaker")
        m = Member(person=p, offering=c, role="INST", added_reason="UNK")
        m.save()
        p = Person.objects.get(userid="0aaa0")
        m = Member(person=p, offering=c, role="STUD", added_reason="UNK")
        m.save()
        
        # test instructor pages
        client = Client()
        client.login_user("ggbaker")

        response = basic_page_tests(self, client, '/' + c.slug + '/')
        self.assertContains(response, 'href="' + reverse('groups.views.groupmanage', kwargs={'course_slug':c.slug}) +'"')

        basic_page_tests(self, client, c.get_absolute_url())
        basic_page_tests(self, client, reverse('grades.views.student_info', kwargs={'course_slug': c.slug, 'userid': '0aaa0'}))
        basic_page_tests(self, client, reverse('grades.views.add_numeric_activity', kwargs={'course_slug':c.slug}))
        basic_page_tests(self, client, reverse('grades.views.add_letter_activity', kwargs={'course_slug':c.slug}))

        # test student pages
        client = Client()
        client.login_user("0aaa0")
        response = basic_page_tests(self, client, '/' + c.slug + '/')
        self.assertContains(response, "Gregory Baker")
        self.assertContains(response, 'href="' + reverse('groups.views.groupmanage', kwargs={'course_slug':c.slug}) +'"')

        response = basic_page_tests(self, client, a.get_absolute_url())
        # small class (one student) shouldn't contain summary stats
        self.assertNotContains(response, "Histogram")
        self.assertNotContains(response, "Standard Deviation")
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:44,代码来源:tests.py

示例9: test_component_view_page

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_component_view_page(self):
        _, course = create_offering()
        a1 = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=course, position=2, max_grade=15, due_date="2010-04-01")
        a1.save()
        a2 = NumericActivity(name="Assignment 2", short_name="A2", status="RLS", offering=course, position=1, max_grade=15, due_date="2010-03-01")
        a2.save()

        p = Person.objects.get(userid="ggbaker")
        member = Member(person=p, offering=course, role="INST", career="NONS", added_reason="UNK")
        member.save()

        c1 = URL.Component(activity=a1, title="URL Link", position=8)
        c1.save()
        c2 = Archive.Component(activity=a1, title="Archive File", position=1, max_size=100000)
        c2.save()
        c3 = Code.Component(activity=a1, title="Code File", position=3, max_size=2000, allowed=".py")
        c3.save()
        client = Client()
        client.login_user("ggbaker")
        
        # When no component, should display error message
        url = reverse('submission.views.show_components', kwargs={'course_slug':course.slug, 'activity_slug':a2.slug})
        response = basic_page_tests(self, client, url)
        self.assertContains(response, 'No components configured.')
        # add component and test
        component = URL.Component(activity=a2, title="URL2", position=1)
        component.save()
        component = Archive.Component(activity=a2, title="Archive2", position=1, max_size=100)
        component.save()
        # should all appear
        response = basic_page_tests(self, client, url)
        self.assertContains(response, "URL2")
        self.assertContains(response, "Archive2")
        # make sure type displays
        #self.assertContains(response, '<li class="view"><label>Type:</label>Archive</li>')
        # delete component
        self.assertRaises(NotImplementedError, component.delete)
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:39,代码来源:tests.py

示例10: test_course_offering

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_course_offering(self):
        """
        Create and test a course offering
        """
        s, c = create_offering()
        
        # should have a get_absolute_url
        url = c.get_absolute_url()
        self.assertEquals(url, str(url))
        self.assertEquals(url[0], '/')
        self.assertEquals(str(c), "CMPT 120 D100 (Fall 2007)")
        self.assertEquals(c.name(), "CMPT 120 D1")

        # check uniqueness criteria
        c2 = CourseOffering(subject="CMPT", number="120", section="D100", semester=s, component="LAB",
                graded=True, crse_id=11112, class_nbr=22223, campus='SURRY',
                enrl_cap=101, enrl_tot=100, wait_tot=3)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, c2.save)

        c2 = CourseOffering(subject="CMPT", number="121", section="D100", semester=s, component="LAB",
                graded=True, crse_id=11111, class_nbr=22223, campus='SURRY',
                enrl_cap=101, enrl_tot=100, wait_tot=3)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, c2.save)

        c2 = CourseOffering(subject="MACM", number="121", section="D102", semester=s, component="LAB",
                graded=True, crse_id=11112, class_nbr=22222, campus='SURRY',
                enrl_cap=101, enrl_tot=100, wait_tot=3)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, c2.save)

        # test some course memberships
        p1 = Person(emplid=210012345, userid="test1",
                last_name="Lname", first_name="Fname", pref_first_name="Fn", middle_name="M")
        p1.save()
        m = Member(person=p1, offering=c, role="INST", credits=0, career="NONS", added_reason="AUTO")
        m.save()
        
        self.assertEqual( str(list(c.instructors())), "[<Person: Lname, Fname>]")
        self.assertEqual( str(list(c.tas())), "[]")
        self.assertEqual( c.student_count(), 0)

        m.role = "TA"
        m.save()
        self.assertEqual( str(list(c.instructors())), "[]")
        self.assertEqual( str(list(c.tas())), "[<Person: Lname, Fname>]")
        self.assertEqual( c.student_count(), 0)

        m.role = "STUD"
        m.save()
        self.assertEqual( str(list(c.instructors())), "[]")
        self.assertEqual( str(list(c.tas())), "[]")
        self.assertEqual( c.student_count(), 1)
        
        self.assertEqual( str(m), "test1 (210012345) in CMPT 120 D100 (Fall 2007)")
开发者ID:avacariu,项目名称:coursys,代码行数:58,代码来源:tests.py

示例11: test_group_change

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_group_change(self):
        """
        Test changing group <-> individual on an activity.  Should only be possible in some conditions.
        """
        s, c = create_offering()

        # add some assignments and members
        due = datetime.datetime.now() + datetime.timedelta(days=1)
        due_date = str(due.date())
        due_time = due.time().strftime("%H:%M:%S")
        a = NumericActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, max_grade=15, percent=10, due_date=due, group=False)
        a.save()
        p = Person.objects.get(userid="ggbaker")
        m = Member(person=p, offering=c, role="INST", added_reason="UNK")
        m.save()
        p = Person.objects.get(userid="0aaa0")
        m = Member(person=p, offering=c, role="STUD", added_reason="UNK")
        m.save()
        
        client = Client()
        client.login_user("ggbaker")
        url = reverse('grades.views.edit_activity', kwargs={'course_slug': c.slug, 'activity_slug': a.slug})

        # for whatever reason, '0' is group and '1' is individual for the group value
        submit_dict = {'name': a.name, 'short_name': a.short_name, 'status': a.status, 'due_date_0': due_date, 'due_date_1': due_time, 'percent': a.percent, 'max_grade': a.max_grade, 'group': '1', 'extend_group': 'None'}
        # no change
        response = client.post(url, submit_dict)
        self.assertEquals(response.status_code, 302) # successful submit -> redirect
        self.assertEquals(NumericActivity.objects.get(id=a.id).group, False)

        # change indiv -> group
        submit_dict['group'] = '0'
        response = client.post(url, submit_dict)
        self.assertEquals(response.status_code, 302)
        self.assertEquals(NumericActivity.objects.get(id=a.id).group, True)
        
        # try with activity past due
        a.due_date = datetime.datetime.now() - datetime.timedelta(days=1)
        a.save()
        submit_dict['due_date_0'] = str(a.due_date.date())
        submit_dict['group'] = '0'
        response = client.post(url, submit_dict)
        self.assertEquals(response.status_code, 200) # error on form -> 200 and back to form with error
        self.assertContains(response, "due date has passed")
        
        # try with a mark in the system
        a.due_date = datetime.datetime.now() + datetime.timedelta(days=1)
        a.save()
        submit_dict['due_date_0'] = str(a.due_date.date())
        submit_dict['group'] = '0'
        g = NumericGrade(activity=a, member=m, value=2, flag="GRAD")
        g.save(entered_by='ggbaker')
        response = client.post(url, submit_dict)
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, "grades have already been given")
        
        # try with a submission in the system
        g.flag = "NOGR"
        g.save(entered_by='ggbaker')
        s = StudentSubmission(activity=a, member=m)
        s.save()
        response = client.post(url, submit_dict)
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, "submissions have already been made")
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:66,代码来源:tests.py

示例12: test_group_models

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_group_models(self):
        """
        Test the backend for groups
        """
        s, c = create_offering()
        a = NumericActivity(name="Assignment 1", short_name="A1", status="URLS", offering=c, position=3, max_grade=20, group=True)
        a.save()
        a1 = a
        a = NumericActivity(name="Assignment 2", short_name="A2", status="URLS", offering=c, position=6, max_grade=20, group=True)
        a.save()
        a2 = a
        
        userid1 = "0aaa4"
        userid2 = "0aaa0"
        userid3 = "0aaa1"
        userid4 = "0aaa2"
        for u in [userid1, userid2, userid3, userid4]:
            p = Person.objects.get(userid=u)
            m = Member(person=p, offering=c, role="STUD", credits=3, career="UGRD", added_reason="UNK")
            m.save()
        
        # basics
        m = Member.objects.get(person__userid=userid1, offering=c)
        g = Group(name="Test Group", manager=m, courseoffering=c)
        g.save()
        self.assertEqual(g.slug, 'g-test-group')
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        m = Member.objects.get(person__userid=userid2, offering=c)
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        gm.save()
        
        gs = Group.objects.filter(courseoffering=c)
        self.assertEqual(len(gs), 1)
        g = gs[0]
        self.assertEqual(set([gm.student.person.userid for gm in g.groupmember_set.all()]), set([userid1,userid2]))

        # check uniqueness of activity + member        
        m = Member.objects.get(person__userid=userid3, offering=c)
        g2 = Group(name="Other Group", manager=m, courseoffering=c)
        g2.save()
        gm = GroupMember(group=g2, student=m, confirmed=True, activity=a1)
        gm.save()
        
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a1)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, gm.save)
        
        # uniqueness of group name
        g3 = Group(name="Other Group", manager=m, courseoffering=c)
        # south doesn't seem to create the constraints in SQLite for testing
        #self.assertRaises(IntegrityError, g3.save)
        
        # finding all activities this group covers
        members = GroupMember.objects.filter(group=g)
        all_act = all_activities(members)
        self.assertEqual(set(a.slug for a in all_act), set([a1.slug]))

        # add a member for assignment 2 and check again
        gm = GroupMember(group=g, student=m, confirmed=True, activity=a2)
        gm.save()
        members = GroupMember.objects.filter(group=g)
        all_act = all_activities(members)
        self.assertEqual(set(a.slug for a in all_act), set([a1.slug, a2.slug]))
        
        # check student-editable tests
        
        # test dates
        m = Member.objects.get(offering=c, person__userid="0aaa0")
        gm = GroupMember.objects.get(group=g, student=m, activity=a1)

        a1.due_date = datetime.datetime.now() - datetime.timedelta(days=1) # yesterday
        a1.save()
        self.assertTrue("passed" in gm.student_editable("0aaa0"))

        a1.due_date = datetime.datetime.now() + datetime.timedelta(days=1) # tomorrow
        a1.save()
        gm = GroupMember.objects.get(group=g, student=m, activity=a1)
        self.assertEqual(gm.student_editable("0aaa0"), '')

        # not member for this activity
        self.assertTrue("not a member" in gm.student_editable("0aaa1"))
        
        # already graded
        gr = NumericGrade(activity=a1, member=m, value=1, flag="GRAD")
        gr.save(entered_by='ggbaker')
        self.assertTrue("grade" in gm.student_editable("0aaa0"))
        gr.flag="NOGR"
        gr.save(entered_by='ggbaker')
        self.assertEqual(gm.student_editable("0aaa0"), '')
        
        # submission made
        s = GroupSubmission(group=g, creator=m, activity=a1)
        s.save()
        self.assertTrue("submission" in gm.student_editable("0aaa0"))
开发者ID:avacariu,项目名称:coursys,代码行数:97,代码来源:tests.py

示例13: test_instructor_workflow

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def test_instructor_workflow(self):
        """
        Work through the site as an instructor
        """
        s, c = create_offering()
        userid1 = "0aaa0"
        userid2 = "0aaa1"
        userid3 = "0aaa2"
        userid4 = "ggbaker"
        for u in [userid1, userid2, userid3, userid4]:
            p = Person.objects.get(userid=u)
            m = Member(person=p, offering=c, role="STUD", credits=3, career="UGRD", added_reason="UNK")
            m.save()
        m.role="INST"
        m.save()
        
        client = Client()
        client.login_user("ggbaker")
        
        # course main screen
        url = reverse('grades.views.course_info', kwargs={'course_slug': c.slug})
        response = basic_page_tests(self, client, url)
        url = reverse('grades.views.activity_choice', kwargs={'course_slug': c.slug})
        self.assertContains(response, 'href="' + url +'"')
        url = reverse('grades.views.add_numeric_activity', kwargs={'course_slug': c.slug})
        response = basic_page_tests(self, client, url)
        
        # add activity
        import datetime
        now = datetime.datetime.now()
        due = now + datetime.timedelta(days=7)
        response = client.post(url, {'name':'Assignment 1', 'short_name':'A1', 'status':'URLS', 'due_date_0':due.strftime('%Y-%m-%d'), 'due_date_1':due.strftime('%H:%M:%S'), 'percent': '10', 'group': '1', 'max_grade': 25, 'extend_group': 'None'})
        self.assertEquals(response.status_code, 302)
        
        acts = NumericActivity.objects.filter(offering=c)
        self.assertEquals(len(acts), 1)
        a = acts[0]
        self.assertEquals(a.name, "Assignment 1")
        self.assertEquals(a.slug, "a1")
        self.assertEquals(a.max_grade, 25)
        self.assertEquals(a.group, False)
        self.assertEquals(a.deleted, False)
        
        # add calculated numeric activity
        url = reverse('grades.views.add_cal_numeric_activity', kwargs={'course_slug': c.slug})
        response = basic_page_tests(self, client, url)
        response = client.post(url, {'name':'Total', 'short_name':'Total', 'status':'URLS', 'group': '1', 'max_grade': 30, 'formula': '[A1]+5'})
        self.assertEquals(response.status_code, 302)

        acts = CalNumericActivity.objects.filter(offering=c)
        self.assertEquals(len(acts), 1)
        a = acts[0]
        self.assertEquals(a.slug, "total")
        self.assertEquals(a.max_grade, 30)
        self.assertEquals(a.group, False)
        self.assertEquals(a.deleted, False)
        self.assertEquals(a.formula, '[A1]+5')
        
        # formula tester
        url = reverse('grades.views.formula_tester', kwargs={'course_slug': c.slug})
        response = basic_page_tests(self, client, url)
        response = client.get(url, {'formula': '[A1]+5', 'a1-status': 'RLS', 'a1-value': '6', 'total-status': 'URLS'})
        self.assertContains(response, '<div id="formula_result">11.0</div>')
        validate_content(self, response.content, url)
开发者ID:tedkirkpatrick,项目名称:coursys,代码行数:66,代码来源:tests.py

示例14: sync_course_member

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
    def sync_course_member(self):
        """
        Once a contract is Signed, we should create a Member object for them.
        If a contract is Cancelled, we should DROP the Member object. 

        This operation should be idempotent - run it as many times as you
        want, the result should always be the same. 
        """
        # if signed, create the Member objects so they have access to the courses.
        courses = self.course.all()
        for crs in courses:
            members = Member.objects.filter(person=self.person, 
                                            role='TA',
                                            offering=crs.course)
            # the student should either be in the course (1) or not (0)
            # any other number of responses is unacceptable. 
            assert( len(members) == 1 or len(members) == 0 )


            dropped_members = Member.objects.filter(person=self.person, 
                                                    offering=crs.course, 
                                                    role='DROP')
            
            assert( len(dropped_members) == 1 or len(dropped_members) == 0)

            # this shouldn't be. 
            if members and dropped_members:
                d = dropped_members[0]
                d.delete()
                dropped_members = []
           
            # the student must be in one of these three states
            exists_and_is_in_the_course = len(members) > 0
            exists_and_is_dropped = len(dropped_members) > 0
            does_not_exist = len(members) == 0 and len(dropped_members) == 0
            
            assert(exists_and_is_in_the_course or exists_and_is_dropped or does_not_exist)            
            assert(not(exists_and_is_in_the_course and exists_and_is_dropped))
            assert(not(exists_and_is_dropped and does_not_exist))
            assert(not(exists_and_is_in_the_course and does_not_exist))
            assert(len(dropped_members) < 2)
            assert(len(members) < 2)

            if self.should_be_added_to_the_course:
                if exists_and_is_dropped:
                    m = dropped_members[0]
                elif exists_and_is_in_the_course:
                    m = members[0]
                elif does_not_exist:
                    m = Member(person=self.person, 
                               offering=crs.course, 
                               role='TA',
                               added_reason='TAC',
                               credits=0, 
                               career='NONS')
                else:
                    assert(False)
                m.added_reason='TAC'
                m.role = 'TA'
                m.config['bu'] = crs.total_bu
                m.save()
                crs.member = m
                crs.save(always_allow=True)
            else:
                if exists_and_is_dropped:
                    pass
                elif exists_and_is_in_the_course:
                    m = members[0]
                    if m.added_reason == 'TAC':
                        m.role = 'DROP'
                        m.save()
                    crs.member = None
                    crs.save(always_allow=True)
                elif does_not_exist:
                    pass

        # If they are TAC-added members of any other course this semester,
        #    they probably shouldn't be.
        members = Member.objects.filter(person=self.person, 
                                        role='TA', 
                                        added_reason='TAC',
                                        offering__semester=self.category.hiring_semester.semester)
        
        courseofferings = [crs.course for crs in courses]
        for member in members:
            if member.offering not in courseofferings:
                member.role = 'DROP'
                member.save()
开发者ID:avacariu,项目名称:coursys,代码行数:90,代码来源:models.py

示例15: test_class_1

# 需要导入模块: from coredata.models import Member [as 别名]
# 或者: from coredata.models.Member import save [as 别名]
def test_class_1(slug):
    """
    main test course: 20 students, TA, some assignments
    """
    crs = CourseOffering.objects.get(slug=slug)
    
    crs.set_labtut(True)
    crs.set_url("http://www.cs.sfu.ca/CC/165/common/")
    crs.set_taemail("[email protected]")
    crs.save()
    for i in range(10):
        lab = "D1%02i" % (random.randint(1,4))
        p = Person.objects.get(userid="0aaa%i"%(i))
        if Member.objects.filter(person=p, offering=crs, role="STUD"):
            # randomly added by other student-adder: skip
            continue

        m = Member(person=p, offering=crs, role="STUD", credits=3, career="UGRD", added_reason="AUTO",
                labtut_section=lab)
        m.save()
    
    if not Member.objects.filter(person__userid='ggbaker', offering=crs, role='INST'):
        Member(person=Person.objects.get(userid='ggbaker'), offering=crs, role='INST').save()
    
    # create a TA
    p = Person(emplid=fake_emplid(), userid="0grad1", last_name="Gradstudent", first_name="Douglas", middle_name="", pref_first_name="Doug")
    p.save()
    m = Member(person=p, offering=crs, role="TA", credits=0, career="NONS", added_reason="AUTO",
            labtut_section=None)
    m.save()
    
    
    # create example activities
    crs.activity_set.all().update(deleted=True)
    a1 = NumericActivity(offering=crs, name="Assignment 1", short_name="A1", status="RLS",
        due_date=crs.semester.start + datetime.timedelta(days=60), percent=10, group=False,
        max_grade=10, position=1)
    a1.set_url("http://www.cs.sfu.ca/CC/165/common/a1")
    a1.save()
    a2 = NumericActivity(offering=crs, name="Assignment 2", short_name="A2", status="URLS",
        due_date=crs.semester.start + datetime.timedelta(days=70), percent=10, group=True,
        max_grade=20, position=2)
    a2.save()
    pr = LetterActivity(offering=crs, name="Project", short_name="Proj", status="URLS",
        due_date=crs.semester.start + datetime.timedelta(days=80), percent=40, group=True, position=3)
    pr.save()
    re = LetterActivity(offering=crs, name="Report", short_name="Rep", status="URLS",
        due_date=crs.semester.start + datetime.timedelta(days=81), percent=10, group=False, position=4)
    re.save()
    ex = NumericActivity(offering=crs, name="Final Exam", short_name="Exam", status="URLS",
        due_date=None, percent=30, group=False, max_grade=90, position=5)
    ex.save()
    to = CalNumericActivity(offering=crs, name="Final Percent", short_name="Perc", status="INVI",
        due_date=None, percent=0, group=False, max_grade=100, formula="[[activitytotal]]", position=6)
    to.save()
    to = CalLetterActivity(offering=crs, name="Letter Grade", short_name="Letter", status="INVI",
        due_date=None, percent=0, group=False, numeric_activity=to, position=6)
    to.save()
    
    # make A1 submittable and markable
    s = CodeComponent(activity=a1, title="Code File", description="The code you're submitting.",
        allowed=".py,.java")
    s.save()
    s = PDFComponent(activity=a1, title="Report", description="Report on what you did.",
        specified_filename="report.pdf")
    s.save()
    
    m = ActivityComponent(numeric_activity=a1, max_mark=5, title="Part 1", description="Part 1 was done well and seems to work.", position=1)
    m.save()
    m = ActivityComponent(numeric_activity=a1, max_mark=5, title="Part 2", description="Part 2 was done well and seems to work.", position=2)
    m.save()
    
    # create some groups
    g = Group(name="SomeGroup", courseoffering=crs, manager=Member.objects.get(offering=crs, person__userid="0aaa0", role='STUD'))
    g.save()
    for userid in ['0aaa0', '0aaa1', '0aaa5', '0aaa8']:
        gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=a2)
        gm.save()
    
    g = Group(name="AnotherGroup", courseoffering=crs, manager=Member.objects.get(offering=crs, person__userid="0aaa4"))
    g.save()
    for userid in ['0aaa4', '0aaa6', '0aaa7', '0aaa2']:
        gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=a2)
        gm.save()
        gm = GroupMember(group=g, student=Member.objects.get(offering=crs, person__userid=userid), confirmed=True, activity=pr)
        gm.save()
开发者ID:avacariu,项目名称:coursys,代码行数:88,代码来源:devdata_importer.py


注:本文中的coredata.models.Member.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。