File size: 2,681 Bytes
8d55ddb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | # Copyright 2019 Aerospike, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import traceback
from collections import defaultdict
from ..const import SheetStyle
from .column_rsheet import ColumnRSheet
from .row_rsheet import RowRSheet
from .json_rsheet import JSONRSheet
render_class = {
SheetStyle.columns: ColumnRSheet,
SheetStyle.rows: RowRSheet,
SheetStyle.json: JSONRSheet,
}
use_json = False
def set_style_json(value=True):
global use_json
use_json = value
def get_style_json():
global use_json
return use_json
def render(
sheet,
title,
data_source,
style=None,
common=None,
description=None,
selectors=None,
title_repeat=False,
disable_aggregations=False,
dynamic_diff=False,
):
"""
Arguments:
sheet -- The decleration.sheet to render.
title -- Title for this render.
data_source -- Dictionary of data_sources to project fields from.
Keyword Arguments:
style -- 'SheetStyle.columns': Output fields as columns.
'SheetStyle.rows' : Output fields as rows.
'SheetStyle.json' : Output sheet as JSON.
common -- A dict of common information passed to each entry.
description -- A description of the sheet.
selectors -- List of regular expressions to select which fields from
dynamic fields.
title_repeat -- Repeat title and row headers every n columns.
disable_aggregations -- Disable sheet aggregations.
dynamic_diff -- Only show dynamic fields that aren't uniform.
"""
tcommon = defaultdict(lambda: None)
if common is not None:
tcommon.update(common)
assert set(sheet.from_sources) - set(data_source.keys()) == set()
if use_json:
style = SheetStyle.json
elif style is None:
style = sheet.default_style
return render_class[style](
sheet,
title,
data_source,
tcommon,
description=description,
selectors=selectors,
title_repeat=title_repeat,
disable_aggregations=disable_aggregations,
dynamic_diff=dynamic_diff,
).render()
|