コード例 #1
0
ファイル: models.py プロジェクト: tomasd/schools-old
    def testCourseMemberPrice(self):
        course_member1 = CourseMember.objects.get(pk=1)
        course_member2 = CourseMember.objects.get(pk=2)
        course_member3 = CourseMember.objects.get(pk=3)

        price = course_member_price(course_member1, datetime(2008, 1, 1, 19), datetime(2008, 1, 1, 20, 30))
        eq_(Decimal(str(60 * 1.5 / 2)), price)

        price = course_member_price(
            course_member1,
            datetime(2008, 1, 1, 19),
            datetime(2008, 1, 1, 20, 30),
            [course_member1, course_member2, course_member3],
        )
        eq_(Decimal(str(60 * 1.5 / 2)), price)
コード例 #2
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),
    )
コード例 #3
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),
    )