Merge pull request #787 from grafana/mderynck/unify-template-environments
Use common environment for templates
This commit is contained in:
commit
6109c7b33e
5 changed files with 14 additions and 8 deletions
|
|
@ -1,5 +1,9 @@
|
|||
# Change Log
|
||||
|
||||
## v1.0.51 (2022-11-05)
|
||||
|
||||
- Bug Fixes
|
||||
|
||||
## v1.0.50 (2022-11-03)
|
||||
|
||||
- Updates to documentation
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ from django.dispatch import receiver
|
|||
from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
from emoji import emojize
|
||||
from jinja2 import Template
|
||||
|
||||
from apps.alerts.grafana_alerting_sync_manager.grafana_alerting_sync import GrafanaAlertingSyncManager
|
||||
from apps.alerts.integration_options_mixin import IntegrationOptionsMixin
|
||||
|
|
@ -29,6 +28,7 @@ from apps.slack.utils import post_message_to_channel
|
|||
from common.api_helpers.utils import create_engine_url
|
||||
from common.exceptions import TeamCanNotBeChangedError, UnableToSendDemoAlert
|
||||
from common.insight_log import EntityEvent, write_resource_insight_log
|
||||
from common.jinja_templater import jinja_template_env
|
||||
from common.public_primary_keys import generate_public_primary_key, increase_public_primary_key_length
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -360,7 +360,7 @@ class AlertReceiveChannel(IntegrationOptionsMixin, MaintainableObject):
|
|||
def description(self):
|
||||
if self.integration == AlertReceiveChannel.INTEGRATION_GRAFANA_ALERTING:
|
||||
contact_points = self.contact_points.all()
|
||||
rendered_description = Template(self.config.description).render(
|
||||
rendered_description = jinja_template_env.from_string(self.config.description).render(
|
||||
is_finished_alerting_setup=self.is_finished_alerting_setup,
|
||||
grafana_alerting_entities=[
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ from django.core.validators import MinLengthValidator
|
|||
from django.db import models
|
||||
from django.db.models import F
|
||||
from django.utils import timezone
|
||||
from jinja2 import Template
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
from common.jinja_templater import jinja_template_env
|
||||
from common.public_primary_keys import generate_public_primary_key, increase_public_primary_key_length
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -103,7 +103,7 @@ class CustomButton(models.Model):
|
|||
if self.forward_whole_payload:
|
||||
post_kwargs["json"] = alert.raw_request_data
|
||||
elif self.data:
|
||||
rendered_data = Template(self.data).render(
|
||||
rendered_data = jinja_template_env.from_string(self.data).render(
|
||||
{
|
||||
"alert_payload": self._escape_alert_payload(alert.raw_request_data),
|
||||
"alert_group_id": alert.group.public_primary_key,
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ import json
|
|||
from collections import defaultdict
|
||||
|
||||
from django.core.validators import URLValidator, ValidationError
|
||||
from jinja2 import Template, TemplateError
|
||||
from jinja2 import TemplateError
|
||||
from rest_framework import serializers
|
||||
from rest_framework.validators import UniqueTogetherValidator
|
||||
|
||||
from apps.alerts.models import CustomButton
|
||||
from common.api_helpers.custom_fields import TeamPrimaryKeyRelatedField
|
||||
from common.api_helpers.utils import CurrentOrganizationDefault, CurrentTeamDefault
|
||||
from common.jinja_templater import jinja_template_env
|
||||
|
||||
|
||||
class CustomButtonSerializer(serializers.ModelSerializer):
|
||||
|
|
@ -52,7 +53,7 @@ class CustomButtonSerializer(serializers.ModelSerializer):
|
|||
return None
|
||||
|
||||
try:
|
||||
template = Template(data)
|
||||
template = jinja_template_env.from_string(data)
|
||||
except TemplateError:
|
||||
raise serializers.ValidationError("Data has incorrect template")
|
||||
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ import json
|
|||
from collections import defaultdict
|
||||
|
||||
from django.core.validators import URLValidator, ValidationError
|
||||
from jinja2 import Template, TemplateError
|
||||
from jinja2 import TemplateError
|
||||
from rest_framework import serializers
|
||||
from rest_framework.validators import UniqueTogetherValidator
|
||||
|
||||
from apps.alerts.models import CustomButton
|
||||
from common.api_helpers.custom_fields import TeamPrimaryKeyRelatedField
|
||||
from common.api_helpers.utils import CurrentOrganizationDefault
|
||||
from common.jinja_templater import jinja_template_env
|
||||
|
||||
|
||||
class ActionCreateSerializer(serializers.ModelSerializer):
|
||||
|
|
@ -56,7 +57,7 @@ class ActionCreateSerializer(serializers.ModelSerializer):
|
|||
return None
|
||||
|
||||
try:
|
||||
template = Template(data)
|
||||
template = jinja_template_env.from_string(data)
|
||||
except TemplateError:
|
||||
raise serializers.ValidationError("Data has incorrect template")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue