Ejemplo n.º 1
0
def test_call_with_appropriate():
    def foo():
        return 'bar'

    assert call_with_appropriate(foo, {'a': 'd', 'c': 'e'}) == 'bar'

    def bar(baz):
        return baz

    assert call_with_appropriate(bar, dict(baz=23)) == 23
Ejemplo n.º 2
0
    def test_basic(self):
        def foo():
            return "bar"

        assert call_with_appropriate(foo, {"a": "d", "c": "e"}) == "bar"

        def bar(baz):
            return baz

        assert call_with_appropriate(bar, dict(baz=23)) == 23
Ejemplo n.º 3
0
    def test_basic(self):
        def foo():
            return 'bar'

        assert call_with_appropriate(foo, {
            'a': 'd',
            'c': 'e'
        }) == 'bar'

        def bar(baz):
            return baz

        assert call_with_appropriate(bar, dict(baz=23)) == 23
Ejemplo n.º 4
0
    def compose_url(self, **kwargs):
        if self.url and callable(self.url):
            return call_with_appropriate(self.url, kwargs)

        bound_column = kwargs.get("bound_column", None)
        record = kwargs["record"]

        if self.reverse_args.get("viewname", None) is not None:
            return self.call_reverse(record=record)

        if bound_column is None and self.accessor is None:
            accessor = Accessor("")
        else:
            accessor = Accessor(self.accessor if self.accessor is not None else bound_column.name)
        context = accessor.resolve(record)
        if not hasattr(context, "get_absolute_url"):
            if hasattr(record, "get_absolute_url"):
                context = record
            else:
                raise TypeError(
                    "for linkify=True, '{}' must have a method get_absolute_url".format(
                        str(context)
                    )
                )
        return context.get_absolute_url()
Ejemplo n.º 5
0
    def footer(self, bound_column, table):
        """
        Returns the content of the footer, if specified.
        """
        footer_kwargs = {"column": self, "bound_column": bound_column, "table": table}

        if self._footer is not None:
            if callable(self._footer):
                return call_with_appropriate(self._footer, footer_kwargs)
            else:
                return self._footer

        if hasattr(self, "render_footer"):
            return call_with_appropriate(self.render_footer, footer_kwargs)

        return ""
Ejemplo n.º 6
0
    def footer(self, bound_column, table):
        footer_kwargs = {
            'column': self,
            'bound_column': bound_column,
            'table': table
        }

        if self._footer is not None:
            if callable(self._footer):
                return call_with_appropriate(self._footer, footer_kwargs)
            else:
                return self._footer

        if hasattr(self, 'render_footer'):
            return call_with_appropriate(self.render_footer, footer_kwargs)

        return ''
Ejemplo n.º 7
0
    def footer(self, bound_column, table):
        footer_kwargs = {
            'column': self,
            'bound_column': bound_column,
            'table': table
        }

        if self._footer is not None:
            if callable(self._footer):
                return call_with_appropriate(self._footer, footer_kwargs)
            else:
                return self._footer

        if hasattr(self, 'render_footer'):
            return call_with_appropriate(self.render_footer, footer_kwargs)

        return ''
Ejemplo n.º 8
0
    def footer(self, bound_column, table):
        """
        Returns the content of the footer, if specified.
        """
        footer_kwargs = {
            "column": self,
            "bound_column": bound_column,
            "table": table
        }

        if self._footer is not None:
            if callable(self._footer):
                return call_with_appropriate(self._footer, footer_kwargs)
            else:
                return self._footer

        if hasattr(self, "render_footer"):
            return call_with_appropriate(self.render_footer, footer_kwargs)

        return ""
Ejemplo n.º 9
0
    def footer(self, bound_column, table):
        '''
        Returns the content of the footer, if specified.
        '''
        footer_kwargs = {
            'column': self,
            'bound_column': bound_column,
            'table': table
        }

        if self._footer is not None:
            if callable(self._footer):
                return call_with_appropriate(self._footer, footer_kwargs)
            else:
                return self._footer

        if hasattr(self, 'render_footer'):
            return call_with_appropriate(self.render_footer, footer_kwargs)

        return ''
Ejemplo n.º 10
0
    def value(self, **kwargs):
        '''
        Returns the content for a specific cell similarly to `.render` however
        without any html content. This can be used to get the data in the
        formatted as it is presented but in a form that could be added to a csv
        file.

        The default implementation just calls the `render` function but any
        subclasses where `render` returns html content should override this
        method.

        See `LinkColumn` for an example.
        '''
        return call_with_appropriate(self.render, kwargs)
Ejemplo n.º 11
0
    def value(self, **kwargs):
        '''
        Returns the content for a specific cell similarly to `.render` however
        without any html content. This can be used to get the data in the
        formatted as it is presented but in a form that could be added to a csv
        file.

        The default implementation just calls the `render` function but any
        subclasses where `render` returns html content should override this
        method.

        See `LinkColumn` for an example.
        '''
        return call_with_appropriate(self.render, kwargs)
Ejemplo n.º 12
0
    def value(self, **kwargs):
        '''
        Returns the content for a specific cell similarly to `.render` however
        without any html content. This can be used to get the data in the
        formatted as it is presented but in a form that could be added to a csv
        file.

        The default implementation just calls the `render` function but any
        subclasses where `render` returns html content should override this
        method.

        See `LinkColumn` for an example.
        '''
        value = call_with_appropriate(self.render, kwargs)

        # convert model instances to string, otherwise exporting to xls fails.
        if isinstance(value, models.Model):
            value = str(value)

        return value
Ejemplo n.º 13
0
    def compose_url(self, **kwargs):
        if self.url and callable(self.url):
            return call_with_appropriate(self.url, kwargs)

        bound_column = kwargs["bound_column"]
        record = kwargs["record"]

        if self.reverse_args.get("viewname", None) is not None:
            return self.call_reverse(record=record)

        accessor = Accessor(
            self.accessor if self.accessor is not None else bound_column.name)
        context = accessor.resolve(record)
        if not hasattr(context, "get_absolute_url"):
            if hasattr(record, "get_absolute_url"):
                context = record
            else:
                raise TypeError(
                    "for linkify=True, '{}' must have a method get_absolute_url"
                    .format(str(context)))
        return context.get_absolute_url()
Ejemplo n.º 14
0
 def footer(self):
     return call_with_appropriate(self.column.footer, {
         'bound_column': self,
         'table': self.table
     })
Ejemplo n.º 15
0
 def footer(self):
     return call_with_appropriate(self.column.footer, {
         'bound_column': self,
         'table': self.table
     })
Ejemplo n.º 16
0
 def footer(self):
     return call_with_appropriate(self.column.footer, {
         "bound_column": self,
         "table": self._table
     })
Ejemplo n.º 17
0
 def footer(self):
     return call_with_appropriate(
         self.column.footer, {"bound_column": self, "table": self._table}
     )