def put(self, mine_guid, variance_guid): variance = Variance.find_by_mine_guid_and_variance_guid( mine_guid, variance_guid) if variance is None: raise NotFound('Unable to fetch variance') data = self.parser.parse_args() inspector_party_guid = data.get('inspector_party_guid') if inspector_party_guid: inspector = Party.find_by_party_guid(inspector_party_guid) if not inspector: raise BadRequest('Unable to find new inspector.') if not 'INS' in inspector.business_roles_codes: raise BadRequest('Party is not an inspector.') variance.inspector_party_guid = inspector_party_guid for key, value in data.items(): if key in ['inspector_party_guid']: continue setattr(variance, key, value) # A manual check to prevent a stack trace dump on a foreign key / # constraint error because global error handling doesn't currently work # with these errors Variance.validate_status_with_other_values( status=variance.variance_application_status_code, issue=variance.issue_date, expiry=variance.expiry_date, inspector=variance.inspector_party_guid) variance.save() return variance
def post(self, mine_guid): data = self.parser.parse_args() compliance_article_id = data['compliance_article_id'] received_date = data['received_date'] inspector_party_guid = data.get('inspector_party_guid') mine = Mine.find_by_mine_guid(mine_guid) if mine is None: raise NotFound('Mine') # A manual check to prevent a stack trace dump on a foreign key / # constraint error because global error handling doesn't currently work # with these errors variance_application_status_code = data.get( 'variance_application_status_code') or 'REV' issue_date = data.get('issue_date') expiry_date = data.get('expiry_date') Variance.validate_status_with_other_values( status=variance_application_status_code, issue=issue_date, expiry=expiry_date, inspector=inspector_party_guid) variance = Variance.create( compliance_article_id=compliance_article_id, mine_guid=mine_guid, received_date=received_date, # Optional fields variance_application_status_code=variance_application_status_code, applicant_guid=data.get('applicant_guid'), inspector_party_guid=inspector_party_guid, note=data.get('note'), parties_notified_ind=data.get('parties_notified_ind'), issue_date=issue_date, expiry_date=expiry_date) if not variance: raise BadRequest('Error: Failed to create variance') variance.save() return variance