Пример #1
0
    def post(self, request, template_name='student/addWorkshop.html'):
        #username=request.POST.get('username')
        name = request.POST.get('name')
        organizer = request.POST.get('organizer')
        location = request.POST.get('location')
        if(request.POST.get('mode')=="Online"):
            mode = True
        else:
            mode = False
        startDate = request.POST.get('startDate')
        endDate = request.POST.get('endDate')
        user = request.user

        try:
            certification = request.FILES['certification']
            fs = FileSystemStorage()
            filename = fs.save(shortuuid.uuid(), certification)
            url = fs.url(filename)
            certification = url
            certBool = True
            publishWorkshop = Work(name=name, organizer=organizer, location=location, mode=mode, startdate=startDate, enddate=endDate, user=user, certification=certification, certBool=certBool)
            publishWorkshop.save()

        except:
            certification = "NA"
            certBool = False
            publishWorkshop = Work(name=name, organizer=organizer, location=location, mode=mode, startdate=startDate, enddate=endDate, user=user, certification=certification, certBool=certBool)
            publishWorkshop.save()

        err = {'error_message': "Workshop Added Successfully."}
        return render(request, template_name, err)
Пример #2
0
def submit(request, index):
    scores = []
    if request.method == 'POST':
        form = SubmitForm(request.POST)
        work = Work.objects.filter(index=index, user_id=request.user.id)
        if not work.exists():
            if form.is_valid():
                work2 = Work(index=index,
                             user_id=request.user.id,
                             number=form.cleaned_data['number'],
                             memo=form.cleaned_data['memo'],
                             publication_date=timezone.now())
                work2.save()
                # credit
                update_avatar(request.user.id, 1, 2)
                # History
                history = PointHistory(
                    user_id=request.user.id,
                    kind=1,
                    message='2分--繳交作業<' + lesson_list[int(index) - 1][2] + '>',
                    url=request.get_full_path().replace("submit", "submitall"))
                history.save()
                # 記錄系統事件
                if is_event_open(request):
                    log = Log(user_id=request.user.id,
                              event=u'新增作業成功<'.encode("UTF-8") +
                              lesson_list[int(index) - 1][2] + '>')
                    log.save()
        else:
            if form.is_valid():
                work.update(number=form.cleaned_data['number'],
                            memo=form.cleaned_data['memo'])
                # 記錄系統事件
                if is_event_open(request):
                    log = Log(user_id=request.user.id,
                              event=u'更新作業成功<'.encode("UTF-8") +
                              lesson_list[int(index) - 1][2] + '>')
                    log.save()
            else:
                work.update(memo=form.cleaned_data['memo'])
            return redirect('/student/submit/' + index)
    else:
        work = Work.objects.filter(index=index, user_id=request.user.id)
        if not work.exists():
            form = SubmitForm()
        else:
            form = SubmitForm(instance=work[0])
            if work[0].scorer > 0:
                score_name = User.objects.get(id=work[0].scorer).first_name
                scores = [work[0].score, score_name]
    lesson = lesson_list[int(index) - 1]
    return render_to_response('student/submit.html', {
        'form': form,
        'scores': scores,
        'index': index,
        'lesson': lesson
    },
                              context_instance=RequestContext(request))
