コード例 #1
0
ファイル: views.py プロジェクト: tomasd/schools-old
def _course_attendance_list_detail(request, course, course_lesson, attendance_list):
    course_members = CourseMember.objects.filter(lessonattendee__attendance_list=attendance_list)
    checked_course_members = {
        "course_members": [a.course_member.pk for a in attendance_list.lessonattendee_set.all() if a.present]
    }
    if request.method == "POST":
        form = AttendanceListForm(request.POST, instance=attendance_list)
        attendee_form = LessonAttendeeCreateForm(course_members, request.POST, initial=checked_course_members)
        if form.is_valid() and attendee_form.is_valid():
            form.instance.lector_price = lector_price(
                form.cleaned_data["lector"], course, form.cleaned_data["start"], form.cleaned_data["end"]
            )
            attendance_list = form.save()

            for lesson_attendee in attendance_list.lessonattendee_set.all():
                lesson_attendee.present = lesson_attendee.course_member in attendee_form.cleaned_data["course_members"]
                lesson_attendee.course_member_price = course_member_price(
                    lesson_attendee.course_member, attendance_list.start, attendance_list.end, course_members
                )
                lesson_attendee.save()

    else:
        form = AttendanceListForm(instance=attendance_list)
        attendee_form = LessonAttendeeCreateForm(course_members, initial=checked_course_members)
    return render_to_response(
        "courses/course_attendance_list_form.html",
        {"lesson_list": course.lesson_set.all(), "course": course, "form": form, "attendee_form": attendee_form},
        context_instance=RequestContext(request),
    )
コード例 #2
0
ファイル: views.py プロジェクト: tomasd/schools-old
 def testAttendaceList(self):
     lesson = Lesson.objects.get(pk=1)
     
     try:
         # delete existing attendance list to simulate that one is created,
         # when accessing it
         lesson.attendancelist.delete()
     except AttendanceList.DoesNotExist: #@UndefinedVariable
         pass
     
     response = self.client.get(lesson.get_attendance_list_url())
     eq_(200, response.status_code)
     
     data = {'classroom':'1', 'start':'2008-01-01', 'end':'2008-01-01 01:00',
                  'lector':'1', 'course_members':['1','2']}
     
     response = self.client.post(lesson.get_attendance_list_url(), data)
     self.assertRedirects(response, lesson.get_attendance_list_url())
     
     lesson = Lesson.objects.get(pk=1)
     eq_(lector_price(Lector.objects.get(pk=1), Course.objects.get(pk=1), datetime(2008, 1, 1), datetime(2008, 1, 1, 1)),
         lesson.attendancelist.lector_price)
     eq_([True,True,False], [a.present for a in lesson.attendancelist.lessonattendee_set.all()])
     
     data['course_members'] = ['1', '3']
     response = self.client.post(lesson.get_attendance_list_url(), data)
     eq_([True,False,True], [a.present for a in lesson.attendancelist.lessonattendee_set.all()])
コード例 #3
0
ファイル: models.py プロジェクト: tomasd/schools-old
 def testLectorPrice(self):
     lector = Lector.objects.get(pk=1)
     course1 = Course.objects.get(pk=1)
     course2 = Course.objects.get(pk=2)
     
     # price from hour rate
     price = lector_price(lector, course1, datetime(2008,1,1,19), datetime(2008,1,1,20,30))
     eq_(Decimal(str(500*1.5)), price)
     
     # price from contract
     price = lector_price(lector, course2, datetime(2008,1,1,19), datetime(2008,1,1,20,30))
     eq_(Decimal(str(300*1.5)), price)
     
     # price from hour rate
     price = lector_price(lector, course1, datetime(2008,1,2,19), datetime(2008,1,3,20,30))
     eq_(Decimal(str(600*25.5)), price)
     
     # price from contract
     price = lector_price(lector, course2, datetime(2008,1,2,19), datetime(2008,1,3,20,30))
     eq_(Decimal(str(400*25.5)), price)
     
     
コード例 #4
0
ファイル: views.py プロジェクト: tomasd/schools-old
def _course_attendance_list_create(request, course, course_lesson, attendance_list):
    if request.method == "POST":
        form = AttendanceListForm(request.POST, instance=attendance_list)
        start, end = (
            (form.cleaned_data["start"], form.cleaned_data["end"])
            if form.is_valid()
            else (attendance_list.start, attendance_list.end)
        )
        course_members = course_members_on_lesson(course, start, end)
        attendee_form = LessonAttendeeCreateForm(course_members, request.POST)

        if form.is_valid() and attendee_form.is_valid():
            form.instance.lector_price = lector_price(
                form.cleaned_data["lector"], course, form.cleaned_data["start"], form.cleaned_data["end"]
            )
            attendance_list = form.save()

            for course_member in course_members:
                attendee = {
                    "present": course_member in attendee_form.cleaned_data["course_members"],
                    "course_member": course_member,
                    "course_member_price": course_member_price(course_member, start, end, course_members),
                }
                attendance_list.lessonattendee_set.create(**attendee)

            return HttpResponseRedirect(attendance_list.get_absolute_url())
    else:
        form = AttendanceListForm(instance=attendance_list)
        attendee_form = LessonAttendeeCreateForm(
            course_members_on_lesson(course, attendance_list.start, attendance_list.end)
        )
    return render_to_response(
        "courses/course_attendance_list_create.html",
        {"form": form, "attendee_form": attendee_form, "lesson_list": course.lesson_set.all(), "course": course},
        context_instance=RequestContext(request),
    )