本文整理汇总了Python中coredata.models.Member类的典型用法代码示例。如果您正苦于以下问题:Python Member类的具体用法?Python Member怎么用?Python Member使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Member类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_components
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")
示例2: create_grades
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(),
)
示例3: daily_cleanup
def daily_cleanup():
logger.info('Cleaning up database')
# cleanup sessions table
call_command('clearsessions')
# cleanup old news items
NewsItem.objects.filter(updated__lt=datetime.datetime.now()-datetime.timedelta(days=365)).delete()
# cleanup old log entries
LogEntry.objects.filter(datetime__lt=datetime.datetime.now()-datetime.timedelta(days=365)).delete()
# cleanup old official grades
Member.clear_old_official_grades()
示例4: test_sort_letter
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")
示例5: test_course_offering
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)")
示例6: index
def index(request):
userid = request.user.username
memberships, excluded = Member.get_memberships(userid)
staff_memberships = [m for m in memberships if m.role in ['INST', 'TA', 'APPR']] # for docs link
is_instructor = len([m for m in memberships if m.role == 'INST']) > 0 # For TUGs link
news_list = _get_news_list(userid, 5)
roles = Role.all_roles(userid)
is_grad = GradStudent.objects.filter(person__userid=userid, current_status__in=STATUS_ACTIVE).exists()
has_grads = Supervisor.objects.filter(supervisor__userid=userid, supervisor_type='SEN', removed=False).exists()
form_groups = FormGroup.objects.filter(members__userid=request.user.username).exists()
has_ras = RAAppointment.objects.filter(hiring_faculty__userid=request.user.username, deleted=False).exists()
# Only CMPT admins should see the one different TA module. Only non-CMPT TA Admins should see the other.
# re-factored to take into account the very few people who should see both (mainly FAS Departmental Admins)
cmpt_taadmn = Role.objects_fresh.filter(person__userid=userid, role='TAAD', unit__label__in=['CMPT', 'SEE']).exists()
other_taadmn = Role.objects_fresh.filter(person__userid=userid, role='TAAD').exclude(unit__label__in=['CMPT', 'SEE']).exists()
context = {'memberships': memberships,
'staff_memberships': staff_memberships,
'news_list': news_list,
'roles': roles,
'is_grad':is_grad,
'has_grads': has_grads,
'has_ras': has_ras,
'excluded': excluded,
'form_groups': form_groups,
'cmpt_taadmn': cmpt_taadmn,
'other_taadmn': other_taadmn,
'is_instructor': is_instructor}
return render(request, "dashboard/index.html", context)
示例7: ensure_member
def ensure_member(person, offering, role, cred, added_reason, career, labtut_section=None, grade=None):
"""
Make sure this member exists with the right properties.
"""
if person.emplid in [200133427, 200133425, 200133426]:
# these are: ["Faculty", "Tba", "Sessional"]. Ignore them: they're ugly.
return
m_old = Member.objects.filter(person=person, offering=offering)
if len(m_old)>1:
# may be other manually-created dropped entries: that's okay.
m_old = Member.objects.filter(person=person, offering=offering).exclude(role="DROP")
if len(m_old)>1:
raise KeyError, "Already duplicate entries: %r" % (m_old)
elif len(m_old)==0:
m_old = Member.objects.filter(person=person, offering=offering)
if len(m_old)>=1:
m = m_old[0]
else:
m = Member(person=person, offering=offering)
m.role = role
m.labtut_section = labtut_section
m.credits = cred
m.added_reason = added_reason
m.career = career
# record official grade if we have it (and might need it)
if has_letter_activities(m.offering):
m.official_grade = grade or None
else:
m.official_grade = None
# if offering is being given lab/tutorial sections, flag it as having them
# there must be some way to detect this in ps_class_tbl, but I can't see it.
if labtut_section and not offering.labtut():
offering.set_labtut(True)
offering.save_if_dirty()
m.save_if_dirty()
return m
示例8: get_queryset
def get_queryset(self):
all = self.request.query_params.get('all', None)
if all == 'yes':
memberships = Member.objects.exclude(role="DROP").exclude(offering__component="CAN") \
.filter(offering__graded=True, person__userid=self.request.user.username)
else:
memberships, _ = Member.get_memberships(self.request.user.username)
offerings = [m.offering for m in memberships]
return offerings
示例9: test_course_page
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)
示例10: test_component_view_page
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)
示例11: test_group_submission_view
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.")
示例12: test_upload
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)
示例13: fill_courses
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()
示例14: index
def index(request):
userid = request.user.username
memberships, excluded = Member.get_memberships(userid)
staff_memberships = [m for m in memberships if m.role in ['INST', 'TA', 'APPR']] # for docs link
news_list = _get_news_list(userid, 5)
roles = Role.all_roles(userid)
is_grad = GradStudent.objects.filter(person__userid=userid, current_status__in=STATUS_ACTIVE).count() > 0
has_grads = Supervisor.objects.filter(supervisor__userid=userid, supervisor_type='SEN', removed=False).count() > 0
form_groups = FormGroup.objects.filter(members__userid=request.user.username).count() > 0
#messages.add_message(request, messages.SUCCESS, 'Success message.')
#messages.add_message(request, messages.WARNING, 'Warning message.')
#messages.add_message(request, messages.INFO, 'Info message.')
#messages.add_message(request, messages.ERROR, 'Error message.')
context = {'memberships': memberships,
'staff_memberships': staff_memberships,
'news_list': news_list,
'roles': roles,
'is_grad':is_grad,
'has_grads': has_grads,
'excluded': excluded,
'form_groups': form_groups}
return render(request, "dashboard/index.html", context)
示例15: add_membership_for
def add_membership_for(tacrs, reason, memberships):
if not tacrs.contract.should_be_added_to_the_course or tacrs.total_bu <= 0:
return
# Find existing membership for this person+offering if it exists
# (Behaviour here implies you can't be both TA and other role in one offering: I'm okay with that.)
for m in memberships:
if m.person == person and m.offering == tacrs.course:
break
else:
# there was no membership: create
m = Member(person=person, offering=tacrs.course)
memberships.append(m)
m.role = 'TA'
m.credits = 0
m.career = 'NONS'
m.added_reason = reason
m.config['bu'] = str(tacrs.total_bu)