Example #1
0
    def get_example_list_model(self, content_type):
        user = User.create(
            user_name='HalIncandenza',
            password='******',
            email='*****@*****.**',
            user_type=UserType.HUMAN,
            about_me='Tennis 4 Life')

        results = build_list_response(
            actor=user,
            items=[
                Sound.create(
                    creator=user,
                    created_by=user,
                    info_url='https://example.com/sound1',
                    audio_url='https://example.com/sound1/file.wav',
                    low_quality_audio_url='https://example.com/sound1/file.mp3',
                    license_type=LicenseType.BY,
                    title='First sound',
                    duration_seconds=12.3,
                    tags=['test']),
                Sound.create(
                    creator=user,
                    created_by=user,
                    info_url='https://example.com/sound2',
                    audio_url='https://example.com/sound2/file.wav',
                    low_quality_audio_url='https://example.com/sound2/file.mp3',
                    license_type=LicenseType.BY,
                    title='Second sound',
                    duration_seconds=1.3,
                    tags=['test']),
                Sound.create(
                    creator=user,
                    created_by=user,
                    info_url='https://example.com/sound3',
                    audio_url='https://example.com/sound3/file.wav',
                    low_quality_audio_url='https://example.com/sound3/file.mp3',
                    license_type=LicenseType.BY,
                    title='Third sound',
                    duration_seconds=30.4,
                    tags=['test']),
            ],
            total_count=100,
            add_next_page=True,
            link_template=self.link_template(user.id),
            page_number=2,
            page_size=3)

        return JSONHandler(AppEntityLinks()) \
            .serialize(results, content_type).decode()
Example #2
0
 def on_get(self, req, resp, session):
     """
     description:
         Return some high-level stats about users, sounds and annotations
     responses:
         - status_code: 200
           example:
             python: get_model_example
           description: Successfully fetched stats
     """
     resp.media = self._get_model(
         total_sounds=session.count(Sound.all_query()),
         total_annotations=session.count(Annotation.all_query()),
         total_users=session.count(User.all_query()),
     )
     resp.status = falcon.HTTP_200
Example #3
0
def sound(
        creator,
        info_url=None,
        audio_url=None,
        license_type=None,
        title=None,
        duration_seconds=None):
    return Sound.create(
        creator=creator,
        created_by=creator,
        info_url=info_url or 'https://archive.org/details/Greatest_Speeches_of_the_20th_Century',
        audio_url=audio_url or 'https://archive.org/download/Greatest_Speeches_of_the_20th_Century/AbdicationAddress.ogg',
        license_type=license_type or LicenseType.BY,
        title='Abdication Address - King Edward VIII' if title is None else title,
        duration_seconds=duration_seconds or (6 * 60) + 42
    )
Example #4
0
    def get_model_example(self, content_type):
        dataset = User.create(
            user_name='HalIncandenza',
            password='******',
            email='*****@*****.**',
            user_type=UserType.DATASET,
            about_me='Tennis 4 Life')

        snd = Sound.create(
            creator=dataset,
            created_by=dataset,
            info_url='https://example.com/sound',
            audio_url='https://example.com/sound/file.wav',
            low_quality_audio_url='https://example.com/sound/file.mp3',
            license_type=LicenseType.BY,
            title='A sound',
            duration_seconds=12.3,
            tags=['test'])

        annotations = [
            Annotation.create(
                creator=dataset,
                created_by=dataset,
                sound=snd,
                start_seconds=1,
                duration_seconds=1,
                tags=['kick']
            ),
            Annotation.create(
                creator=dataset,
                created_by=dataset,
                sound=snd,
                start_seconds=2,
                duration_seconds=1,
                tags=['snare']
            ),
        ]
        results = build_list_response(
            actor=dataset,
            items=annotations,
            total_count=100,
            add_next_page=True,
            link_template=self.link_template(dataset.id),
            page_size=2,
            page_number=2)
        return JSONHandler(AppEntityLinks()) \
            .serialize(results, content_type).decode()
Example #5
0
    def on_get(self, req, resp, session, actor):
        """
        description:
            Get a list of sounds
        query_params:
            page_size: The number of results per page
            page_number: The page of results to view
            low_id: Only return identifiers occurring later in the series than
                this one
            created_by: Only return sounds created by the user with this id
        responses:
            - status_code: 200
              description: Successfully fetched a list of sounds
              example:
                python: get_example_list_model
            - status_code: 401
              description: Unauthorized request
            - status_code: 403
              description: User is not permitted to access this sound
        """
        created_by_key = Sound.created_by.name

        user_id = req.get_param(created_by_key)
        additional_params = {}

        if user_id:
            query = Sound.created_by == User.partial_hydrate(id=user_id)
            additional_params[created_by_key] = user_id
        else:
            query = Sound.all_query()

        tags = req.get_param_as_list('tags')
        if tags:
            additional_params['tags'] = tags
            for tag in tags:
                query = query & (Sound.tags == tag)

        list_entity(
            req,
            resp,
            session,
            actor,
            query,
            Sound,
            SoundsResource.LINK_TEMPLATE,
            additional_params=additional_params)
Example #6
0
 def on_post(self, req, resp, session, actor):
     """
     description:
         Create a new sound
     example_request_body:
         python: get_example_post_body
     responses:
         - status_code: 201
           description: Successful sound creation
         - status_code: 400
           description: Input model validation error
         - status_code: 401
           description: Unauthorized request
         - status_code: 403
           description: User is not permitted to create sounds
     """
     data = req.media
     data['created_by'] = actor
     sound = Sound.create(creator=actor, **data)
     resp.set_header('Location', f'/sounds/{sound.id}')
     resp.status = falcon.HTTP_CREATED
Example #7
0
 def get_model_example(self, content_type):
     user = User.create(
         user_name='HalIncandenza',
         password='******',
         email='*****@*****.**',
         user_type=UserType.HUMAN,
         about_me='Tennis 4 Life')
     snd = Sound.create(
         creator=user,
         created_by=user,
         info_url='https://example.com/sound',
         audio_url='https://example.com/sound/file.wav',
         low_quality_audio_url='https://example.com/sound/file.mp3',
         license_type=LicenseType.BY,
         title='A sound',
         duration_seconds=12.3,
         tags=['test'])
     view = snd.view(user)
     view = self.add_links(snd, view)
     return JSONHandler(AppEntityLinks()) \
         .serialize(view, content_type).decode()