Пример #3
0
def work_group(request, classroom_id):
    # 限本班任課教師
    if not is_teacher(request.user, classroom_id):
        return redirect("/")
    classroom = Classroom.objects.get(id=classroom_id)
    lesson = Classroom.objects.get(id=classroom_id).lesson
    groups = [
        group
        for group in EnrollGroup.objects.filter(classroom_id=classroom_id)
    ]
    enroll_pool = [
        enroll for enroll in Enroll.objects.filter(
            classroom_id=classroom_id).order_by('seat')
    ]
    student_ids = map(lambda a: a.student_id, enroll_pool)
    work_pool = Work.objects.filter(user_id__in=student_ids,
                                    lesson=classroom.lesson)
    user_pool = [
        user for user in User.objects.filter(id__in=work_pool.values('scorer'))
    ]
    assistant_pool = [
        assistant
        for assistant in Assistant.objects.filter(classroom_id=classroom_id)
    ]
    lessons = []
    lesson_dict = OrderedDict()
    for unit1 in lesson_list[int(lesson) - 1][1]:
        for assignment in unit1[1]:
            student_groups = []
            for group in groups:
                members = filter(lambda u: u.group == group.id, enroll_pool)
                group_assistants = []
                works = []
                scorer_name = ""
                for member in members:
                    work = filter(
                        lambda w: w.index == assignment[2] and w.user_id ==
                        member.student_id, work_pool)
                    if work:
                        work = work[0]
                        scorer = filter(lambda u: u.id == work.scorer,
                                        user_pool)
                        scorer_name = scorer[0].first_name if scorer else 'X'
                    else:
                        work = Work(index=assignment[2], user_id=1, score=-2)
                    works.append([member, work.score, scorer_name, work.memo])
                    assistant = filter(
                        lambda a: a.student_id == member.student_id and a.
                        lesson == assignment[2], assistant_pool)
                    if assistant:
                        group_assistants.append(member)
                group_name = EnrollGroup.objects.get(id=group.id).name
                student_groups.append(
                    [group, works, group_assistants, group_name])
            lesson_dict[assignment[2]] = [assignment, student_groups]
    return render(request, 'teacher/work_groups.html', {
        'lesson_dict': sorted(lesson_dict.iteritems()),
        'classroom': classroom
    })
Пример #4
0
def score(request, classroom_id, lesson, index):
    # 限本班任課教師
    if not is_teacher(request.user, classroom_id):
        return redirect("/")
    enrolls = Enroll.objects.filter(classroom_id=classroom_id)
    classroom_name = Classroom.objects.get(id=classroom_id).name
    classmate_work = []
    scorer_name = ""
    for enroll in enrolls:
        try:
            work = Work.objects.get(user_id=enroll.student_id,
                                    index=index,
                                    lesson=lesson)
            if work.scorer > 0:
                scorer = User.objects.get(id=work.scorer)
                scorer_name = scorer.first_name
            else:
                scorer_name = "1"
        except ObjectDoesNotExist:
            work = Work(index=index, user_id=0, lesson=lesson)
        except MultipleObjectsReturned:
            work = Work.objects.filter(user_id=enroll.student_id,
                                       index=index,
                                       lesson=lesson).order_by("-id")[0]
        try:
            group_name = EnrollGroup.objects.get(id=enroll.group).name
        except ObjectDoesNotExist:
            group_name = "沒有組別"
        assistant = Assistant.objects.filter(classroom_id=classroom_id,
                                             student_id=enroll.student_id,
                                             lesson=index)
        if assistant.exists():
            classmate_work.append([enroll, work, 1, scorer_name, group_name])
        else:
            classmate_work.append([enroll, work, 0, scorer_name, group_name])
    lesson_dict = {}
    for unit in lesson_list[int(lesson) - 1][1]:
        for assignment in unit[1]:
            lesson_dict[assignment[2]] = assignment[0]
    assignment = lesson_dict[int(index)]

    def getKey(custom):
        return custom[0].seat

    classmate_work = sorted(classmate_work, key=getKey)

    return render(
        request, 'teacher/score.html', {
            'lesson': lesson,
            'classmate_work': classmate_work,
            'classroom_id': classroom_id,
            'assignment': assignment,
            'index': index
        })
