예제 #1
0
 def post(self, request: Request, id, *args, **kwargs):
     _position = request.data.get('position')
     _worker = request.data.get('worker')
     attention_table = AttentionTable.objects.get(pk=id)
     position = Position.objects.get(id=_position)
     worker = Worker.objects.get(id=_worker)
     department = request.user.user.department
     if (position.department == department) and (attention_table.department == department) and (
                 worker.position.department == department):
         pass
     else:
         return Response(data={'error': '错误的部门信息'}, status=status.HTTP_400_BAD_REQUEST)
     new = AttentionDetail(worker=worker, position=position, study=True)
     new.save()
     attention_table.person.add(new)
     print(attention_table.person.all())
     return Response(status=status.HTTP_201_CREATED)
예제 #2
0
    def list(self, request: Request, *args, **kwargs):
        default = get_current_class()
        date = request.GET.get('date', default=default.date)
        day_number = request.GET.get('day-number', default=default.day_number)
        department = request.user.user.department
        try:
            attention_table = AttentionTable.objects.get(date=date, day_number=day_number, department=department)
        except exceptions.ObjectDoesNotExist:
            department = request.user.user.department
            workers = Worker.objects.filter(position__department=request.user.user.department,
                                            class_number=CallOverNumber.objects.get(date=date,
                                                                                    day_number=day_number).class_number)
            attention_table = AttentionTable(department=department, date=date, day_number=day_number, lock=False)
            attention_table.save()
            for worker in workers:
                new = AttentionDetail(
                    worker=worker,
                    position=worker.position,
                    study=worker.is_study,
                )
                new.save()
                attention_table.person.add(new)
        try:
            call_over_table = CallOverDetail.objects.get(
                date=date,
                day_number=day_number,
                department=department
            )
            end = True if call_over_table.end_time else False
        except exceptions.ObjectDoesNotExist:
            end = False

        if end:
            return ErrorResponse("点名会已结束,请在查询页面查询出勤人员")
        scrapy_data = attention_table.scrapy.all()
        can_add_workers = Worker.objects.all()
        had_attention = attention_table.person.all()
        for worker in had_attention:
            can_add_workers = can_add_workers.exclude(pk=worker.worker_id)
        can_add_workers.filter(position__department=request.user.user.department)
        return Response(data={'attend': self.get_serializer_class()(attention_table).data,
                              'id': attention_table.id,
                              'lock': attention_table.lock,
                              'replace': WorkerSer(can_add_workers, many=True).data},
                        status=status.HTTP_200_OK)