How to use the tableaudocumentapi.multilookup_dict.MultiLookupDict function in tableaudocumentapi

To help you get started, we’ve selected a few tableaudocumentapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tableau / document-api-python / test / test_multidict.py View on Github external
def setUp(self):
        self.mld = MultiLookupDict({
            '[foo]': {
                'alias': 'bar',
                'caption': 'baz',
                'value': 1
            },
            '[bar]': {
                'caption': 'foo',
                'value': 2
            },
            '[baz]': {
                'value': 3
            }
github tableau / document-api-python / tableaudocumentapi / multilookup_dict.py View on Github external
def __init__(self, args=None):
        if args is None:
            args = {}
        super(MultiLookupDict, self).__init__(args)
        self._indexes = {
            'alias': weakref.WeakValueDictionary(),
            'caption': weakref.WeakValueDictionary()
        }
        self._populate_indexes()
github tableau / document-api-python / tableaudocumentapi / datasource.py View on Github external
_ColumnObjectReturnTuple = collections.namedtuple('_ColumnObjectReturnTupleType', ['id', 'object'])


def _get_metadata_xml_for_field(root_xml, field_name):
    if "'" in field_name:
        field_name = sax.escape(field_name, {"'": "'"})
    xpath = u".//metadata-record[@class='column'][local-name='{}']".format(field_name)
    return root_xml.find(xpath)


def _is_used_by_worksheet(names, field):
    return any(y for y in names if y in field.worksheets)


class FieldDictionary(MultiLookupDict):

    def used_by_sheet(self, name):
        # If we pass in a string, no need to get complicated, just check to see if name is in
        # the field's list of worksheets
        if isinstance(name, basestring):
            return [x for x in self.values() if name in x.worksheets]

        # if we pass in a list, we need to check to see if any of the names in the list are in
        # the field's list of worksheets
        return [x for x in self.values() if _is_used_by_worksheet(name, x)]


def _column_object_from_column_xml(root_xml, column_xml):
    field_object = Field.from_column_xml(column_xml)
    local_name = field_object.id
    metadata_record = _get_metadata_xml_for_field(root_xml, local_name)