Пример #5
0
def work_group(request, lesson, classroom_id):
    # 限本班任課教師
    if not is_teacher(request.user, classroom_id):
        return redirect("homepage")
    classroom_name = Classroom.objects.get(id=classroom_id).name
    student_groups = []
    groups = EnrollGroup.objects.filter(classroom_id=classroom_id)
    try:
        student_group = Enroll.objects.get(student_id=request.user.id,
                                           classroom_id=classroom_id).group
    except ObjectDoesNotExist:
        student_group = []
    for group in groups:
        enrolls = Enroll.objects.filter(classroom_id=classroom_id,
                                        group=group.id)
        group_assistants = []
        works = []
        scorer_name = ""
        for enroll in enrolls:
            try:
                work = Work.objects.get(user_id=enroll.student_id,
                                        index=lesson)
                if work.scorer > 0:
                    scorer = User.objects.get(id=work.scorer)
                    scorer_name = scorer.first_name
                else:
                    scorer_name = "X"
            except ObjectDoesNotExist:
                work = Work(index=lesson, user_id=1, number="0")
            works.append([enroll, work.score, scorer_name, work.number])
            try:
                assistant = Assistant.objects.get(student_id=enroll.student.id,
                                                  classroom_id=classroom_id,
                                                  lesson=lesson)
                group_assistants.append(enroll)
            except ObjectDoesNotExist:
                pass
        student_groups.append([group, works, group_assistants])
    lesson_data = lesson_list[int(lesson) - 1]
    # 記錄系統事件
    if is_event_open(rrequest):
        log = Log(user_id=request.user.id,
                  event=u'以分組顯示作業<' + lesson + '><' + classroom_name + '>')
        log.save()
    return render_to_response('teacher/work_group.html', {
        'lesson': lesson,
        'lesson_data': lesson_data,
        'student_groups': student_groups,
        'classroom_id': classroom_id,
        'student_group': student_group
    },
                              context_instance=RequestContext(request))
Пример #6
0
def work_group(request, index, classroom_id):
    student_groups = []
    lesson = Classroom.objects.get(id=classroom_id).lesson
    groups = EnrollGroup.objects.filter(classroom_id=classroom_id)
    try:
        student_group = Enroll.objects.get(student_id=request.user.id,
                                           classroom_id=classroom_id).group
    except ObjectDoesNotExist:
        student_group = []
    for group in groups:
        enrolls = Enroll.objects.filter(classroom_id=classroom_id,
                                        group=group.id)
        group_assistants = []
        works = []
        scorer_name = ""
        for enroll in enrolls:
            try:
                work = Work.objects.get(user_id=enroll.student_id,
                                        index=index,
                                        lesson=lesson)
                if work.scorer > 0:
                    scorer = User.objects.get(id=work.scorer)
                    scorer_name = scorer.first_name
                else:
                    scorer_name = "X"
            except ObjectDoesNotExist:
                work = Work(lesson=lesson, index=index, user_id=1, score=-2)
            except MultipleObjectsReturned:
                work = Work.objects.filter(user_id=enroll.student_id,
                                           index=index,
                                           lesson=lesson).order_by("-id")[0]
            works.append([enroll, work.score, scorer_name, work.file])
            try:
                assistant = Assistant.objects.get(student_id=enroll.student.id,
                                                  classroom_id=classroom_id,
                                                  lesson=index)
                group_assistants.append(enroll)
            except ObjectDoesNotExist:
                pass
        student_groups.append([group, works, group_assistants])
    lesson_dict = {}
    for unit in lesson_list[int(lesson) - 1][1]:
        for assignment in unit[1]:
            lesson_dict[assignment[2]] = assignment[0]
    assignment = lesson_dict[int(index)]
    return render(
        request, 'student/work_group.html', {
            'lesson': lesson,
            'assignment': assignment,
            'student_groups': student_groups,
            'classroom_id': classroom_id
        })
Пример #7
0
def submitall(request, index):
        scores = []
        if request.method == 'POST':
            form = SubmitForm(request.POST)
            work = Work.objects.filter(index=index, user_id=request.user.id)
            if not work.exists():
                if form.is_valid():
                    work2 = Work(index=index, user_id=request.user.id, number=form.cleaned_data['number'], memo=form.cleaned_data['memo'], publication_date=timezone.now())
                    work2.save()
					# credit
                    update_avatar(request.user.id, 1, 2)
                    # History
                    history = PointHistory(user_id=request.user.id, kind=1, message='2分--繳交作業<'+lesson_list[int(index)-1][2]+'>', url=request.get_full_path())
                    history.save()	
                    # 記錄系統事件 
                    if is_event_open(request) :                      
                        log = Log(user_id=request.user.id, event=u'新增作業成功<'+index+'>')
                        log.save()                        
            else:
                if form.is_valid():
                    work.update(number=form.cleaned_data['number'], memo=form.cleaned_data['memo'])
                    # 記錄系統事件 
                    if is_event_open() :  
                        log = Log(user_id=request.user.id, event=u'更新作業成功<'+index+'>')
                        log.save()                           
                else :
                    work.update(memo=form.cleaned_data['memo'])           
                return redirect('/student/submitall/'+index)
        else:
            work = Work.objects.filter(index=index, user_id=request.user.id)
            if not work.exists():
                form = SubmitForm()
            else:
                form = SubmitForm(instance=work[0])
                if work[0].scorer>0: 
                    score_name = User.objects.get(id=work[0].scorer).first_name
                    scores = [work[0].score, score_name]
        lesson = lesson_list[int(index)-1]					
        return render_to_response('student/submitall.html', {'form':form, 'scores':scores, 'index':index, 'lesson':lesson}, context_instance=RequestContext(request))
