Exemple #1
0
    def get(self):
        """
        학생 잔류 신청 확인
        """
        stay = StayApplyModel.objects(student=g.user).first()

        if not stay:
            stay = StayApplyModel(
                student=g.user,
                value=4
            ).save()

        return {
            'value': stay.value
        }
class StudentModel(AccountBase):
    """
    Student account model
    """
    meta = {'collection': 'account_student'}

    number = IntField(required=True, min_value=1101, max_value=3421)

    extension_apply_11 = EmbeddedDocumentField(
        document_type=ExtensionApplyModel)
    extension_apply_12 = EmbeddedDocumentField(
        document_type=ExtensionApplyModel)
    goingout_apply = EmbeddedDocumentField(document_type=GoingoutApplyModel,
                                           default=GoingoutApplyModel())
    stay_apply = EmbeddedDocumentField(document_type=StayApplyModel,
                                       default=StayApplyModel())

    good_point = IntField(default=0)

    bad_point = IntField(default=0)

    point_histories = ListField(
        ReferenceField(document_type=PointHistoryModel,
                       reverse_delete_rule=CASCADE))

    penalty_training_status = BooleanField(default=False)
    penalty_level = IntField(default=0)
Exemple #3
0
    def generate_excel(self):
        wb, ws = self.ready_worksheet()

        for apply in self.model.objects:
            student = apply.student

            number_cell, name_cell, status_cell = get_cell_positions_from_student_number(student)

            stay_apply = StayApplyModel.objects(student=student).first()

            if stay_apply.value < 3:
                ws[number_cell] = None
                ws[name_cell] = None
                continue
            else:
                ws[number_cell] = student.number
                ws[name_cell] = student.name

            ws.column_dimensions['D'].width = 20
            ws.column_dimensions['H'].width = 20
            ws.column_dimensions['L'].width = 20
            ws.column_dimensions['P'].width = 20

            ws[status_cell] = self.get_status(apply)

        self.save_excel(wb)
Exemple #4
0
    def testApplySuccess(self):
        # (1) 잔류신청
        resp = self._request()

        # (2) status code 201
        self.assertEqual(resp.status_code, 201)

        # (3) 데이터베이스 확인
        self.assertTrue(
            StayApplyModel.objects(student=self.student, value=self.value))
Exemple #5
0
    def testInquireWithAppliment(self):
        apply = StayApplyModel(student=self.student, value=1).save()

        # (1) 별도의 신청 정보가 있는 상태에서 조회
        resp = self._request()

        # (2) status code 200
        self.assertEqual(resp.status_code, 200)

        # (3) response data
        self.assertDictEqual(resp.json, {'value': apply.value})
Exemple #6
0
    def post(self):
        """
        잔류신청
        """
        student = g.user

        now = datetime.now()

        if current_app.testing or (now.weekday() == 6 and now.time() > time(20, 30)) or (0 <= now.weekday() < 3) or (now.weekday() == 3 and now.time() < time(22, 00)):
            # 신청 가능 범위
            # - 일요일 오후 8시 30분 이후부터 목요일 오후 10시까지
            # weekday는 월요일이 0, 일요일이 6
            value = int(request.form['value'])

            StayApplyModel.objects(student=student).delete()
            StayApplyModel(student=student, value=value, apply_date=datetime.now()).save()

            return Response('', 201)
        else:
            return Response('', 204)
Exemple #7
0
    def get(self):
        """
        잔류신청 정보 조회
        """
        student = g.user

        apply = StayApplyModel.objects(student=student).first()

        return self.unicode_safe_json_response({
            'value': apply.value
        }, 200)
Exemple #8
0
    def get(self):
        """
        학생 신청 정보 확인
        """
        extension11 = ExtensionApply11Model.objects(student=g.user).first()
        extension12 = ExtensionApply12Model.objects(student=g.user).first()
        goingout = GoingoutApplyModel.objects(student=g.user).first()
        stay = StayApplyModel.objects(student=g.user).first()

        if not goingout:
            goingout = GoingoutApplyModel(
                student=g.user,
                on_saturday=False,
                on_sunday=False
            ).save()

        if not stay:
            stay = StayApplyModel(
                student=g.user,
                value=4
            ).save()

        return {
            'extension11': {
                'classNum': extension11.class_,
                'seatNum': extension11.seat
            } if extension11 else None,
            'extension12': {
                'classNum': extension12.class_,
                'seatNum': extension12.seat
            } if extension12 else None,
            'goingout': {
                'sat': goingout.on_saturday,
                'sun': goingout.on_sunday
            },
            'stay': stay.value
        }
