Beispiel #1
0
    def get(self):
        """
        학생 외출 정보 확인
        """
        goingout = GoingoutApplyModel.objects(student=g.user).first()

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

        return {'sat': goingout.on_saturday, 'sun': goingout.on_sunday}
Beispiel #2
0
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)
    def get(self):
        """
        학생 외출 정보 확인
        """
        goingout = GoingoutApplyModel.objects(studnt=g.user).first()

        return {'sat': goingout.on_saturday, 'sun': goingout.on_sunday}
    def testApplySuccess(self):
        # (1) 외출신청
        resp = self._request()

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

        # (3) 데이터베이스 확인
        self.assertTrue(GoingoutApplyModel.objects(student=self.student, on_saturday=self.sat, on_sunday=self.sun))
Beispiel #5
0
    def get(self):
        """
        외출신청 정보 조회
        """
        student = g.user

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

        return self.unicode_safe_json_response(
            {
                'sat': apply.on_saturday,
                'sun': apply.on_sunday
            }, 200)
Beispiel #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() < 5) or (
                    now.weekday() == 5 and now.time() < time(22, 00)):
            sat = request.form['sat'].upper() == 'TRUE'
            sun = request.form['sun'].upper() == 'TRUE'

            GoingoutApplyModel.objects(student=student).delete()
            GoingoutApplyModel(student=student,
                               on_saturday=sat,
                               on_sunday=sun,
                               apply_date=datetime.now()).save()

            return Response('', 201)
        else:
            return Response('', 204)
Beispiel #7
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() < 5) or (now.weekday() == 5 and now.time() < time(22, 00)):
            GoingoutApplyModel(student=g.user, on_saturday=payload['sat'], on_sunday=payload['sun']).save()

            return Response('', 201)

        return Response('', 204)
Beispiel #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
        }
    def testInquireWithAppliment(self):
        apply = GoingoutApplyModel(
            student=self.student,
            on_saturday=True,
            on_sunday=False
        ).save()

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

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

        # (3) response data
        self.assertDictEqual(resp.json, {
            'sat': apply.on_saturday,
            'sun': apply.on_sunday
        })
Beispiel #10
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
            })