Chromium Code Reviews| Index: gm/rebaseline_server/column.py |
| diff --git a/gm/rebaseline_server/column.py b/gm/rebaseline_server/column.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c0d3b1c152e98abab1b882454e41c7f0966d1601 |
| --- /dev/null |
| +++ b/gm/rebaseline_server/column.py |
| @@ -0,0 +1,65 @@ |
| +#!/usr/bin/python |
| + |
| +""" |
| +Copyright 2014 Google Inc. |
| + |
| +Use of this source code is governed by a BSD-style license that can be |
| +found in the LICENSE file. |
| + |
| +ColumnHeaderFactory class (see class docstring for details) |
| +""" |
| + |
| +# Keys used within dictionary representation of each column header. |
| +KEY__HEADER_TEXT = 'headerText' |
| +KEY__HEADER_URL = 'headerUrl' |
| +KEY__IS_FILTERABLE = 'isFilterable' |
| +KEY__IS_SORTABLE = 'isSortable' |
| +KEY__VALUES_AND_COUNTS = 'valuesAndCounts' |
| + |
| + |
| +class ColumnHeaderFactory(object): |
| + """ |
| + 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.
|
| + """ |
| + |
| + def __init__(self, header_text, header_url=None, |
| + is_filterable=True, is_sortable=True, |
| + include_values_and_counts=True): |
| + """ |
| + Args: |
| + 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.
|
| + header_url: string; target URL if user clicks on column header. |
| + If None, nothing to click on. |
| + is_filterable: boolean; whether client should allow filtering on this |
| + column |
| + is_sortable: boolean; whether client should allow sorting on this column |
| + include_values_and_counts: boolean; whether the set of values found |
| + within this column, and their counts, should be available for the |
| + client to display |
| + """ |
| + self._header_text = header_text |
| + self._header_url = header_url |
| + self._is_filterable = is_filterable |
| + self._is_sortable = is_sortable |
| + self._include_values_and_counts = include_values_and_counts |
| + |
| + def create_as_dict(self, values_and_counts_dict=None): |
| + """ |
|
rmistry
2014/02/12 19:23:56
Nit:
See above comment. Maybe do:
""" Creates the
epoger
2014/02/12 19:59:16
Done.
|
| + Creates the header for this column in dictionary form, as needed when |
| + constructing the JSON representation. Uses the KEY__* constants as keys. |
| + |
| + Args: |
| + values_and_counts_dict: dictionary mapping each possible column value |
| + to its count (how many entries in the column have this value), or |
| + None if this information is not available |
| + """ |
| + asdict = { |
| + KEY__HEADER_TEXT: self._header_text, |
| + KEY__IS_FILTERABLE: self._is_filterable, |
| + KEY__IS_SORTABLE: self._is_sortable, |
| + } |
| + if self._header_url: |
| + asdict[KEY__HEADER_URL] = self._header_url |
| + if self._include_values_and_counts and values_and_counts_dict: |
| + asdict[KEY__VALUES_AND_COUNTS] = values_and_counts_dict |
| + return asdict |