Пример #8
0
def score(request, classroom_id, index):
    # 限本班任課教師
    if not is_teacher(request.user, classroom_id):
        return redirect("homepage")
    enrolls = Enroll.objects.filter(classroom_id=classroom_id)
    classroom_name = Classroom.objects.get(id=classroom_id).name
    classmate_work = []
    scorer_name = ""
    for enroll in enrolls:
        try:
            work = Work.objects.get(user_id=enroll.student_id, index=index)
            if work.scorer > 0:
                scorer = User.objects.get(id=work.scorer)
                scorer_name = scorer.first_name
            else:
                scorer_name = "1"
        except ObjectDoesNotExist:
            work = Work(index=index, user_id=1, number="0")
        try:
            group_name = EnrollGroup.objects.get(id=enroll.group).name
        except ObjectDoesNotExist:
            group_name = "沒有組別"
        assistant = Assistant.objects.filter(classroom_id=classroom_id,
                                             student_id=enroll.student_id,
                                             lesson=index)
        if assistant.exists():
            classmate_work.append([enroll, work, 1, scorer_name, group_name])
        else:
            classmate_work.append([enroll, work, 0, scorer_name, group_name])
    lesson = lesson_list[int(index) - 1]

    def getKey(custom):
        return custom[0].seat

    classmate_work = sorted(classmate_work, key=getKey)

    # 記錄系統事件
    if is_event_open(request):
        log = Log(user_id=request.user.id,
                  event=u'列出某作業所有同學名單<' + classroom_name + '><' + index + '>')
        log.save()
    return render_to_response('teacher/score.html', {
        'classmate_work': classmate_work,
        'classroom_id': classroom_id,
        'lesson': lesson,
        'index': index
    },
                              context_instance=RequestContext(request))
Пример #9
0
def score_peer(request, lesson, index, classroom_id, group):
    lesson_dict = {}
    for unit in lesson_list[int(lesson) - 1][1]:
        for assignment in unit[1]:
            lesson_dict[assignment[2]] = assignment[0]
    assignment = lesson_dict[int(index)]
    try:
        assistant = Assistant.objects.get(lesson=index,
                                          classroom_id=classroom_id,
                                          student_id=request.user.id)
    except ObjectDoesNotExist:
        return redirect("/student/group/work/" + lesson + "/" + index + "/" +
                        classroom_id)

    enrolls = Enroll.objects.filter(classroom_id=classroom_id, group=group)
    classmate_work = []
    workfiles = []
    for enroll in enrolls:
        if not enroll.student_id == request.user.id:
            scorer_name = ""
            try:
                work = Work.objects.get(lesson=lesson,
                                        user_id=enroll.student.id,
                                        index=index)
                if work.scorer > 0:
                    scorer = User.objects.get(id=work.scorer)
                    scorer_name = scorer.first_name
            except ObjectDoesNotExist:
                work = Work(lesson=lesson, index=index, user_id=1)
            workfiles = WorkFile.objects.filter(work_id=work.id)
            classmate_work.append([enroll.student, work, 1, scorer_name])
    return render(
        request, 'teacher/score_peer.html', {
            'assignment': assignment,
            'enrolls': enrolls,
            'workfiles': workfiles,
            'classmate_work': classmate_work,
            'classroom_id': classroom_id,
            'lesson': lesson,
            'index': index
        })
