def make(request): user_id = request.POST.get('userid') action = request.POST.get('action') if user_id and action: user = User.objects.get(id=user_id) try: group = Group.objects.get(name="teacher") except ObjectDoesNotExist: group = Group(name="teacher") group.save() if action == 'set': group.user_set.add(user) # create Message title = "<" + request.user.first_name + u">設您為教師" url = "/teacher/classroom" message = Message(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll(message_id=message.id, reader_id=user_id) messagepoll.save() else: group.user_set.remove(user) # create Message title = "<" + request.user.first_name + u">取消您為教師" url = "/" message = Message(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll(message_id=message.id, reader_id=user_id) messagepoll.save() return JsonResponse({'status': 'ok'}, safe=False) else: return JsonResponse({'status': 'no'}, safe=False)
def form_valid(self, form): self.object = form.save(commit=False) self.object.author_id = self.request.user.id self.object.classroom_id = self.kwargs['classroom_id'] self.object.save() # create Message title = self.request.user.first_name + u"--提出一個Bug<" + form.cleaned_data[ 'title'] + ">" url = "/student/bug/" + str(self.object.id) message = Message.create(title=title, url=url, time=timezone.now()) message.save() enrolls = Enroll.objects.filter(student_id=self.request.user.id) for enroll in enrolls: # message for teacher messagepoll = MessagePoll.create( message_id=message.id, reader_id=enroll.classroom.teacher_id) messagepoll.save() # message for classsmates classmates = Enroll.objects.filter( classroom_id=enroll.classroom_id) for classmate in classmates: if not classmate.student_id == self.request.user.id: messagepoll = MessagePoll.create( message_id=message.id, reader_id=classmate.student_id) messagepoll.save() # 記錄系統事件 classroom_name = Classroom.objects.get( id=self.kwargs['classroom_id']).name if is_event_open(self.request): log = Log(user_id=self.request.user.id, event=u'張貼Bug<' + classroom_name + '>') log.save() return redirect(url)
def assistant_cancle(request, classroom_id, user_id, lesson, index): 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)] # 限本班任課教師 if not is_teacher(request.user, classroom_id): return redirect("homepage") user = User.objects.get(id=user_id) assistant = Assistant.objects.get(student_id=user_id, classroom_id=classroom_id, lesson=index) assistant.delete() # create Message title = "<" + assistant.student.first_name.encode( "utf-8") + u">取消小老師<".encode("utf-8") + assignment + ">" url = "/student/group/work/" + str( lesson) + "/" + index + "/" + classroom_id 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/' + str(assistant.classroom_id) + "/" + lesson + "/" + index)
def register(request): if request.method == 'POST': form = UserRegistrationForm(request.POST) if form.is_valid(): # Create a new user object but avoid saving it yet new_user = form.save(commit=False) # Set the chosen password new_user.set_password( form.cleaned_data['password']) # Save the User object new_user.save() profile = Profile(user=new_user) profile.save() # 記錄系統事件 if is_event_open(request) : log = Log(user_id=new_user.id, event='註冊帳號成功') log.save() # create Message title = "請洽詢任課教師課程名稱及選課密碼" url = "/student/classroom/add" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create(message_id = message.id,reader_id=new_user.id) messagepoll.save() return render(request, 'account/register_done.html', {'new_user': new_user}) else: form = UserRegistrationForm() return render(request, 'account/register.html', {'form': form})
def import_student(request): if False: return redirect("/") users = ImportUser.objects.all() for user in users: try: account = User.objects.get(username=request.user.username + "_" + user.username) except ObjectDoesNotExist: username = request.user.username + "_" + user.username new_user = User(username=username, first_name=user.first_name, password=user.password, email=username + "@edu.tw") # Set the chosen password new_user.set_password(user.password) # Save the User object new_user.save() profile = Profile(user=new_user) profile.save() # create Message title = "請洽詢任課教師課程名稱及選課密碼" url = "/student/classroom/add" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create(message_id=message.id, reader_id=new_user.id) messagepoll.save() return redirect('/teacher/student/list')
def form_valid(self, form): self.object = form.save(commit=False) self.object.author_id = self.request.user.id self.object.classroom_id = self.kwargs['classroom_id'] self.object.save() # create Message title = self.request.user.first_name + u"--提出一個Bug<" + form.cleaned_data['title'] + ">" url = "/student/bug/" + str(self.object.id) message = Message.create(title=title, url=url, time=timezone.now()) message.save() enrolls = Enroll.objects.filter(student_id = self.request.user.id) for enroll in enrolls: # message for teacher messagepoll = MessagePoll.create(message_id = message.id,reader_id=enroll.classroom.teacher_id) messagepoll.save() # message for classsmates classmates = Enroll.objects.filter(classroom_id = enroll.classroom_id) for classmate in classmates: if not classmate.student_id == self.request.user.id: messagepoll = MessagePoll.create(message_id = message.id,reader_id=classmate.student_id) messagepoll.save() # 記錄系統事件 classroom_name = Classroom.objects.get(id=self.kwargs['classroom_id']).name if is_event_open(self.request) : log = Log(user_id=self.request.user.id, event=u'張貼Bug<'+ classroom_name +'>') log.save() return redirect(url)
def register(request): if request.method == 'POST': form = UserRegistrationForm(request.POST) if form.is_valid(): # Create a new user object but avoid saving it yet new_user = form.save(commit=False) # Set the chosen password new_user.set_password(form.cleaned_data['password']) # Save the User object new_user.save() profile = Profile(user=new_user) profile.save() # 記錄系統事件 if is_event_open(request): log = Log(user_id=new_user.id, event='註冊帳號成功') log.save() # create Message title = "請洽詢任課教師課程名稱及選課密碼" url = "/student/classroom/add" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create(message_id=message.id, reader_id=new_user.id) messagepoll.save() return render(request, 'account/register_done.html', {'new_user': new_user}) else: form = UserRegistrationForm() return render(request, 'account/register.html', {'form': form})
def assistant_cancle(request, classroom_id, user_id, lesson): # 限本班任課教師 if not is_teacher(request.user, classroom_id): return redirect("homepage") user = User.objects.get(id=user_id) assistant = Assistant.objects.get(student_id=user_id, classroom_id=classroom_id, lesson=lesson) assistant.delete() # 記錄系統事件 if is_event_open(request) : log = Log(user_id=request.user.id, event=u'取消小老師<'.encode("utf-8")+user.first_name.encode("utf-8")+'><'+ lesson_list[int(lesson)-1][2] + ">") log.save() # create Message title = "<" + assistant.student.first_name.encode("utf-8") + u">取消小老師<".encode("utf-8") + lesson_list[int(lesson)-1][2] + ">" url = "/student/group/work/" + str(lesson) + "/" + classroom_id 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/'+str(assistant.classroom_id)+"/"+lesson)
def make(request): user_id = request.POST.get('userid') action = request.POST.get('action') if user_id and action : user = User.objects.get(id=user_id) try : group = Group.objects.get(name="teacher") except ObjectDoesNotExist : group = Group(name="teacher") group.save() if action == 'set': # 記錄系統事件 log = Log(user_id=1, event=u'管理員設為教師<'+user.first_name+'>') log.save() group.user_set.add(user) # create Message title = "<" + request.user.first_name + u">設您為教師" url = "/teacher/classroom" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create(message_id = message.id,reader_id=user_id) messagepoll.save() else : # 記錄系統事件 if is_event_open(request) : log = Log(user_id=1, event=u'取消教師<'+user.first_name+'>') log.save() group.user_set.remove(user) # create Message title = "<"+ request.user.first_name + u">取消您為教師" url = "/" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create(message_id = message.id,reader_id=user_id) messagepoll.save() return JsonResponse({'status':'ok'}, safe=False) else: return JsonResponse({'status':user.first_name}, safe=False)
def make_image(unit, enroll_id, teacher_id): ''' A View that Returns a PNG Image generated using PIL''' from PIL import Image, ImageDraw im = Image.open(settings.BASE_DIR+'/static/certificate/certificate'+unit+'.jpg') # create the image #draw = ImageDraw.Draw(im) # create a drawing object that is # used to draw on the new image #red = (255,0,0) # color of our text #text_pos = (10,10) # top-left position of our text # Now, we'll do the drawing: font_student = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',80) font_teacher = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',60) draw = ImageDraw.Draw(im) enroll = Enroll.objects.get(id=enroll_id) #studnet_id = enroll.student.id student_name = User.objects.get(id=enroll.student.id).first_name teacher_name = User.objects.get(id=teacher_id).first_name student = smart_text(student_name, encoding='utf-8', strings_only=False, errors='strict') teacher = smart_text(teacher_name, encoding='utf-8', strings_only=False, errors='strict') draw.text((340,162), student,(0,0,0),font=font_student) draw.text((500,387), teacher,(0,0,200),font=font_teacher) draw.text((410,448), timezone.localtime(timezone.now()).strftime("%Y/%m/%d"),(0,0,0),font=font_teacher) del draw # I'm done drawing so I don't need this anymore # We need an HttpResponse object with the correct mimetype #response = HttpResponse(content_type = "image/jpeg") #im.save(response, 'jpeg') #return response # now, we tell the image to save as a PNG to the # provided file-like object temp_handle = StringIO.StringIO() im.save(temp_handle, 'jpeg') temp_handle.seek(0) # open file write mode context = {'error':''} fileName = settings.BASE_DIR+"/static/certificate/"+unit+"/"+enroll_id+".jpg" writeFile(temp_handle.read(), fileName, context) #update and message title = "<" + teacher_name + u">核發了一張證書給你" #title = smart_text(teacher_name+"--核發了一張證書給你", encoding='utf-8', strings_only=False, errors='strict') url = "/certificate/show/" + unit + "/" + enroll_id message = Message.create(title=title, url=url, time=timezone.now()) message.save() messagepoll = MessagePoll.create(reader_id=enroll.student.id, message_id = message.id) messagepoll.save()
def debug_value(request, bug_id): import sys reload(sys) sys.setdefaultencoding("utf-8") # A comment was posted debug = Debug.objects.filter(id=3) debug_value_form = DebugValueForm(data=request.POST) if debug_value_form.is_valid(): try: debug_id = int(debug_value_form.cleaned_data['id']) debug = Debug.objects.get(id=debug_id) url = "/student/bug/"+str(bug_id) if debug_value_form.cleaned_data['reward'] == "0": reward = "沒有解決" msg =u'0分<'+ request.user.first_name.encode('utf-8')+u'>評價您的除錯<'+reward.encode('utf-8')+'>' elif debug_value_form.cleaned_data['reward'] == "1": reward = "部份解決" msg =u'1分<'+ request.user.first_name.encode('utf-8')+u'>評價您的除錯<'+reward.encode('utf-8')+'>' elif debug_value_form.cleaned_data['reward'] == "2": reward = "大概解決" msg =u'2分<'+ request.user.first_name.encode('utf-8')+u'>評價您的除錯<'+reward.encode('utf-8')+'>' elif debug_value_form.cleaned_data['reward'] == "3": reward = "完全解決" msg =u'3分<'+ request.user.first_name.encode('utf-8')+u'>評價您的除錯<'+reward.encode('utf-8')+'>' # credit if debug.reward < 0 : # credit update_avatar(debug.author_id, 3, int(debug_value_form.cleaned_data['reward'])) # History history = PointHistory(user_id=debug.author_id, kind=3, message=msg, url=url) history.save() # create Message message = Message.create(title=msg, url=url, time=timezone.localtime(timezone.now())) message.save() messagepoll = MessagePoll.create(reader_id=debug.author_id, message_id = message.id) messagepoll.save() debug.reward=debug_value_form.cleaned_data['reward'] debug.save() # 記錄系統事件 if is_event_open(request) : log = Log(user_id=request.user.id, event=u'評價除錯<'+ debug_value_form.cleaned_data['reward']+u'分><'+debug.author.first_name+'>') log.save() except ObjectDoesNotExist: pass return redirect("/student/bug/"+str(bug_id))
def bug_detail(request, bug_id): bug = Bug.objects.get(id=bug_id) # List of active comments for this post debugs = Debug.objects.filter(bug_id=bug.id) datas = [] for debug in debugs: datas.append([debug, DebugValueForm(instance=debug)]) if request.method == 'POST': # A comment was posted debug_form = DebugForm(data=request.POST) if debug_form.is_valid(): # Create Comment object but don't save to database yet new_debug = debug_form.save(commit=False) # Assign the current bug to the comment new_debug.bug_id = bug.id new_debug.author_id = request.user.id # Save the comment to the database new_debug.save() # create Message title = "<" + request.user.first_name + u">幫您除錯了<" + bug.title + ">" url = request.get_full_path() message = Message.create(title=title, url=url, time=timezone.localtime(timezone.now())) message.save() messagepoll = MessagePoll.create(reader_id=bug.author_id, message_id=message.id) messagepoll.save() # 記錄系統事件 bug = Bug.objects.get(id=bug_id) if is_event_open(request): log = Log(user_id=request.user.id, event=u'幫忙除錯<' + bug.title + '>') log.save() return redirect("/student/bug/" + bug_id) else: debug_form = DebugForm() return render_to_response('student/bug_detail.html', { 'bug': bug, 'datas': datas, 'debug_form': debug_form }, context_instance=RequestContext(request))
def assistant(request, classroom_id, user_id, lesson): # 限本班任課教師 if not is_teacher(request.user, classroom_id): return redirect("homepage") user = User.objects.get(id=user_id) assistant = Assistant(student_id=user_id, classroom_id=classroom_id, lesson=lesson) assistant.save() # 記錄系統事件 if is_event_open(request): log = Log(user_id=request.user.id, event=u'設為小老師<'.encode("utf-8") + user.first_name.encode("utf-8") + '><' + lesson_list[int(lesson) - 1][2] + ">") log.save() group = Enroll.objects.get(classroom_id=classroom_id, student_id=assistant.student_id).group # create Message title = "<" + assistant.student.first_name.encode( "utf-8") + u">擔任小老師<".encode("utf-8") + lesson_list[int(lesson) - 1][2] + ">" url = "/teacher/score_peer/" + str( lesson) + "/" + classroom_id + "/" + str(group) message = Message.create(title=title, url=url, time=timezone.now()) message.save() 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/' + str(assistant.classroom_id) + "/" + lesson)
def bug_detail(request, bug_id): bug = Bug.objects.get(id=bug_id) # List of active comments for this post debugs = Debug.objects.filter(bug_id=bug.id) datas = [] for debug in debugs: datas.append([debug, DebugValueForm(instance=debug)]) if request.method == 'POST': # A comment was posted debug_form = DebugForm(data=request.POST) if debug_form.is_valid(): # Create Comment object but don't save to database yet new_debug = debug_form.save(commit=False) # Assign the current bug to the comment new_debug.bug_id = bug.id new_debug.author_id = request.user.id # Save the comment to the database new_debug.save() # create Message title = "<" + request.user.first_name + u">幫您除錯了<"+ bug.title + ">" url = request.get_full_path() message = Message.create(title=title, url=url, time=timezone.localtime(timezone.now())) message.save() messagepoll = MessagePoll.create(reader_id=bug.author_id, message_id = message.id) messagepoll.save() # 記錄系統事件 bug = Bug.objects.get(id=bug_id) if is_event_open(request) : log = Log(user_id=request.user.id, event=u'幫忙除錯<'+ bug.title +'>') log.save() return redirect("/student/bug/"+bug_id) else: debug_form = DebugForm() return render_to_response('student/bug_detail.html',{'bug': bug,'datas': datas, 'debug_form': debug_form}, context_instance=RequestContext(request))
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))
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 })
def form_valid(self, form): classrooms = self.request.POST.getlist('classrooms') files = self.request.FILES.getlist('files') self.object = form.save(commit=False) filenames = [] for file in files: fs = FileSystemStorage() filename = uuid4().hex fs.save("static/message/" + filename, file) filenames.append([filename, file.name]) for classroom_id in classrooms: message = Message() message.title = u"[公告]" + self.object.title message.author_id = self.request.user.id message.classroom_id = classroom_id message.content = self.object.content message.save() message.url = "/teacher/announce/detail/" + str(message.id) message.save() for filename in filenames: messagefile = MessageFile(message_id=message.id, filename=filename[0], before_name=filename[1]) messagefile.save() # 班級學生訊息 enrolls = Enroll.objects.filter(classroom_id=classroom_id) for enroll in enrolls: messagepoll = MessagePoll(message_id=message.id, reader_id=enroll.student_id, classroom_id=classroom_id) messagepoll.save() return redirect("/teacher/announce/" + self.kwargs['classroom_id'])
def make_image(unit, enroll_id, teacher_id): ''' A View that Returns a PNG Image generated using PIL''' from PIL import Image, ImageDraw im = Image.open(settings.BASE_DIR + '/static/certificate/certificate' + unit + '.jpg') # create the image #draw = ImageDraw.Draw(im) # create a drawing object that is # used to draw on the new image #red = (255,0,0) # color of our text #text_pos = (10,10) # top-left position of our text # Now, we'll do the drawing: font_student = ImageFont.truetype( settings.BASE_DIR + '/static/cwTeXQKai-Medium.ttf', 80) font_teacher = ImageFont.truetype( settings.BASE_DIR + '/static/cwTeXQKai-Medium.ttf', 60) draw = ImageDraw.Draw(im) enroll = Enroll.objects.get(id=enroll_id) #studnet_id = enroll.student.id student_name = User.objects.get(id=enroll.student.id).first_name teacher_name = User.objects.get(id=teacher_id).first_name student = smart_text(student_name, encoding='utf-8', strings_only=False, errors='strict') teacher = smart_text(teacher_name, encoding='utf-8', strings_only=False, errors='strict') draw.text((340, 162), student, (0, 0, 0), font=font_student) draw.text((500, 387), teacher, (0, 0, 200), font=font_teacher) draw.text((410, 448), timezone.localtime(timezone.now()).strftime("%Y/%m/%d"), (0, 0, 0), font=font_teacher) del draw # I'm done drawing so I don't need this anymore # We need an HttpResponse object with the correct mimetype #response = HttpResponse(content_type = "image/jpeg") #im.save(response, 'jpeg') #return response # now, we tell the image to save as a PNG to the # provided file-like object temp_handle = StringIO.StringIO() im.save(temp_handle, 'jpeg') temp_handle.seek(0) # open file write mode context = {'error': ''} fileName = settings.BASE_DIR + "/static/certificate/" + unit + "/" + enroll_id + ".jpg" writeFile(temp_handle.read(), fileName, context) #update and message title = "<" + teacher_name + u">核發了一張證書給你" #title = smart_text(teacher_name+"--核發了一張證書給你", encoding='utf-8', strings_only=False, errors='strict') url = "/certificate/show/" + unit + "/" + enroll_id message = Message.create(title=title, url=url, time=timezone.now()) message.save() messagepoll = MessagePoll.create(reader_id=enroll.student.id, message_id=message.id) messagepoll.save()
def loginsession(request): username = request.POST['useremail'] password = request.POST['userpassword'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: login(request, user) message = Message() message.status = "ok" message.to = "dashboard" message.msg = "Authentification réussie. Redirection vers le tableau de bord." return JsonResponse(message.getdict()) else: message = Message() message.status = "error" message.to = "login" message.msg = "Ce compte est inactif contacter l'administrateur" return JsonResponse(message.getdict()) else: message = Message() message.status = "error" message.to = "login" message.msg = "Soit ce compte n'existe pas soit le mot de passe n'est pas le bon." return JsonResponse(message.getdict())
def make_image(unit, enroll_id, teacher_id): ''' A View that Returns a PNG Image generated using PIL''' from PIL import Image, ImageDraw im = Image.open(settings.BASE_DIR+'/static/certificate/certificate'+unit+'.jpg') # create the image #draw = ImageDraw.Draw(im) # create a drawing object that is # used to draw on the new image #red = (255,0,0) # color of our text #text_pos = (10,10) # top-left position of our text # Now, we'll do the drawing: font_student = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',60) font_school = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',40) font_teacher = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',50) font_date = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',50) draw = ImageDraw.Draw(im) enroll = Enroll.objects.get(id=enroll_id) #studnet_id = enroll.student.id student_name = User.objects.get(id=enroll.student.id).first_name school_name = User.objects.get(id=teacher_id).last_name lesson_name = "高慧君老師" teacher_name = User.objects.get(id=teacher_id).first_name+"老師" year = timezone.localtime(timezone.now()).year month = timezone.localtime(timezone.now()).month day = timezone.localtime(timezone.now()).day date_name = "中 華 民 國 "+ str(year-1911) + " 年 "+ str(month) + " 月 " + str(day) + " 日" student = smart_text(student_name, encoding='utf-8', strings_only=False, errors='strict') school = smart_text(school_name, encoding='utf-8', strings_only=False, errors='strict') lesson = smart_text(lesson_name, encoding='utf-8', strings_only=False, errors='strict') teacher = smart_text(teacher_name, encoding='utf-8', strings_only=False, errors='strict') date_string = smart_text(date_name, encoding='utf-8', strings_only=False, errors='strict') draw.text((370,190), student,(0,0,200),font=font_student) draw.text((490-len(school_name)*20,100), school,(0,0,0),font=font_school) draw.text((470,410), teacher,(0,0,0),font=font_teacher) draw.text((160,410), lesson,(0,0,0),font=font_teacher) draw.text((160,475), date_string ,(0,0,0),font=font_date) del draw # I'm done drawing so I don't need this anymore # We need an HttpResponse object with the correct mimetype #response = HttpResponse(content_type = "image/jpeg") #im.save(response, 'jpeg') #return response # now, we tell the image to save as a PNG to the # provided file-like object temp_handle = StringIO.StringIO() im.save(temp_handle, 'jpeg') temp_handle.seek(0) # open file write mode if not os.path.exists(settings.BASE_DIR+"/static/certificate/"+unit): os.mkdir(settings.BASE_DIR+"/static/certificate/"+unit) context = {'error':''} fileName = settings.BASE_DIR+"/static/certificate/"+unit+"/"+enroll_id+".jpg" writeFile(temp_handle.read(), fileName, context) #update and message title = "<" + teacher_name + u">核發了一張證書給你" #title = smart_text(teacher_name+"--核發了一張證書給你", encoding='utf-8', strings_only=False, errors='strict') url = "/certificate/show/" + unit + "/" + enroll_id message = Message.create(title=title, url=url, time=timezone.now()) message.save() messagepoll = MessagePoll.create(reader_id=enroll.student.id, message_id = message.id) messagepoll.save()
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 = SWork.objects.get(student_id=user_id, index=index) except ObjectDoesNotExist: work3 = SWork(index=index, student_id=user_id) if request.method == 'POST': form = ScoreForm(request.user, request.POST) if form.is_valid(): work = SWork.objects.filter(index=index, student_id=user_id) if not work.exists(): work = SWork(index=index, student_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分--小老師:<' + index.encode('utf-8') + '><' + 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分--作業受評<' + index.encode('utf-8') + '><' + 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") + index.encode( 'utf-8') + ">" 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/work/class/' + classroom_id + '/' + index) else: return redirect('/teacher/score_peer/' + index + '/' + classroom_id + '/' + str(enroll.group)) else: work = SWork.objects.filter(index=index, student_id=user_id) if not work.exists(): form = ScoreForm(user=request.user) else: form = ScoreForm(instance=work[0], user=request.user) return render_to_response('teacher/scoring.html', { 'form': form, 'work': work3, 'student': user, 'classroom_id': classroom_id }, context_instance=RequestContext(request))
def make_image(lesson, unit, enroll_id, teacher_id): ''' A View that Returns a PNG Image generated using PIL''' im = Image.open(settings.BASE_DIR+'/static/certificate/certificate'+lesson+"_"+unit+'.jpg') # create the image draw = ImageDraw.Draw(im) # create a drawing object that is # used to draw on the new image #red = (255,0,0) # color of our text #text_pos = (10,10) # top-left position of our text # Now, we'll do the drawing: font_student = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',60) font_school = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',30) font_teacher = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',50) font_date = ImageFont.truetype(settings.BASE_DIR+'/static/cwTeXQKai-Medium.ttf',50) enroll = Enroll.objects.get(id=enroll_id) #studnet_id = enroll.student.id student_name = User.objects.get(id=enroll.student.id).first_name school_name = u"認證教師:"+School.objects.get(id=User.objects.get(id=teacher_id).last_name).name lesson_name = "高慧君老師" teacher_name = User.objects.get(id=teacher_id).first_name+u"老師" year = timezone.localtime(timezone.now()).year month = timezone.localtime(timezone.now()).month day = timezone.localtime(timezone.now()).day date_name = "中 華 民 國 "+ str(year-1911) + " 年 "+ str(month) + " 月 " + str(day) + " 日" student = smart_text(student_name, encoding='utf-8', strings_only=False, errors='strict') school = smart_text(school_name, encoding='utf-8', strings_only=False, errors='strict') lesson_name = smart_text(lesson_name, encoding='utf-8', strings_only=False, errors='strict') teacher = smart_text(teacher_name, encoding='utf-8', strings_only=False, errors='strict') date_string = smart_text(date_name, encoding='utf-8', strings_only=False, errors='strict') draw.text((450,160), student,(0,0,200),font=font_student) draw.text((500,440), teacher,(0,0,0),font=font_teacher) draw.text((490,405), school_name,(0,0,0),font=font_school) draw.text((160,520), date_string ,(0,0,0),font=font_date) del draw # I'm done drawing so I don't need this anymore # We need an HttpResponse object with the correct mimetype #response = HttpResponse(content_type = "image/jpeg") #im.save(response, 'jpeg') #return response # now, we tell the image to save as a PNG to the # provided file-like object temp_handle = StringIO.StringIO() im.save(temp_handle, 'jpeg') temp_handle.seek(0) # open file write mode if not os.path.exists(settings.BASE_DIR+"/static/certification/"): os.mkdir(settings.BASE_DIR+"/static/certification/") if not os.path.exists(settings.BASE_DIR+"/static/certification/"+lesson): os.mkdir(settings.BASE_DIR+"/static/certification/"+lesson) if not os.path.exists(settings.BASE_DIR+"/static/certification/"+lesson+"/"+unit): os.mkdir(settings.BASE_DIR+"/static/certification/"+lesson+"/"+unit) context = {'error':''} fileName = settings.BASE_DIR+"/static/certification/"+lesson+"/"+unit+"/"+enroll_id+".jpg" writeFile(temp_handle.read(), fileName, context) #update and message title = "<" + teacher_name + u">核發了一張證書給你" #title = smart_text(teacher_name+"--核發了一張證書給你", encoding='utf-8', strings_only=False, errors='strict') url = "/certificate/show/" + lesson + "/" + unit + "/" + enroll_id message = Message.create(title=title, url=url, time=timezone.now()) message.save() messagepoll = MessagePoll(reader_id=enroll.student.id, message_id = message.id) messagepoll.save()
def user_login(request): message = None test = "" if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: if user.id == 1: if user.first_name == "": user.first_name = "管理員" user.save() # create Message title = "請修改您的姓名" url = "/account/realname" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create(message_id = message.id,reader_id=1) messagepoll.save() # 登入成功,導到大廳 login(request, user) # 記錄系統事件 if is_event_open(request) : log = Log(user_id=request.user.id, event='登入系統') log.save() # 記錄訪客資訊 admin_user = User.objects.get(id=1) profile = Profile.objects.get(user=admin_user) profile.visitor_count = profile.visitor_count + 1 profile.save() year = localtime(timezone.now()).year month = localtime(timezone.now()).month day = localtime(timezone.now()).day date_number = year * 10000 + month*100 + day try: visitor = Visitor.objects.get(date=date_number) except ObjectDoesNotExist: visitor = Visitor(date=date_number) visitor.count = visitor.count + 1 visitor.save() visitorlog = VisitorLog(visitor_id=visitor.id, user_id=user.id, IP=request.META.get('REMOTE_ADDR')) visitorlog.save() return redirect('dashboard') else: message = "Your user is inactive" else: # 記錄系統事件 if is_event_open(request) : log = Log(user_id=0, event='登入失敗') log.save() message = "無效的帳號或密碼!" else: form = LoginForm() return render_to_response('registration/login.html', {'test': test, 'message': message, 'form': form}, context_instance=RequestContext(request))
def user_login(request, role): message = None test = "" if request.method == "POST": if role == "0": form = LoginForm(request.POST) else: form = LoginStudentForm(request.POST) if form.is_valid(): teacher = request.POST['teacher'] username = request.POST['username'] password = request.POST['password'] if role == "0": user = authenticate(username=username, password=password) else: user = authenticate(username=teacher + "_" + username, password=password) if user is not None: if user.is_active: if user.id == 1: zones = Zone.objects.all() if len(zones) == 0: for city_name, zones, mapx, mapy in county: city = County(name=city_name, mapx=mapx, mapy=mapy) city.save() for zone_name in zones: zone = Zone(name=zone_name, county=city.id) zone.save() school = School(county=1, zone=9, system=3, name="南港高中") school.save() user.last_name = "1" user.save() if user.first_name == "": user.first_name = "管理員" user.save() try: group = Group.objects.get(name="apply") except ObjectDoesNotExist: group = Group(name="apply") group.save() group.user_set.add(user) # create Message title = "請修改您的姓名" url = "/account/realname" message = Message(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll(message_id=message.id, reader_id=1) messagepoll.save() # 記錄訪客資訊 admin_user = User.objects.get(id=1) try: profile = Profile.objects.get(user=admin_user) except ObjectDoesNotExist: profile = Profile(user=admin_user) profile.save() profile.visitor_count = profile.visitor_count + 1 profile.save() year = localtime(timezone.now()).year month = localtime(timezone.now()).month day = localtime(timezone.now()).day date_number = year * 10000 + month * 100 + day try: visitor = Visitor.objects.get(date=date_number) except ObjectDoesNotExist: visitor = Visitor(date=date_number) except MultipleObjectsReturned: visitor = Visitor.objects.filter(date=date_number)[0] visitor.count = visitor.count + 1 visitor.save() visitorlog = VisitorLog(visitor_id=visitor.id, user_id=user.id, IP=request.META.get('REMOTE_ADDR')) visitorlog.save() # 登入成功,導到大廳 login(request, user) return redirect('/account/dashboard/0') else: message = "帳號未啟用!" else: message = "無效的帳號或密碼!" else: if role == "0": form = LoginForm() else: form = LoginStudentForm() return render(request, 'registration/login.html', { 'role': role, 'message': message, 'form': form })
def user_login(request): message = None test = "" if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: if user.id == 1: if user.first_name == "": user.first_name = "管理員" user.save() # create Message title = "請修改您的姓名" url = "/account/realname" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create( message_id=message.id, reader_id=1) messagepoll.save() # 登入成功,導到大廳 login(request, user) # 記錄系統事件 if is_event_open(request): log = Log(user_id=request.user.id, event='登入系統') log.save() # 記錄訪客資訊 admin_user = User.objects.get(id=1) try: profile = Profile.objects.get(user=admin_user) except ObjectDoesNotExist: profile = Profile(user=admin_user) profile.save() profile.login_count = profile.login_count + 1 profile.save() year = localtime(timezone.now()).year month = localtime(timezone.now()).month day = localtime(timezone.now()).day date_number = year * 10000 + month * 100 + day try: visitor = Visitor.objects.get(date=date_number) except ObjectDoesNotExist: visitor = Visitor(date=date_number) visitor.count = visitor.count + 1 visitor.save() visitorlog = VisitorLog(visitor_id=visitor.id, user_id=user.id, IP=request.META.get('REMOTE_ADDR')) visitorlog.save() return redirect('dashboard') else: message = "Your user is inactive" else: # 記錄系統事件 if is_event_open(request): log = Log(user_id=0, event='登入失敗') log.save() message = "無效的帳號或密碼!" else: form = LoginForm() return render_to_response('registration/login.html', { 'test': test, 'message': message, 'form': form }, context_instance=RequestContext(request))
def student_login(request): message = None test = "" if request.method == "POST": form = StudentLoginForm(request.POST) if form.is_valid(): username = request.POST['teacher'] + "_" + request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: # 登入成功,導到大廳 login(request, user) # 記錄訪客資訊 admin_user = User.objects.get(id=1) try: profile = Profile.objects.get(user=admin_user) except ObjectDoesNotExist: profile = Profile(user=admin_user) profile.save() profile.visitor_count = profile.visitor_count + 1 profile.save() try: profile = Profile.objects.get(user=user) except ObjectDoesNotExist: profile = Profile(user=user) profile.save() # create Message title = "請洽詢任課教師課程名稱及選課密碼" url = "/student/classroom/add" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll(message_id=message.id, reader_id=user.id) messagepoll.save() profile.visitor_count = profile.visitor_count + 1 profile.save() year = localtime(timezone.now()).year month = localtime(timezone.now()).month day = localtime(timezone.now()).day date_number = year * 10000 + month * 100 + day try: visitor = Visitor.objects.get(date=date_number) except ObjectDoesNotExist: visitor = Visitor(date=date_number) visitor.count = visitor.count + 1 visitor.save() visitorlog = VisitorLog(visitor_id=visitor.id, user_id=user.id, IP=request.META.get('REMOTE_ADDR')) visitorlog.save() return redirect('/account/0') else: message = "Your user is inactive" else: message = "無效的帳號或密碼!" else: form = StudentLoginForm() return render(request, 'account/student_login.html', { 'test': test, 'message': message, 'form': form })
def user_login(request): message = None test = "" if request.method == "POST": form = LoginForm(request.POST) if form.is_valid(): username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: if user.is_superuser: mygroup1, created = Group.objects.get_or_create( name='teacher') user.groups.add(mygroup1) mygroup2, created = Group.objects.get_or_create( name='active_teacher') user.groups.add(mygroup2) if user.first_name == "": user.first_name = "管理員" user.save() # create Message title = "請修改您的姓名" url = "/account/realname" message = Message.create(title=title, url=url, time=timezone.now()) message.save() # message for group member messagepoll = MessagePoll.create( message_id=message.id, reader_id=1) messagepoll.save() # 登入成功,導到大廳 login(request, user) # 記錄訪客資訊 admin_user = User.objects.get(id=1) try: profile = Profile.objects.get(user=admin_user) except ObjectDoesNotExist: profile = Profile(user=admin_user) profile.save() profile.visitor_count = profile.visitor_count + 1 profile.save() year = localtime(timezone.now()).year month = localtime(timezone.now()).month day = localtime(timezone.now()).day date_number = year * 10000 + month * 100 + day try: visitor = Visitor.objects.get(date=date_number) except ObjectDoesNotExist: visitor = Visitor(date=date_number) visitor.count = visitor.count + 1 visitor.save() visitorlog = VisitorLog(visitor_id=visitor.id, user_id=user.id, IP=request.META.get('REMOTE_ADDR')) visitorlog.save() return redirect('/account/0') else: message = "Your user is inactive" else: message = "無效的帳號或密碼!" else: form = LoginForm() return render(request, 'registration/login.html', { 'test': test, 'message': message, 'form': form })
def debug_value(request, bug_id): import sys reload(sys) sys.setdefaultencoding("utf-8") # A comment was posted debug = Debug.objects.filter(id=3) debug_value_form = DebugValueForm(data=request.POST) if debug_value_form.is_valid(): try: debug_id = int(debug_value_form.cleaned_data['id']) debug = Debug.objects.get(id=debug_id) url = "/student/bug/" + str(bug_id) if debug_value_form.cleaned_data['reward'] == "0": reward = "沒有解決" msg = u'0分<' + request.user.first_name.encode( 'utf-8') + u'>評價您的除錯<' + reward.encode('utf-8') + '>' elif debug_value_form.cleaned_data['reward'] == "1": reward = "部份解決" msg = u'1分<' + request.user.first_name.encode( 'utf-8') + u'>評價您的除錯<' + reward.encode('utf-8') + '>' elif debug_value_form.cleaned_data['reward'] == "2": reward = "大概解決" msg = u'2分<' + request.user.first_name.encode( 'utf-8') + u'>評價您的除錯<' + reward.encode('utf-8') + '>' elif debug_value_form.cleaned_data['reward'] == "3": reward = "完全解決" msg = u'3分<' + request.user.first_name.encode( 'utf-8') + u'>評價您的除錯<' + reward.encode('utf-8') + '>' # credit if debug.reward < 0: # credit update_avatar(debug.author_id, 3, int(debug_value_form.cleaned_data['reward'])) # History history = PointHistory(user_id=debug.author_id, kind=3, message=msg, url=url) history.save() # create Message message = Message.create(title=msg, url=url, time=timezone.localtime(timezone.now())) message.save() messagepoll = MessagePoll.create(reader_id=debug.author_id, message_id=message.id) messagepoll.save() debug.reward = debug_value_form.cleaned_data['reward'] debug.save() # 記錄系統事件 if is_event_open(request): log = Log(user_id=request.user.id, event=u'評價除錯<' + debug_value_form.cleaned_data['reward'] + u'分><' + debug.author.first_name + '>') log.save() except ObjectDoesNotExist: pass return redirect("/student/bug/" + str(bug_id))