コード例 #1
0
    def __check_post_params(self, request_data):
        comments_enabled = request_data.get('comments_enabled')
        if comments_enabled is not None:
            check_boolean_field(comments_enabled)

        text = request_data.get('text')
        if text is not None:
            check_field_length(text, MIN_POST_TEXT_LENGTH)

        location_uid = request_data.get('location_uid')
        location = Location.get_active(uid=location_uid)
        if bool(location_uid) != bool(location):
            raise ResourceNotFound('`location_uid` not found')

        request_blobs = request_data.get('blobs')
        if not isinstance(request_blobs, list):
            raise BadRequest('`blobs` must be an array')

        post_slides = []
        for blob_uid in request_blobs:
            try:
                blob = Blob.get_active(uid=blob_uid)
                post_slides.append(blob)
            except :
                raise ResourceNotFound('Blob `{}` not found'.format(blob_uid))

        return dict(
            post_slides=post_slides,
            comments_enabled=comments_enabled,
            location=location,
            text=text)
コード例 #2
0
    def patch(self, location_uid):
        request_data = get_current_request_data()

        location = Location.get_active(uid=location_uid)
        if location is None:
            raise ResourceNotFound('Location not found')

        params = self.__validate_location_update_params(request_data)

        location = self.edit_location(location, params)

        return location.as_json()
コード例 #3
0
    def get(self, location_uid):
        location = Location.get_active(uid=location_uid)
        if location is None:
            raise ResourceNotFound('Location not found')

        return location.as_json()