Пример #10
0
def score_peer(request, index, classroom_id, group):
    try:
        assistant = Assistant.objects.get(lesson=index,
                                          classroom_id=classroom_id,
                                          student_id=request.user.id)
    except ObjectDoesNotExist:
        return redirect("/student/group/work/" + classroom_id + "/" + index)

    enrolls = Enroll.objects.filter(classroom_id=classroom_id, group=group)
    lesson = ""
    classmate_work = []
    for enroll in enrolls:
        if not enroll.student_id == request.user.id:
            scorer_name = ""
            try:
                work = Work.objects.get(user_id=enroll.student.id, index=index)
                if work.scorer > 0:
                    scorer = User.objects.get(id=work.scorer)
                    scorer_name = scorer.first_name
            except ObjectDoesNotExist:
                work = Work(index=index, user_id=1, number="0")
            classmate_work.append([enroll.student, work, 1, scorer_name])
        lesson = lesson_list[int(index) - 1]
    # 記錄系統事件
    if is_event_open(request):
        log = Log(user_id=request.user.id,
                  event=u'小老師評分名單<' + index + '><' + group + '>')
        log.save()
    return render_to_response('teacher/score_peer.html', {
        'enrolls': enrolls,
        'classmate_work': classmate_work,
        'classroom_id': classroom_id,
        'lesson': lesson,
        'index': index
    },
                              context_instance=RequestContext(request))
Пример #11
0
def scoring(request, classroom_id, user_id, index):
    user = User.objects.get(id=user_id)
    enroll = Enroll.objects.get(classroom_id=classroom_id, student_id=user_id)
    try:
        assistant = Assistant.objects.filter(classroom_id=classroom_id,lesson=index,student_id=request.user.id)
    except ObjectDoesNotExist:            
        if not is_teacher(request.user, classroom_id):
            return render_to_response('message.html', {'message':"您沒有權限"}, context_instance=RequestContext(request))
        
    try:
        work3 = Work.objects.get(user_id=user_id, index=index)
    except ObjectDoesNotExist:
        work3 = Work(index=index, user_id=user_id, number="0")
        
    if request.method == 'POST':
        form = ScoreForm(request.user, request.POST)
        if form.is_valid():
            work = Work.objects.filter(index=index, user_id=user_id)
            if not work.exists():
                work = Work(index=index, user_id=user_id, score=form.cleaned_data['score'], publication_date=timezone.now())
                work.save()
                # 記錄系統事件
                if is_event_open() :            
                    log = Log(user_id=request.user.id, event=u'新增評分<'+user.first_name+'><'+work.score+'分>')
                    log.save()                      
            else:
                if work[0].score < 0 :   
                    # 小老師
                    if not is_teacher(request.user, classroom_id):
    	                # credit
                        update_avatar(request.user.id, 2, 1)
                        # History
                        history = PointHistory(user_id=request.user.id, kind=2, message='1分--小老師:<'+lesson_list[int(index)-1][2]+'><'+enroll.student.first_name.encode('utf-8')+'>', url=request.get_full_path())
                        history.save()				
    
				    # credit
                    update_avatar(enroll.student_id, 1, 1)
                    # History
                    history = PointHistory(user_id=user_id, kind=1, message='1分--作業受評<'+lesson_list[int(index)-1][2]+'><'+request.user.first_name.encode('utf-8')+'>', url=request.get_full_path())
                    history.save()		                        
                
                work.update(score=form.cleaned_data['score'])
                work.update(scorer=request.user.id)
                # 記錄系統事件
                if is_event_open(request) :                   
                    log = Log(user_id=request.user.id, event=u'更新評分<'+user.first_name+u'><'+str(work[0].score)+u'分>')
                    log.save()                    
						
            if is_teacher(request.user, classroom_id):         
                if form.cleaned_data['assistant']:
                    try :
					    assistant = Assistant.objects.get(student_id=user_id, classroom_id=classroom_id, lesson=index)
                    except ObjectDoesNotExist:
                        assistant = Assistant(student_id=user_id, classroom_id=classroom_id, lesson=index)
                        assistant.save()	
                        
                    # create Message
                    title = "<" + assistant.student.first_name.encode("utf-8") + u">擔任小老師<".encode("utf-8") + lesson_list[int(index)-1][2] + ">"
                    url = "/teacher/score_peer/" + str(index) + "/" + classroom_id + "/" + str(enroll.group) 
                    message = Message.create(title=title, url=url, time=timezone.now())
                    message.save()                        
                    
                    group = Enroll.objects.get(classroom_id=classroom_id, student_id=assistant.student_id).group
                    if group > 0 :
                        enrolls = Enroll.objects.filter(group = group)
                        for enroll in enrolls:
                            # message for group member
                            messagepoll = MessagePoll.create(message_id = message.id,reader_id=enroll.student_id)
                            messagepoll.save()
                    
                return redirect('/teacher/score/'+classroom_id+'/'+index)
            else: 
                return redirect('/teacher/score_peer/'+index+'/'+classroom_id+'/'+str(enroll.group))

    else:
        work = Work.objects.filter(index=index, user_id=user_id)
        if not work.exists():
            form = ScoreForm(user=request.user)
        else:
            form = ScoreForm(instance=work[0], user=request.user)
    lesson = lesson_list[int(index)-1]
    return render_to_response('teacher/scoring.html', {'form': form,'work':work3, 'student':user, 'classroom_id':classroom_id, 'lesson':lesson}, context_instance=RequestContext(request))