Exemple #9
0
    def get(self):
        """
        외출신청 엑셀 다운로드
        """
        wb = Workbook()
        ws = wb.active

        ready_applyment_worksheet(ws)

        for apply in GoingoutApplyModel.objects:
            student = apply.student

            number_cell, name_cell, status_cell = get_cell_positions_from_student_number(
                student)

            stay_apply = StayApplyModel.objects(student=student).first()

            if stay_apply.value < 3:
                ws[number_cell] = None
                ws[name_cell] = None
                continue
            else:
                ws[number_cell] = student.number
                ws[name_cell] = student.name

            if apply.on_saturday and apply.on_sunday:
                status = '토요일, 일요일 외출'
            elif apply.on_saturday:
                status = '토요일 외출'
            elif apply.on_sunday:
                status = '일요일 외출'
            else:
                status = ''
            ws.column_dimensions['D'].width = 20
            ws.column_dimensions['H'].width = 20
            ws.column_dimensions['L'].width = 20
            ws.column_dimensions['P'].width = 20

            ws[status_cell] = status

        filename = 'goingout.xlsx'

        wb.save('{}'.format(filename))
        wb.close()

        resp = make_response(send_from_directory('../', filename))
        resp.headers.extend({'Cache-Control': 'no-cache'})

        return resp
Exemple #10
0
    def post(self):
        """
        학생 잔류 신청
        """
        payload = request.json

        now = datetime.now()

        if current_app.testing or (now.weekday() == 6 and now.time() > time(20, 30)) or (0 <= now.weekday() < 3) or (now.weekday() == 3 and now.time() < time(23, 00)):
            # 신청 가능 범위
            # - 일요일 오후 8시 30분 이후부터 목요일 오후 10시까지
            StayApplyModel(student=g.user, value=payload['value']).save()

            return Response('', 201)
        else:
            return Response('', 204)
Exemple #11
0
    def generate_excel(self):
        wb, ws = self.ready_worksheet()

        for apply in self.model.objects:
            student = apply.student

            number_cell, name_cell, status_cell = get_cell_positions_from_student_number(
                student)

            ws[number_cell] = student.number
            ws[name_cell] = student.name

            apply = StayApplyModel.objects(student=student).first()

            ws[status_cell] = self.get_status(apply)

        self.save_excel(wb)
Exemple #12
0
    def get(self):
        """
        잔류신청 엑셀 다운로드
        """
        wb = Workbook()
        ws = wb.active

        ready_applyment_worksheet(ws)

        for student in StudentModel.objects:
            number_cell, name_cell, status_cell = get_cell_positions_from_student_number(
                student)

            ws[number_cell] = student.number
            ws[name_cell] = student.name

            apply = StayApplyModel.objects(student=student).first()

            if not apply or apply.value == 4:
                status = '잔류'
            elif apply.value == 1:
                status = '금요 귀가'
            elif apply.value == 2:
                status = '토요 귀가'
            elif apply.value == 3:
                status = '토요 귀사'
            else:
                status = '잔류'

            ws[status_cell] = status

        filename = 'stay.xlsx'

        wb.save('{}'.format(filename))
        wb.close()

        resp = make_response(send_from_directory('../', filename))
        resp.headers.extend({'Cache-Control': 'no-cache'})

        return resp
Exemple #13
0
    def testAfterApply(self):
        extension_apply_11 = ExtensionApply11Model(student=self.student,
                                                   class_=1,
                                                   seat=15).save()

        extension_apply_12 = ExtensionApply12Model(student=self.student,
                                                   class_=3,
                                                   seat=13).save()

        goingout_apply = GoingoutApplyModel(student=self.student,
                                            on_saturday=True,
                                            on_sunday=False).save()

        stay_apply = StayApplyModel(student=self.student, value=1).save()

        # (1) 신청 정보 확인
        resp = self._request()

        # (2) status code 200
        self.assertEqual(resp.status_code, 200)

        # (3) response data
        self.assertDictEqual(
            resp.json, {
                'extension11': {
                    'classNum': extension_apply_11.class_,
                    'seatNum': extension_apply_11.seat
                },
                'extension12': {
                    'classNum': extension_apply_12.class_,
                    'seatNum': extension_apply_12.seat
                },
                'goingout': {
                    'sat': goingout_apply.on_saturday,
                    'sun': goingout_apply.on_sunday
                },
                'stay': stay_apply.value
            })
Exemple #14
0
 def get(self):
     """
     학생 잔류 신청 확인
     """
     return {'value': StayApplyModel.objects(student=g.user).first().value}