コード例 #1
0
 def post(self, request, subject_id):
     subject = Subject.objects.get(id=subject_id)
     is_hod = is_user_hod(request, subject)
     staff_list = subject.staff.all()
     try:
         if is_hod:
             form = AssignOrRemoveStaffForm(request.POST)
             if form.is_valid():
                 for staff_id in form.cleaned_data['staffselect']:
                     staff = User.objects.get(id=staff_id)
                     subject.staff.remove(staff)
                     subject.save()
             else:
                 self.error = 'Something went wrong.'
                 self.status = 500
                 raise
         else:
             self.error = 'You are not an HOD'
             self.status = 403
     except:
         return render(request, self.template,
                       {
                           'is_hod': is_hod,
                           'staff_list': staff_list,
                           'subject': subject,
                           'error': self.error
                       }, status=self.status)
     return HttpResponseRedirect('/subject/' + subject_id)
コード例 #2
0
 def post(self, request, subject_id):
     subject = Subject.objects.get(id=subject_id)
     is_hod = is_user_hod(request, subject)
     staff_list = {}
     for department in Department.objects.all():
         staff_list[department.name] = [x.user for
                                        x in department.profile_set.all()
                                        if is_user_hod_or_teacher(x)]
     try:
         if is_hod:
             form = AssignOrRemoveStaffForm(request.POST)
             if form.is_valid():
                 for staff_id in form.cleaned_data['staffselect']:
                     staff = User.objects.get(id=staff_id)
                     subject.staff.add(staff)
             else:
                 self.error = 'Something went wrong.'
                 self.status = 500
                 raise
         else:
             self.error = 'You are not an HOD'
             self.status = 403
     except:
         return render(request, self.template,
                       {
                           'is_hod': is_hod,
                           'staff_list': staff_list,
                           'subject': subject,
                           'error': self.error
                       }, status=self.status)
     return HttpResponseRedirect('/subject/' + subject_id)