Пример #12
0
def scoring(request, classroom_id, user_id, lesson, index):
    user = User.objects.get(id=user_id)
    enroll = Enroll.objects.get(classroom_id=classroom_id, student_id=user_id)
    classroom = Classroom.objects.get(id=classroom_id)
    lesson_dict = {}
    for unit in lesson_list[int(lesson) - 1][1]:
        for assignment in unit[1]:
            lesson_dict[assignment[2]] = assignment[0]
    assignment = lesson_dict[int(index)]
    try:
        assistant = Assistant.objects.filter(classroom_id=classroom_id,
                                             lesson=index,
                                             student_id=request.user.id)
    except ObjectDoesNotExist:
        if not is_teacher(request.user, classroom_id):
            return render(request, 'message.html', {'message': "您沒有權限"})

    try:
        work3 = Work.objects.get(user_id=user_id, index=index, lesson=lesson)
    except ObjectDoesNotExist:
        work3 = Work(index=index, user_id=user_id, lesson=lesson)
    except MultipleObjectsReturned:
        work3 = Work.objects.filter(user_id=user_id,
                                    index=index,
                                    lesson=lesson).order_by("-id")[0]

    workfiles = WorkFile.objects.filter(work_id=work3.id).order_by("-id")

    if request.method == 'POST':
        form = ScoreForm(request.user, request.POST)
        if form.is_valid():
            work = Work.objects.filter(index=index,
                                       user_id=user_id,
                                       lesson=lesson)
            if not work.exists():
                work = Work(lesson=lesson,
                            index=index,
                            user_id=user_id,
                            score=form.cleaned_data['score'],
                            publication_date=timezone.now())
                work.save()
            else:
                if work[0].score < 0:
                    # 小老師
                    if not is_teacher(request.user, classroom_id):
                        # credit
                        update_avatar(request.user.id, 2, 1)
                        # History
                        history = PointHistory(
                            user_id=request.user.id,
                            kind=2,
                            message='1分--小老師:<' + assignment + '><' +
                            enroll.student.first_name.encode('utf-8') + '>',
                            url=request.get_full_path())
                        history.save()

