def get_context_data(self, **kwargs): ctx = super(ReviewListView, self).get_context_data(**kwargs) try : review = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: review = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) review.save() show = ShowGroup.objects.get(id=self.kwargs['show_id']) members = Enroll.objects.filter(group_show=self.kwargs['show_id']) reviews = ShowReview.objects.filter(show_id=self.kwargs['show_id'], done=True) score1 = reviews.aggregate(Sum('score1')).values()[0] score2 = reviews.aggregate(Sum('score2')).values()[0] score3 = reviews.aggregate(Sum('score3')).values()[0] score = [review.score1, review.score2, review.score3] if reviews.count() > 0 : score1 = score1 / reviews.count() score2 = score2 / reviews.count() score3 = score3 / reviews.count() scores = [math.ceil(score1*10)/10, math.ceil(score2*10)/10, math.ceil(score3*10)/10, score1+score2+score3, reviews.count()] else : scores = [0,0,0,0] ctx['scores'] = scores ctx['show'] = show ctx['members'] = members round = Round.objects.get(id=show.round_id) ctx['teacher'] = is_teacher(self.request.user, round.classroom_id) return ctx
def group_add(request, classroom_id): classroom_name = Classroom.objects.get(id=classroom_id).name if request.method == 'POST': form = GroupForm(request.POST) if form.is_valid(): group = ShowGroup(name=form.cleaned_data['name'], classroom_id=int(classroom_id)) group.save() enrolls = Enroll.objects.filter(classroom_id=classroom_id) for enroll in enrolls: review = ShowReview(show_id=group.id, student_id=enroll.student_id) review.save() # 記錄系統事件 if is_event_open(request): log = Log(user_id=request.user.id, event=u'新增創意秀組別<' + group.name + '><' + classroom_name + '>') log.save() return redirect('/show/group/' + classroom_id) else: form = GroupForm() return render_to_response('show/group_add.html', {'form': form}, context_instance=RequestContext(request))
def get_context_data(self, **kwargs): ctx = super(ReviewListView, self).get_context_data(**kwargs) try: review = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: review = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) review.save() show = ShowGroup.objects.get(id=self.kwargs['show_id']) members = Enroll.objects.filter(group_show=self.kwargs['show_id']) reviews = ShowReview.objects.filter(show_id=self.kwargs['show_id'], done=True) score1 = reviews.aggregate(Sum('score1')).values()[0] score2 = reviews.aggregate(Sum('score2')).values()[0] score3 = reviews.aggregate(Sum('score3')).values()[0] score = [review.score1, review.score2, review.score3] if reviews.count() > 0: score1 = score1 / reviews.count() score2 = score2 / reviews.count() score3 = score3 / reviews.count() scores = [ math.ceil(score1 * 10) / 10, math.ceil(score2 * 10) / 10, math.ceil(score3 * 10) / 10, reviews.count() ] else: scores = [0, 0, 0, 0] ctx['scores'] = scores ctx['show'] = show ctx['members'] = members return ctx
def get_object(self, queryset=None): try : obj = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: obj = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) obj.save() return obj
def get_object(self, queryset=None): try: obj = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: obj = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) obj.save() return obj
def get_queryset(self): lists = {} counter = 0 enrolls = Enroll.objects.filter( classroom_id=self.kwargs['classroom_id']).order_by('seat') classroom_name = Classroom.objects.get( id=self.kwargs['classroom_id']).name for enroll in enrolls: lists[enroll.id] = [] shows = ShowGroup.objects.filter( classroom_id=self.kwargs['classroom_id']) if not shows.exists(): lists[enroll.id].append([enroll]) else: for show in shows: members = Enroll.objects.filter(group_show=show.id) try: review = ShowReview.objects.get( show_id=show.id, student_id=enroll.student_id) except ObjectDoesNotExist: review = ShowReview(show_id=show.id) lists[enroll.id].append([enroll, review, show, members]) lists = OrderedDict( sorted(lists.items(), key=lambda x: x[1][0][0].seat)) # 記錄系統事件 if is_event_open(self.request): log = Log(user_id=self.request.user.id, event=u'查看創意秀評分狀況<' + classroom_name + '>') log.save() return lists
def get(self, request, **kwargs): show = ShowGroup.objects.get(id=self.kwargs['show_id']) try: self.object = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: self.object = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) self.object.save() reviews = ShowReview.objects.filter(show_id=self.kwargs['show_id'], done=True) score1 = reviews.aggregate(Sum('score1')).values()[0] score2 = reviews.aggregate(Sum('score2')).values()[0] score3 = reviews.aggregate(Sum('score3')).values()[0] score = [self.object.score1, self.object.score2,self.object.score3] if reviews.count() > 0 : score1 = score1 / reviews.count() score2 = score2 / reviews.count() score3 = score3 / reviews.count() scores = [math.ceil(score1*10)/10, math.ceil(score2*10)/10, math.ceil(score3*10)/10, reviews.count()] else : scores = [0,0,0,0] members = Enroll.objects.filter(group_show=self.kwargs['show_id']) form_class = self.get_form_class() form = self.get_form(form_class) showfiles = ShowFile.objects.filter(show_id=self.kwargs['show_id']).order_by("-id") round = Round.objects.get(id=self.kwargs['round_id']) teacher = is_teacher(self.request.user, round.classroom_id) context = self.get_context_data(teacher=teacher, showfiles=showfiles, show=show, form=form, members=members, review=self.object, scores=scores, score=score, reviews=reviews) return self.render(request, context)
def get(self, request, **kwargs): show = ShowGroup.objects.get(id=self.kwargs['show_id']) try: self.object = ShowReview.objects.get( show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: self.object = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) self.object.save() reviews = ShowReview.objects.filter(show_id=self.kwargs['show_id'], done=True) score1 = reviews.aggregate(Sum('score1')).values()[0] score2 = reviews.aggregate(Sum('score2')).values()[0] score3 = reviews.aggregate(Sum('score3')).values()[0] score = [self.object.score1, self.object.score2, self.object.score3] if reviews.count() > 0: score1 = score1 / reviews.count() score2 = score2 / reviews.count() score3 = score3 / reviews.count() scores = [ math.ceil(score1 * 10) / 10, math.ceil(score2 * 10) / 10, math.ceil(score3 * 10) / 10, reviews.count() ] else: scores = [0, 0, 0, 0] members = Enroll.objects.filter(group_show=self.kwargs['show_id']) form_class = self.get_form_class() form = self.get_form(form_class) showfiles = ShowFile.objects.filter( show_id=self.kwargs['show_id']).order_by("-id") round = Round.objects.get(id=self.kwargs['round_id']) teacher = is_teacher(self.request.user, round.classroom_id) context = self.get_context_data(teacher=teacher, showfiles=showfiles, show=show, form=form, members=members, review=self.object, scores=scores, score=score, reviews=reviews) return self.render_to_response(context)
def group_add(request, round_id): show = Round.objects.get(id=round_id) classroom_id = show.classroom_id classroom_name = Classroom.objects.get(id=classroom_id).name if request.method == 'POST': form = GroupForm(request.POST) if form.is_valid(): group = ShowGroup(name=form.cleaned_data['name'],round_id=int(round_id)) group.save() enrolls = Enroll.objects.filter(classroom_id=classroom_id) for enroll in enrolls : review = ShowReview(show_id=group.id, student_id=enroll.student_id) review.save() # 記錄系統事件 if is_event_open(request) : log = Log(user_id=request.user.id, event=u'新增創意秀組別<'+group.name+'><'+classroom_name+'>') log.save() return redirect('/show/group/'+round_id) else: form = GroupForm() return render(request, 'show/group_add.html', {'form':form})
class ReviewUpdateView(UpdateView): model = ShowReview form_class = ReviewForm template_name_suffix = '_review' def get(self, request, **kwargs): show = ShowGroup.objects.get(id=self.kwargs['show_id']) try: self.object = ShowReview.objects.get( show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: self.object = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) self.object.save() reviews = ShowReview.objects.filter(show_id=self.kwargs['show_id'], done=True) score1 = reviews.aggregate(Sum('score1')).values()[0] score2 = reviews.aggregate(Sum('score2')).values()[0] score3 = reviews.aggregate(Sum('score3')).values()[0] score = [self.object.score1, self.object.score2, self.object.score3] if reviews.count() > 0: score1 = score1 / reviews.count() score2 = score2 / reviews.count() score3 = score3 / reviews.count() scores = [ math.ceil(score1 * 10) / 10, math.ceil(score2 * 10) / 10, math.ceil(score3 * 10) / 10, reviews.count() ] else: scores = [0, 0, 0, 0] members = Enroll.objects.filter(group_show=self.kwargs['show_id']) form_class = self.get_form_class() form = self.get_form(form_class) context = self.get_context_data(show=show, form=form, members=members, review=self.object, scores=scores, score=score, reviews=reviews) return self.render_to_response(context) def get_object(self, queryset=None): try: obj = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: obj = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) obj.save() return obj def form_valid(self, form): show = ShowGroup.objects.get(id=self.kwargs['show_id']) #save object obj = form.save(commit=False) if obj.done == False: classroom_id = ShowGroup.objects.get( id=self.kwargs['show_id']).classroom_id member = Enroll.objects.get(classroom_id=classroom_id, student_id=self.request.user.id) # credit update_avatar(member.student, 4, 1) # History show = ShowGroup.objects.get(id=self.kwargs['show_id']) history = PointHistory(user_id=member.student_id, kind=4, message=u'1分--評分創意秀<' + show.title + '>', url='/show/detail/' + str(show.id)) history.save() obj.publish = timezone.now() obj.done = True obj.save() # 記錄系統事件 if is_event_open(self.request): log = Log(user_id=self.request.user.id, event=u'評分創意秀<' + show.name + '>') log.save() return redirect('/show/detail/' + self.kwargs['show_id'])
class ReviewUpdateView(UpdateView): model = ShowReview form_class = ReviewForm template_name_suffix = '_review' def get(self, request, **kwargs): show = ShowGroup.objects.get(id=self.kwargs['show_id']) try: self.object = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: self.object = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) self.object.save() reviews = ShowReview.objects.filter(show_id=self.kwargs['show_id'], done=True) score1 = reviews.aggregate(Sum('score1')).values()[0] score2 = reviews.aggregate(Sum('score2')).values()[0] score3 = reviews.aggregate(Sum('score3')).values()[0] score = [self.object.score1, self.object.score2,self.object.score3] if reviews.count() > 0 : score1 = score1 / reviews.count() score2 = score2 / reviews.count() score3 = score3 / reviews.count() scores = [math.ceil(score1*10)/10, math.ceil(score2*10)/10, math.ceil(score3*10)/10, reviews.count()] else : scores = [0,0,0,0] members = Enroll.objects.filter(group_show=self.kwargs['show_id']) form_class = self.get_form_class() form = self.get_form(form_class) showfiles = ShowFile.objects.filter(show_id=self.kwargs['show_id']).order_by("-id") round = Round.objects.get(id=self.kwargs['round_id']) teacher = is_teacher(self.request.user, round.classroom_id) context = self.get_context_data(teacher=teacher, showfiles=showfiles, show=show, form=form, members=members, review=self.object, scores=scores, score=score, reviews=reviews) return self.render(request, context) def get_object(self, queryset=None): try : obj = ShowReview.objects.get(show_id=self.kwargs['show_id'], student_id=self.request.user.id) except ObjectDoesNotExist: obj = ShowReview(show_id=self.kwargs['show_id'], student_id=self.request.user.id) obj.save() return obj def form_valid(self, form): show = ShowGroup.objects.get(id=self.kwargs['show_id']) #save object obj = form.save(commit=False) if obj.done == False: round_id = ShowGroup.objects.get(id=self.kwargs['show_id']).round_id classroom_id = Round.objects.get(id=round_id).classroom_id member = Enroll.objects.get(classroom_id=classroom_id, student_id=self.request.user.id) # credit update_avatar(member.student, 4, 1) # History show = ShowGroup.objects.get(id=self.kwargs['show_id']) history = PointHistory(user_id=member.student_id, kind=4, message=u'1分--評分創意秀<'+show.title+'>', url='/show/detail/'+str(show.id)) history.save() obj.publish = timezone.now() obj.done = True obj.save() # 記錄系統事件 if is_event_open(self.request) : log = Log(user_id=self.request.user.id, event=u'評分創意秀<'+show.name+'>') log.save() return redirect('/show/detail/'+self.kwargs['round_id']+'/'+self.kwargs['show_id'])