示例#1
0
 def post(self):
     data = api.payload
     t = datetime_from_iso8601(data['time'])
     timestamp = int(time.mktime(t.timetuple()))
     data['time'] = timestamp
     uuid = Event.add(data)
     return Event.get(uuid)
示例#2
0
 def field_value(field, value):
     if field.__class__ in (me_fields.ListField, me_fields.SortedListField):
         return [
             field_value(field.field, item)
             for item in value
         ]
     if field.__class__ in (
             me_fields.GenericEmbeddedDocumentField,
             me_fields.GenericReferenceField
     ):
         return field.document_type(**value)
     elif field.__class__ in (
             me_fields.EmbeddedDocumentField,
             me_fields.ReferenceField,) and value is not None:
         f = field.document_type(**value) 
         return merge(f, value)
     elif field.__class__ == me_fields.DateTimeField and isinstance(value, str):
         return datetime_from_iso8601(value)
     else:
         return value
示例#3
0
def save_updated_user(user, data, token):
    if data['birthday']:
        data['birthday'] = inputs.datetime_from_iso8601(data['birthday'])
    user_update = User.query.filter_by(public_id=user.public_id).update(data)
    if not user_update:
        response_object = {
            'status': 'fail',
            'message': 'User doesn\'t exists. Please check given ID.',
        }
        return response_object, 409
    else:
        if token:
            auth_token = token.split(" ")[0]
        else:
            response_object = {
                'status': 'fail',
                'message': 'You must be logged in to update your profil'
            }
            return response_object, 401
        if auth_token:
            user_to_update = User.query.filter_by(
                public_id=user.public_id).first()
            resp = User.decode_auth_token(auth_token)
            to_authentify = User.query.filter_by(id=resp).first()
            if to_authentify.id == user_to_update.id:
                authentified_user = True
            else:
                response_object = {
                    'status': 'fail',
                    'message': 'You can only update your profil'
                }
                return response_object, 401
        if authentified_user:
            db.session.commit()
            response_object = {
                'status': 'success',
                'message': 'User profil successfully updated.',
            }
            return response_object, 201
示例#4
0
 def test_error(self):
     with pytest.raises(ValueError):
         inputs.datetime_from_iso8601('2008-13-13')
示例#5
0
 def test_valid_values(self, value, expected):
     assert inputs.datetime_from_iso8601(value) == expected
示例#6
0
 def test_error(self):
     with assert_raises(ValueError):
         inputs.datetime_from_iso8601('2008-13-13')
示例#7
0
 def post(self):
     args = parser_create_match.parse_args()
     args['datetime'] = datetime_from_iso8601(args['datetime'])
     args['duration'] = datetime.timedelta(seconds=args['duration'])
     return matchespending.create(**args)
示例#8
0
class PermitAmendmentResource(Resource, UserMixin):
    parser = reqparse.RequestParser(trim=True)

    parser.add_argument(
        'permittee_party_guid',
        type=str,
        help='GUID of the party that is the permittee for this permit.',
        location='json')
    parser.add_argument(
        'received_date',
        location='json',
        type=lambda x: inputs.datetime_from_iso8601(x) if x else None,
        store_missing=False)
    parser.add_argument(
        'issue_date',
        location='json',
        type=lambda x: inputs.datetime_from_iso8601(x) if x else None,
        store_missing=False)
    parser.add_argument(
        'authorization_end_date',
        location='json',
        type=lambda x: inputs.datetime_from_iso8601(x) if x else None,
        store_missing=False)
    parser.add_argument(
        'permit_amendment_type_code', type=str, location='json', store_missing=False)
    parser.add_argument(
        'permit_amendment_status_code', type=str, location='json', store_missing=False)
    parser.add_argument('description', type=str, location='json', store_missing=False)
    parser.add_argument('security_total', type=str, location='json', store_missing=False)
    parser.add_argument('uploadedFiles', type=list, location='json', store_missing=False)

    @api.doc(params={'permit_amendment_guid': 'Permit amendment guid.'})
    @requires_role_view_all
    @api.marshal_with(PERMIT_AMENDMENT_MODEL, code=200)
    def get(self, mine_guid, permit_guid, permit_amendment_guid):
        permit_amendment = PermitAmendment.find_by_permit_amendment_guid(permit_amendment_guid)
        if not permit_amendment:
            raise NotFound("Permit Amendment not found.")
        if not str(permit_amendment.mine_guid) == mine_guid:
            raise BadRequest('Permits mine_guid and supplied mine_guid mismatch.')
        return permit_amendment

    @api.doc(params={
        'permit_amendment_guid': 'Permit amendment guid.',
        'permit_guid': 'Permit GUID'
    })
    @requires_role_edit_permit
    @api.marshal_with(PERMIT_AMENDMENT_MODEL, code=200)
    def put(self, mine_guid, permit_guid, permit_amendment_guid):
        permit_amendment = PermitAmendment.find_by_permit_amendment_guid(permit_amendment_guid)
        if not permit_amendment:
            raise NotFound("Permit Amendment not found.")
        if not str(permit_amendment.mine_guid) == mine_guid:
            raise BadRequest('Permits mine_guid and supplied mine_guid mismatch.')

        data = self.parser.parse_args()
        current_app.logger.info(f'updating {permit_amendment} with >> {data}')

        for key, value in data.items():
            if key == 'uploadedFiles':
                for newFile in value:
                    new_pa_doc = PermitAmendmentDocument(
                        document_name=newFile['fileName'],
                        document_manager_guid=newFile['document_manager_guid'],
                        mine_guid=permit_amendment.mine_guid,
                    )
                    permit_amendment.related_documents.append(new_pa_doc)
            else:
                setattr(permit_amendment, key, value)

        permit_amendment.save()

        return permit_amendment

    @api.doc(params={
        'permit_amendment_guid': 'Permit amendment guid.',
        'permit_guid': 'Permit GUID'
    })
    @requires_role_mine_admin
    @api.response(204, 'Successfully deleted.')
    def delete(self, mine_guid, permit_guid, permit_amendment_guid):
        permit_amendment = PermitAmendment.find_by_permit_amendment_guid(permit_amendment_guid)
        if not permit_amendment:
            raise NotFound("Permit Amendment not found.")
        if not str(permit_amendment.mine_guid) == mine_guid:
            raise BadRequest('Permits mine_guid and supplied mine_guid mismatch.')

        try:
            permit_amendment.soft_delete()
        except Exception as e:
            raise BadRequest(e)

        return
示例#9
0
 def test_valid_values(self, value, expected):
     assert inputs.datetime_from_iso8601(value) == expected