diff --git a/models/redner.py b/models/redner.py index 76233648539d75f68d045de6070b39605c5a7b8e_bW9kZWxzL3JlZG5lci5weQ==..4baf00f6fc43e251f5ba3a547d1fdcc35d3051db_bW9kZWxzL3JlZG5lci5weQ== 100644 --- a/models/redner.py +++ b/models/redner.py @@ -154,7 +154,7 @@ name(string): Name of your template. This is to help the user find its templates in a list. language(string): Language your template is written with. - Can be mustache or handlebar + Can be mustache, handlebar or od+mustache. body(string): Content you want to create. produces(string): Can be text/html or @@ -192,7 +192,7 @@ name="", produces="text/html", body_format="text", - locale="fr", + locale="fr_FR", version="N/A", ): """Store template in Redner @@ -202,7 +202,7 @@ This is to help the user find its templates in a list. name(string): The new template name (optional) language(string): Language your template is written with. - Can be mustache or handlebar + Can be mustache, handlebar or od+mustache body(string): Content you want to create. @@ -247,3 +247,19 @@ "v1/template/%s/%s" % (self.master.account, name), http_verb="delete", ) + + def account_template_varlist(self, name): + """Extract the list of variables present in the template. + The list is not quaranteed to be accurate depending on the + template language. + + Args: + name(string): Redner template name. + + Returns: + dict: API response. + """ + + params = {"account": self.master.account, "name": name} + + return self.master.call("v1/varlist", **params) diff --git a/models/redner_template.py b/models/redner_template.py index 76233648539d75f68d045de6070b39605c5a7b8e_bW9kZWxzL3JlZG5lcl90ZW1wbGF0ZS5weQ==..4baf00f6fc43e251f5ba3a547d1fdcc35d3051db_bW9kZWxzL3JlZG5lcl90ZW1wbGF0ZS5weQ== 100644 --- a/models/redner_template.py +++ b/models/redner_template.py @@ -93,7 +93,7 @@ selection=[ ("mustache", "mustache"), ("handlebar", "handlebar"), - ("od+mustache", "od"), + ("od+mustache", "od+mustache"), ], default="mustache", required=True, @@ -147,8 +147,6 @@ # Use template data field if the selected language is "od"; # otherwise the body field is used. if vals.get("language") == "od+mustache": - body = ( - vals.get("template_data") - ) + body = vals.get("template_data") body_format = "base64" else: @@ -153,8 +151,6 @@ body_format = "base64" else: - body = ( - vals.get("body") - ) + body = vals.get("body") body_format = "text" # We depend on the API for consistency here @@ -227,6 +223,6 @@ default = dict(default or {}, name=_("%s (copy)") % self.name) return super(RednerTemplate, self).copy(default) - @api.depends("body") + @api.depends("body", "template_data") def _compute_keywords(self): for record in self: @@ -231,6 +227,9 @@ def _compute_keywords(self): for record in self: - record.detected_keywords = get_redner_tmpl_keys(record.body) + if record.language == "od+mustache": + record.detected_keywords = record.template_varlist_fetch() + else: + record.detected_keywords = get_redner_tmpl_keys(record.body) @api.model def get_keywords(self): @@ -234,6 +233,8 @@ @api.model def get_keywords(self): - """Return mjml redner keywords""" + """Return template redner keywords""" + if self.language == "od+mustache": + return self.template_varlist_fetch() return get_redner_tmpl_keys(self.body) @@ -238,5 +239,20 @@ return get_redner_tmpl_keys(self.body) + @api.model + def template_varlist_fetch(self): + """Retrieve the list of variables present in the template.""" + try: + if not self.redner_id: + return [] + + return self.redner.templates.account_template_varlist( + self.redner_id + ) + + except Exception as e: + logger.warning("Failed to fetch account template varlist :%s" % e) + return [] + def send_to_rednerd_server(self): """Send templates to the rednerd server. Useful when you have existing templates you want to register onto a new rednerd server (or