Exemple #1
0
    def section_entries(self, resources):
        query = self.props.section_entries
        query_results = Query.filter_collection(
            resources,
            rtype=query.rtype,
            sort_value=query.sort_value,
        )

        results = []
        for r in query_results:
            result = dict(
                label=r.title,
                subheading=r.excerpt,
                docname=r.docname,
                accent=r.props.accent,
                icon=r.props.icon,
                logo=getattr(r.props, 'logo', None),
            )
            if getattr(r.props, 'images', False):
                headshot_thumbnail = r.headshot_thumbnail('icon_96')
                if headshot_thumbnail:
                    result['headshot_thumbnail'] = headshot_thumbnail
            results.append(result)

        return results
Exemple #2
0
    def entries(self, resources, references):
        results = []
        for entry in self.props.entries:
            # Get the resource for this entry
            resource = resources[entry.docname]

            result = dict(
                docname=entry.docname,
                entries=[],
                entries_count=0,
            )
            result['label'] = entry.label if entry.label else resource.title

            # Subheading can come from several places
            if getattr(entry, 'subheading', False):
                result['subheading'] = entry.subheading
            else:
                subheading = getattr(resource.props, 'subheading', '')
                if subheading is None:
                    subheading = ''
                result['subheading'] = subheading

            # Accent and icon
            result['accent'] = entry.accent
            result['icon'] = entry.icon

            # Process the query, if any
            query = entry.query
            if query:
                query_results = Query.filter_collection(
                    resources,
                    rtype=query.rtype,
                    props=query.props,
                    parent_name=query.parent_name,
                    sort_value=query.sort_value,
                    limit=query.limit,
                    reverse=query.reverse
                )

                # Flatten the query results
                for r in query_results:
                    result['entries'].append(dict(
                        title=r.title,
                        label=r.title,
                        rtype=r.rtype,
                        excerpt=r.excerpt,
                        docname=r.docname,
                        duration=r.props.duration,
                        published=r.props.published,
                        accent='primary',
                        icon='fas fa-eye',
                        author=r.get_author(references),
                        references=r.get_references(references),
                        logo=r.get_logo(resources)
                    ))
                result['entries_count'] = len(query_results)

            results.append(result)

        return results
Exemple #3
0
 def test_filter_resources_sort(self, query_resources, field, reverse,
                                expected_title):
     results = Query.filter_collection(query_resources,
                                       sort_value=field,
                                       reverse=reverse)
     first_title = results[0].title
     assert expected_title == first_title
Exemple #4
0
 def test_filter_resources_sort_value_not_title(self, query_resources):
     results = Query.filter_collection(query_resources,
                                       sort_value='template',
                                       reverse=True)
     # Remember, we reversed based on template
     last_template = results[0].props.template
     assert 'I am c2' == last_template
Exemple #5
0
 def test_filter_resources_props(self, query_resources, dummy_prop):
     props = [
         dummy_prop,
     ]
     kw = dict(props=props)
     results = Query.filter_collection(query_resources, **kw)
     assert 1 == len(results)
     assert 'About' == results[0].title
Exemple #6
0
 def test_filter_resources(self, query_resources, filter_key, filter_value,
                           expected):
     # No filter applied
     if filter_key is None:
         kw = {}
     else:
         kw = {filter_key: filter_value}
     results = Query.filter_collection(query_resources, **kw)
     assert expected == results[0].title
Exemple #7
0
 def test_filter_resources_parent(self, query_resources):
     published = ''
     parent = Section('section2/index', 'section', published)
     parent.title = 'Parent'
     child = Article('section2/article2', 'article', published)
     child.title = 'Child'
     query_resources[parent.docname] = parent
     query_resources[child.docname] = child
     kw = dict(parent_name='section2/index')
     results = Query.filter_collection(query_resources, **kw)
     assert len(results) == 1
     assert 'Child' == results[0].title
    def make_context(self, context: Dict, sphinx_app):
        """ Put information into the context for rendering """

        query = self.props.query
        results = Query.filter_collection(sphinx_app.env.resources,
                                          rtype=query.rtype,
                                          props=query.props,
                                          parent_name=query.parent_name,
                                          sort_value=query.sort_value,
                                          limit=query.limit,
                                          reverse=query.reverse)
        context['results'] = results
        context['result_count'] = len(results)
Exemple #9
0
    def make_context(self, context, sphinx_app):
        result_sets = []
        for query_section in self.props.queries:
            result_set = dict(
                label=query_section.label,
                style=query_section.style,
            )
            query = query_section.query
            results = Query.filter_collection(sphinx_app.env.resources,
                                              rtype=query.rtype,
                                              props=query.props,
                                              parent_name=query.parent_name,
                                              sort_value=query.sort_value,
                                              limit=query.limit,
                                              reverse=query.reverse)
            result_set['results'] = results
            result_sets.append(result_set)

        context['result_sets'] = result_sets
Exemple #10
0
 def test_filter_resources_sort_value_none(self, query_resources):
     results = Query.filter_collection(query_resources, sort_value=None)
     first_title = results[0].title
     assert 'Second should sort ahead of first' == first_title
Exemple #11
0
 def test_filter_resources_limit(self, query_resources):
     # No filter applied
     results = Query.filter_collection(query_resources, limit=2)
     assert len(results) == 2
Exemple #12
0
 def test_filter_resources_empty_props(self, query_resources, dummy_prop):
     dummy_prop.value = None
     kw = dict(props=[dummy_prop])
     results = Query.filter_collection(query_resources, **kw)
     assert 6 == len(results)
     assert 'About' == results[0].title
Exemple #13
0
 def test_filter_resources_sort_title_reverse(self, query_resources):
     results = Query.filter_collection(query_resources,
                                       sort_value='title',
                                       reverse=True)
     first_title = results[0].title
     assert 'Z Last weights first' == first_title