# credit
                    update_avatar(enroll.student_id, 1, 1)
                    # History
                    history = PointHistory(
                        user_id=user_id,
                        kind=1,
                        message='1分--作業受評<' + assignment + '><' +
                        request.user.first_name.encode('utf-8') + '>',
                        url=request.get_full_path())
                    history.save()

                work.update(score=form.cleaned_data['score'])
                work.update(scorer=request.user.id)

            if is_teacher(request.user, classroom_id):
                if form.cleaned_data['assistant']:
                    try:
                        assistant = Assistant.objects.get(
                            student_id=user_id,
                            classroom_id=classroom_id,
                            lesson=index)
                    except ObjectDoesNotExist:
                        assistant = Assistant(student_id=user_id,
                                              classroom_id=classroom_id,
                                              lesson=index)
                        assistant.save()

                    # create Message
                    title = "<" + assistant.student.first_name.encode(
                        "utf-8") + u">擔任小老師<".encode(
                            "utf-8") + assignment + ">"
                    url = "/teacher/score_peer/" + lesson + "/" + str(
                        index) + "/" + classroom_id + "/" + str(enroll.group)
                    message = Message.create(title=title,
                                             url=url,
                                             time=timezone.now())
                    message.save()

                    group = Enroll.objects.get(
                        classroom_id=classroom_id,
                        student_id=assistant.student_id).group
                    if group > 0:
                        enrolls = Enroll.objects.filter(group=group)
                        for enroll in enrolls:
                            # message for group member
                            messagepoll = MessagePoll.create(
                                message_id=message.id,
                                reader_id=enroll.student_id)
                            messagepoll.save()

                return redirect('/teacher/score/' + classroom_id + '/' +
                                lesson + "/" + index)
            else:
                return redirect('/teacher/score_peer/' + lesson + "/" + index +
                                '/' + classroom_id + '/' + str(enroll.group))

    else:
        work = Work.objects.filter(lesson=lesson, index=index, user_id=user_id)
        if not work.exists():
            form = ScoreForm(user=request.user)
        else:
            form = ScoreForm(instance=work[0], user=request.user)
    return render(
        request, 'teacher/scoring.html', {
            'form': form,
            'workfiles': workfiles,
            'index': index,
            'work': work3,
            'student': user,
            'classroom': classroom,
            'lesson': lesson,
            'assignment': assignment
        })
Пример #13
0
def scoring(request, classroom_id, user_id, index):
    user = User.objects.get(id=user_id)
    enroll = Enroll.objects.get(classroom_id=classroom_id, student_id=user_id)
    try:
        assistant = Assistant.objects.filter(classroom_id=classroom_id,
                                             lesson=index,
                                             student_id=request.user.id)
    except ObjectDoesNotExist:
        if not is_teacher(request.user, classroom_id):
            return render_to_response('message.html', {'message': "您沒有權限"},
                                      context_instance=RequestContext(request))

    try:
        work3 = Work.objects.get(user_id=user_id, index=index)
    except ObjectDoesNotExist:
        work3 = Work(index=index, user_id=user_id, number="0")

    if request.method == 'POST':
        form = ScoreForm(request.user, request.POST)
        if form.is_valid():
            work = Work.objects.filter(index=index, user_id=user_id)
            if not work.exists():
                work = Work(index=index,
                            user_id=user_id,
                            score=form.cleaned_data['score'],
                            publication_date=timezone.now())
                work.save()
                # 記錄系統事件
                if is_event_open():
                    log = Log(user_id=request.user.id,
                              event=u'新增評分<' + user.first_name + '><' +
                              work.score + '分>')
                    log.save()
            else:
                if work[0].score < 0:
                    # 小老師
                    if not is_teacher(request.user, classroom_id):
                        # credit
                        update_avatar(request.user.id, 2, 1)
                        # History
                        history = PointHistory(
                            user_id=request.user.id,
                            kind=2,
                            message='1分--小老師:<' +
                            lesson_list[int(index) - 1][2] + '><' +
                            enroll.student.first_name.encode('utf-8') + '>',
                            url=request.get_full_path())
                        history.save()

