Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add param to set type of template variable in Template class #96

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import attr
from attr.validators import instance_of
from grafanalib.validators import is_in
import itertools
import math
from numbers import Number
Expand Down Expand Up @@ -143,6 +144,9 @@ def to_json_data(self):
PLUGIN_ID_ELASTICSEARCH = "elasticsearch"
PLUGIN_ID_CLOUDWATCH = "cloudwatch"

# Template types
TEMPLATE_TYPES = ('custom', 'query', 'interval')


@attr.s
class Mapping(object):
Expand Down Expand Up @@ -511,6 +515,7 @@ class Template(object):
return by your data source query.
:param multi: If enabled, the variable will support the selection of
multiple options at the same time.
:param variableType: set type of template variable
"""

default = attr.ib()
Expand All @@ -528,6 +533,10 @@ class Template(object):
validator=instance_of(bool),
)
regex = attr.ib(default=None)
variableType = attr.ib(
default='query',
validator=is_in(TEMPLATE_TYPES),
)

def to_json_data(self):
return {
Expand All @@ -550,7 +559,7 @@ def to_json_data(self):
'sort': 1,
'tagValuesQuery': None,
'tagsQuery': None,
'type': 'query',
'type': self.variableType,
}


Expand Down