Пример #1
0
    def validate_fields(self, data, original_data):
        is_patch_request = 'id' in original_data['data']
        if is_patch_request:
            try:
                session = Session.query.filter_by(
                    id=original_data['data']['id']).one()
            except NoResultFound:
                raise ObjectNotFound({'parameter': '{id}'},
                                     "Session: not found")

            if 'starts_at' not in data:
                data['starts_at'] = session.starts_at

            if 'ends_at' not in data:
                data['ends_at'] = session.ends_at

            if 'event' not in data:
                data['event'] = session.event_id

        if data['starts_at'] and data['ends_at']:
            if data['starts_at'] >= data['ends_at']:
                raise UnprocessableEntityError(
                    {'pointer': '/data/attributes/ends-at'},
                    "ends-at should be after starts-at",
                )
            if not is_patch_request and datetime.timestamp(
                    data['starts_at']) <= datetime.timestamp(datetime.now()):
                raise UnprocessableEntityError(
                    {'pointer': '/data/attributes/starts-at'},
                    "starts-at should be after current date-time",
                )

        if 'state' in data:
            if data['state'] not in ('draft', 'pending'):
                if not has_access('is_coorganizer', event_id=data['event']):
                    raise ForbiddenError({'source': ''},
                                         'Co-organizer access is required.')

        if 'track' in data:
            if not has_access('is_coorganizer', event_id=data['event']):
                raise ForbiddenError({'source': ''},
                                     'Co-organizer access is required.')

        if 'microlocation' in data:
            if not has_access('is_coorganizer', event_id=data['event']):
                raise ForbiddenError({'source': ''},
                                     'Co-organizer access is required.')

        validate_complex_fields_json(self, data, original_data)
Пример #2
0
 def validate_json(self, data, original_data):
     validate_complex_fields_json(self, data, original_data)