# credit
                    update_avatar(enroll.student_id, 1, 1)
                    # History
                    history = PointHistory(
                        user_id=user_id,
                        kind=1,
                        message='1分--作業受評<' + lesson_list[int(index) - 1][2] +
                        '><' + request.user.first_name.encode('utf-8') + '>',
                        url=request.get_full_path())
                    history.save()

                work.update(score=form.cleaned_data['score'])
                work.update(scorer=request.user.id)
                # 記錄系統事件
                if is_event_open(request):
                    log = Log(user_id=request.user.id,
                              event=u'更新評分<' + user.first_name + u'><' +
                              str(work[0].score) + u'分>')
                    log.save()

            if is_teacher(request.user, classroom_id):
                if form.cleaned_data['assistant']:
                    try:
                        assistant = Assistant.objects.get(
                            student_id=user_id,
                            classroom_id=classroom_id,
                            lesson=index)
                    except ObjectDoesNotExist:
                        assistant = Assistant(student_id=user_id,
                                              classroom_id=classroom_id,
                                              lesson=index)
                        assistant.save()

                    # create Message
                    title = "<" + assistant.student.first_name.encode(
                        "utf-8") + u">擔任小老師<".encode("utf-8") + lesson_list[
                            int(index) - 1][2] + ">"
                    url = "/teacher/score_peer/" + str(
                        index) + "/" + classroom_id + "/" + str(enroll.group)
                    message = Message.create(title=title,
                                             url=url,
                                             time=timezone.now())
                    message.save()

                    group = Enroll.objects.get(
                        classroom_id=classroom_id,
                        student_id=assistant.student_id).group
                    if group > 0:
                        enrolls = Enroll.objects.filter(group=group)
                        for enroll in enrolls:
                            # message for group member
                            messagepoll = MessagePoll.create(
                                message_id=message.id,
                                reader_id=enroll.student_id)
                            messagepoll.save()

                return redirect('/teacher/score/' + classroom_id + '/' + index)
            else:
                return redirect('/teacher/score_peer/' + index + '/' +
                                classroom_id + '/' + str(enroll.group))

    else:
        work = Work.objects.filter(index=index, user_id=user_id)
        if not work.exists():
            form = ScoreForm(user=request.user)
        else:
            form = ScoreForm(instance=work[0], user=request.user)
    lesson = lesson_list[int(index) - 1]
    return render_to_response('teacher/scoring.html', {
        'form': form,
        'work': work3,
        'student': user,
        'classroom_id': classroom_id,
        'lesson': lesson
    },
                              context_instance=RequestContext(request))
Пример #14
0
def lesson(request, lesson, unit, index):
    lesson_dict = OrderedDict()
    works = Work.objects.filter(user_id=request.user.id,
                                lesson=lesson,
                                index=index).order_by("-id")
    for unit1 in lesson_list[int(lesson) - 1][1]:
        for assignment in unit1[1]:
            sworks = filter(lambda w: w.index == assignment[2], works)
            if len(sworks) > 0:
                lesson_dict[assignment[2]] = [assignment, sworks[0]]
            else:
                lesson_dict[assignment[2]] = [assignment, None]
    assignment = lesson_dict[int(index)]
    scores = []
    workfiles = []
    #work_index = lesson_list[int(lesson)-1][1][int(unit)-1][1][int(index)-1][2]
    works = Work.objects.filter(index=index,
                                lesson=lesson,
                                user_id=request.user.id)
    try:
        filepath = request.FILES['file']
    except:
        filepath = False
    if request.method == 'POST':
        if filepath:
            myfile = request.FILES['file']
            fs = FileSystemStorage()
            filename = uuid4().hex
            fs.save("static/work/" + str(request.user.id) + "/" + filename,
                    myfile)

        form = SubmitForm(request.POST, request.FILES)

        if not works.exists():
            if form.is_valid():
                work = Work(lesson=lesson,
                            index=index,
                            user_id=request.user.id,
                            memo=form.cleaned_data['memo'],
                            publication_date=timezone.now())
                work.save()
                workfile = WorkFile(work_id=work.id, filename=filename)
                workfile.save()
                # credit
                update_avatar(request.user.id, 1, 2)
                # History
                history = PointHistory(user_id=request.user.id,
                                       kind=1,
                                       message='2分--繳交作業<' + assignment[0][0] +
                                       '>',
                                       url=request.get_full_path())
                history.save()
        else:
            if form.is_valid():
                works.update(memo=form.cleaned_data['memo'],
                             publication_date=timezone.localtime(
                                 timezone.now()))
                workfile = WorkFile(work_id=works[0].id, filename=filename)
                workfile.save()
            else:
                works.update(memo=form.cleaned_data['memo'])
        return redirect('/student/lesson/' + lesson + '/' + unit + "/" +
                        index + "#tab4")
    else:
        if not works.exists():
            form = SubmitForm()
        else:
            workfiles = WorkFile.objects.filter(
                work_id=works[0].id).order_by("-id")
            form = SubmitForm(instance=works[0])
            if len(workfiles) > 0 and works[0].scorer > 0:
                score_name = User.objects.get(id=works[0].scorer).first_name
                scores = [works[0].score, score_name]
    return render(
        request, 'student/lesson.html', {
            'assignment': assignment,
            'index': index,
            'form': form,
            'unit': unit,
            'lesson': lesson,
            'scores': scores,
            'workfiles': workfiles
        })