Optional filters

This commit is contained in:
Sergey Motornyuk 2022-05-07 02:07:23 +03:00
parent 67b599ce1a
commit 885a05fea4
2 changed files with 21 additions and 9 deletions

View File

@ -57,11 +57,23 @@ def event_report(context, data_dict):
tk.check_access("sysadmin", context, data_dict) tk.check_access("sysadmin", context, data_dict)
se = init_service(utils.config_credentials()) se = init_service(utils.config_credentials())
filters = "ga:eventAction=={action};ga:eventCategory=={category}".format( filters = []
action=data_dict["action"], category=data_dict["category"] if "action" in data_dict:
) filters.append(
"ga:eventAction=={action}".format(action=data_dict["action"])
)
if "category" in data_dict:
filters.append(
"ga:eventCategory=={category}".format(
category=data_dict["category"]
)
)
if "label" in data_dict: if "label" in data_dict:
filters += ";ga:eventLabel=={label}".format(label=data_dict["label"]) filters.append(
"ga:eventLabel=={label}".format(label=data_dict["label"])
)
report = ( report = (
se.data() se.data()
@ -72,7 +84,7 @@ def event_report(context, data_dict):
metrics=",".join(data_dict["metrics"]), metrics=",".join(data_dict["metrics"]),
start_date=data_dict["start_date"].date().isoformat(), start_date=data_dict["start_date"].date().isoformat(),
end_date=data_dict["end_date"].date().isoformat(), end_date=data_dict["end_date"].date().isoformat(),
filters=filters, filters=";".join(filters) or None,
) )
.execute() .execute()
) )

View File

@ -13,14 +13,14 @@ def resource_stats_show(not_empty):
@validator_args @validator_args
def event_report( def event_report(
not_empty, isodate, ignore_missing, json_list_or_string, default not_empty, isodate, json_list_or_string, default, ignore_empty
): ):
return { return {
"start_date": [not_empty, isodate], "start_date": [not_empty, isodate],
"end_date": [not_empty, isodate], "end_date": [not_empty, isodate],
"category": [not_empty], "category": [ignore_empty],
"action": [not_empty], "action": [ignore_empty],
"label": [ignore_missing, not_empty], "label": [ignore_empty],
"dimensions": [ "dimensions": [
default("ga:eventCategory,ga:eventAction,ga:eventLabel"), default("ga:eventCategory,ga:eventAction,ga:eventLabel"),
json_list_or_string, json_list_or_string,