OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 | |
3 """ | |
4 Copyright 2014 Google Inc. | |
5 | |
6 Use of this source code is governed by a BSD-style license that can be | |
7 found in the LICENSE file. | |
8 | |
9 ColumnHeaderFactory class (see class docstring for details) | |
10 """ | |
11 | |
12 # Keys used within dictionary representation of each column header. | |
13 KEY__HEADER_TEXT = 'headerText' | |
14 KEY__HEADER_URL = 'headerUrl' | |
15 KEY__IS_FILTERABLE = 'isFilterable' | |
16 KEY__IS_SORTABLE = 'isSortable' | |
17 KEY__VALUES_AND_COUNTS = 'valuesAndCounts' | |
18 | |
19 | |
20 class ColumnHeaderFactory(object): | |
21 """ | |
22 Assembles the header for a single column of data. | |
rmistry
2014/02/12 19:23:56
Nit:
From the python style guide: http://google-s
epoger
2014/02/12 19:59:16
Done throughout.
| |
23 """ | |
24 | |
25 def __init__(self, header_text, header_url=None, | |
26 is_filterable=True, is_sortable=True, | |
27 include_values_and_counts=True): | |
28 """ | |
29 Args: | |
30 header_text: string; text the client should display within column header | |
rmistry
2014/02/12 19:23:56
Nit:
Missing ending period. Some lines in this arg
epoger
2014/02/12 19:59:16
Done.
| |
31 header_url: string; target URL if user clicks on column header. | |
32 If None, nothing to click on. | |
33 is_filterable: boolean; whether client should allow filtering on this | |
34 column | |
35 is_sortable: boolean; whether client should allow sorting on this column | |
36 include_values_and_counts: boolean; whether the set of values found | |
37 within this column, and their counts, should be available for the | |
38 client to display | |
39 """ | |
40 self._header_text = header_text | |
41 self._header_url = header_url | |
42 self._is_filterable = is_filterable | |
43 self._is_sortable = is_sortable | |
44 self._include_values_and_counts = include_values_and_counts | |
45 | |
46 def create_as_dict(self, values_and_counts_dict=None): | |
47 """ | |
rmistry
2014/02/12 19:23:56
Nit:
See above comment. Maybe do:
""" Creates the
epoger
2014/02/12 19:59:16
Done.
| |
48 Creates the header for this column in dictionary form, as needed when | |
49 constructing the JSON representation. Uses the KEY__* constants as keys. | |
50 | |
51 Args: | |
52 values_and_counts_dict: dictionary mapping each possible column value | |
53 to its count (how many entries in the column have this value), or | |
54 None if this information is not available | |
55 """ | |
56 asdict = { | |
57 KEY__HEADER_TEXT: self._header_text, | |
58 KEY__IS_FILTERABLE: self._is_filterable, | |
59 KEY__IS_SORTABLE: self._is_sortable, | |
60 } | |
61 if self._header_url: | |
62 asdict[KEY__HEADER_URL] = self._header_url | |
63 if self._include_values_and_counts and values_and_counts_dict: | |
64 asdict[KEY__VALUES_AND_COUNTS] = values_and_counts_dict | |
65 return asdict | |
OLD | NEW |