Exemplo n.º 1
0
    def post(self):
        current_app.logger.debug('Attempting to load application')
        try:
            application = Application._schema().load(request.json)
        except MarshmallowError as e:
            raise BadRequest(e)

        if application.application_guid is not None:
            raise BadRequest(
                f'messageid: {application.messageid} already exists.')

        if application.applicant.clientid == application.submitter.clientid:
            application.submitter = application.applicant
        current_app.logger.debug('Attempting to load the mine')
        mine = Mine.find_by_mine_no(application.minenumber)

        if mine is None:
            raise BadRequest('Mine not found from the minenumber supplied.')

        application.mine = mine

        application.now_application_identity = NOWApplicationIdentity(
            mine=mine,
            mine_guid=mine.mine_guid,
            now_submission=application,
            now_number=NOWApplicationIdentity.create_now_number(mine))
        current_app.logger.debug('Attempting to Save')
        application.save()
        return application, 201
Exemplo n.º 2
0
    def post(self):
        data = self.parser.parse_args()
        mine = Mine.find_by_mine_guid(data['mine_guid'])
        permit = Permit.find_by_permit_guid(data['permit_guid'])
        err_str = ''
        if not mine:
            err_str += 'Mine not Found. '
        if not permit:
            err_str += 'Permit not Found. '
        if mine and not mine.major_mine_ind:
            err_str += 'Permit Applications can only be created on mines where major_mine_ind=True'
        if err_str:
            raise BadRequest(err_str)
        new_now = NOWApplicationIdentity(mine_guid=data['mine_guid'], permit=permit)
        new_now.now_application = NOWApplication(
            notice_of_work_type_code=data['notice_of_work_type_code'],
            now_application_status_code='REC',
            submitted_date=data['submitted_date'],
            received_date=data['received_date'])

        new_now.save()
        return new_now, 201