| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8b8f351 commit 202acea
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | if field.default_aggregation: | |
| 24 | 24 | print(' the default aggregation is {}'.format(field.default_aggregation)) | |
| 25 | 25 | blank_line = True | |
| 26 | + if field.description: | ||
| 27 | + print(' the description is {}'.format(field.description)) | ||
| 26 | 28 | ||
| 27 | 29 | if blank_line: | |
| 28 | 30 | print('') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,6 @@ | |||
| 1 | 1 | import functools | |
| 2 | + import xml.etree.ElementTree as ET | ||
| 3 | + | ||
| 2 | 4 | ||
| 3 | 5 | _ATTRIBUTES = [ | |
| 4 | 6 | 'id', # Name of the field as specified in the file, usually surrounded by [ ] | |
@@ -8,6 +10,7 @@ | |||
| 8 | 10 | 'type', # three possible values: quantitative, ordinal, or nominal | |
| 9 | 11 | 'alias', # Name of the field as displayed in Tableau if the default name isn't wanted | |
| 10 | 12 | 'calculation', # If this field is a calculated field, this will be the formula | |
| 13 | + 'description', # If this field has a description, this will be the description (including formatting tags) | ||
| 11 | 14 | ] | |
| 12 | 15 | ||
| 13 | 16 | _METADATA_ATTRIBUTES = [ | |
@@ -164,6 +167,11 @@ def default_aggregation(self): | |||
| 164 | 167 | """ The default type of aggregation on the field (e.g Sum, Avg)""" | |
| 165 | 168 | return self._aggregation | |
| 166 | 169 | ||
| 170 | + @property | ||
| 171 | + def description(self): | ||
| 172 | + """ The contents of the <desc> tag on a field """ | ||
| 173 | + return self._description | ||
| 174 | + | ||
| 167 | 175 | @property | |
| 168 | 176 | def worksheets(self): | |
| 169 | 177 | return list(self._worksheets) | |
@@ -184,3 +192,11 @@ def _read_calculation(xmldata): | |||
| 184 | 192 | return None | |
| 185 | 193 | ||
| 186 | 194 | return calc.attrib.get('formula', None) | |
| 195 | + | ||
| 196 | + @staticmethod | ||
| 197 | + def _read_description(xmldata): | ||
| 198 | + description = xmldata.find('.//desc') | ||
| 199 | + if description is None: | ||
| 200 | + return None | ||
| 201 | + | ||
| 202 | + return u'{}'.format(ET.tostring(description, encoding='utf-8')) # This is necessary for py3 support | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,14 @@ | |||
| 75 | 75 | <column datatype='integer' name='[Number of Records]' role='measure' type='quantitative' user:auto-column='numrec'> | |
| 76 | 76 | <calculation class='tableau' formula='1' /> | |
| 77 | 77 | </column> | |
| 78 | - <column caption='A' datatype='string' name='[a]' role='dimension' type='nominal' /> | ||
| 78 | + <column caption='A' datatype='string' name='[a]' role='dimension' type='nominal'> | ||
| 79 | + <desc> | ||
| 80 | + <formatted-text> | ||
| 81 | + <run bold='true' fontsize='96'>A thing</run> | ||
| 82 | + <run fontcolor='#686868'> Something will go here too, in a muted gray</run> | ||
| 83 | + </formatted-text> | ||
| 84 | + </desc> | ||
| 85 | + </column> | ||
| 79 | 86 | <column caption='Today's Date' datatype='string' name='[Today's Date]' role='dimension' type='nominal' /> | |
| 80 | 87 | <column caption='X' datatype='integer' name='[x]' role='measure' type='ordinal' /> | |
| 81 | 88 | <column caption='Y' datatype='integer' name='[y]' role='measure' type='quantitative' /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,11 @@ def test_datasource_field_datatype(self): | |||
| 58 | 58 | def test_datasource_field_role(self): | |
| 59 | 59 | self.assertEqual(self.ds.fields['[x]'].role, 'measure') | |
| 60 | 60 | ||
| 61 | + def test_datasource_field_description(self): | ||
| 62 | + actual = self.ds.fields['[a]'].description | ||
| 63 | + self.assertIsNotNone(actual) | ||
| 64 | + self.assertTrue(u'muted gray' in actual) | ||
| 65 | + | ||
| 61 | 66 | ||
| 62 | 67 | class DataSourceFieldsTWB(unittest.TestCase): | |
| 63 | 68 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments