def render(self, context): request = context.get("request", None) if request: tag_config = TagTypeSettings().get(self.tag_type) if TagStrategy(request=request).should_include( self.tag_type, tag_config): ctx = Tag.create_context(request=request, context=context) if self.src: if self.src.endswith(".html"): return render_to_string(self.src, ctx) elif self.src.endswith(".css"): tag = BeautifulSoup("", "html.parser").new_tag("link") tag["rel"] = "stylesheet" tag["type"] = "text/css" tag["href"] = static(self.src) elif self.src.endswith(".js"): tag = BeautifulSoup("", "html.parser").new_tag("script") tag["type"] = "text/javascript" tag["src"] = static(self.src) return mark_safe(tag.decode()) output = self.nodelist.render(ctx) return output return ""
def __init__(self, request, consent=None): self._request = request self._consent = consent self._context = Tag.create_context(request) self._cookies = request.COOKIES self._config = TagTypeSettings.all() self._tags = [] self.cookies = {} self.define_strategy()
def __init__(self, request, payload=None): self._request = request self._context = Tag.create_context(request) self._payload = payload or {} self._config = TagTypeSettings.all() self._tags = [] from wagtail_tag_manager.utils import get_consent self.consent_state = get_consent(request) self.consent = {} if request: self.define_strategy()