Exemplo n.º 1
0
def add_front_resources(context, content):
    view_class = getattr(context["view"], "__class__", None) if context.get("view") else None
    if not view_class:
        return
    view_name = getattr(view_class, "__name__", "")
    if view_name in ["AddressesPhase", "CheckoutMethodPhase"]:  # For front
        add_resources(
            context,
            fields=[
                ("initializeBillingRegion", "#id_billing"),
                ("initializeShippingRegion", "#id_shipping")
            ]
        )
    elif view_name == "ContactEditView":  # For admin contact edit
        add_resources(
            context,
            fields=[
                ("initializeBillingRegion", "#id_billing_address"),
                ("initializeShippingRegion", "#id_shipping_address")
            ]
        )
    elif view_name == "OrderEditView":  # For admin order editor only regions is enough
        add_resource(context, "body_end", InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
    elif view_name in ["AddressBookEditView"]:
        add_resources(context, fields=[("initializeRegion", "#id_address")])
    elif view_name in ["WizardView"]:
        add_resource(context, "body_end", InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
Exemplo n.º 2
0
def add_front_resources(context, content):
    view_class = getattr(context["view"], "__class__",
                         None) if context.get("view") else None
    if not view_class:
        return

    view_name = getattr(view_class, "__name__", "")

    # For front
    if view_name in [
            "CheckoutMethodPhase", "CompanyRegistrationView",
            "CustomerEditView", "CompanyEditView"
    ]:
        add_resource(context, "body_end", static("shuup-regions.js"))
        add_init_fields_resource(context, "#id_billing-country",
                                 "#id_billing-region_code",
                                 "#id_billing-region")
        add_init_fields_resource(context, "#id_shipping-country",
                                 "#id_shipping-region_code",
                                 "#id_shipping-region")

    elif view_name in ["AddressesPhase"]:
        # the address phase can be requested through ajax
        # when ajax request, we should append the scripts at the end of the content
        # and not at the body end, as there is no body element in the ajax response
        placement = "body_end"
        request = context.get("request")
        if request and request.is_ajax():
            placement = "content_end"

        add_resource(context, placement, static("shuup-regions.js"))
        add_init_fields_resource(context, "#id_billing-country",
                                 "#id_billing-region_code",
                                 "#id_billing-region", placement)
        add_init_fields_resource(context, "#id_shipping-country",
                                 "#id_shipping-region_code",
                                 "#id_shipping-region", placement)

    # For admin views
    elif view_name in ["ContactEditView", "OrderAddressEditView"]:
        add_resource(context, "body_end", static("shuup-regions.js"))
        add_init_fields_resource(context, "#id_billing_address-country",
                                 "#id_billing_address-region_code",
                                 "#id_billing_address-region")
        add_init_fields_resource(context, "#id_shipping_address-country",
                                 "#id_shipping_address-region_code",
                                 "#id_shipping_address-region")

    # For admin order editor only regions is enough
    elif view_name == "OrderEditView":
        add_resource(context, "body_end", static("shuup-regions.js"))

    elif view_name in [
            "AddressBookEditView", "WizardView", "ShopEditView",
            "SupplierEditView"
    ]:
        add_resource(context, "body_end", static("shuup-regions.js"))
        add_init_fields_resource(context, "#id_address-country",
                                 "#id_address-region_code",
                                 "#id_address-region")
Exemplo n.º 3
0
def add_resources(context, content):
    view_class = getattr(context["view"], "__class__", None) if context.get("view") else None
    if not view_class:
        return
    view_name = getattr(view_class, "__name__", "")
    if view_name == "ProductDetailView":
        add_resource(context, "body_end", get_shuup_static_url("shuup/recently_viewed_products/lib.js"))
Exemplo n.º 4
0
def add_front_resources(context, content):
    view_class = getattr(context["view"], "__class__", None) if context.get("view") else None
    if not view_class:
        return
    view_name = getattr(view_class, "__name__", "")
    if view_name in ["AddressesPhase", "CheckoutMethodPhase", "CompanyRegistrationView"]:  # For front
        add_resources(
            context,
            fields=[
                ("initializeBillingRegion", "#id_billing"),
                ("initializeShippingRegion", "#id_shipping")
            ]
        )
    elif view_name in ["ContactEditView", "OrderAddressEditView"]:  # For admin views
        add_resources(
            context,
            fields=[
                ("initializeBillingRegion", "#id_billing_address"),
                ("initializeShippingRegion", "#id_shipping_address")
            ]
        )
    elif view_name == "OrderEditView":  # For admin order editor only regions is enough
        add_resource(context, "body_end", InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
    elif view_name in ["AddressBookEditView"]:
        add_resources(context, fields=[("initializeRegion", "#id_address")])
    elif view_name in ["WizardView"]:
        add_resource(context, "body_end", InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
Exemplo n.º 5
0
def test_injecting_into_weird_places():
    request = get_request()
    (template, layout, gibberish, ctx) = get_test_template_bits(request, **{
        RESOURCE_CONTAINER_VAR_NAME: ResourceContainer()
    })
    with pytest.raises(ValueError):
        add_resource(ctx, "yes", "hello.js")
Exemplo n.º 6
0
def add_edit_resources(context):
    """
    Possibly inject Xtheme editor injection resources into the given
    context's resources.

    :param context: Jinja rendering context
    :type context: jinja2.runtime.Context
    """
    request = context.get("request")
    if not (request and could_edit(request) and may_inject(context)):
        return
    from ._theme import get_current_theme
    from .rendering import get_view_config  # avoid circular import
    view_config = get_view_config(context)
    theme = get_current_theme(request=request)
    if not theme:
        return
    add_resource(context, "body_end", InlineScriptResource.from_vars("XthemeEditorConfig", {
        "commandUrl": "/xtheme/",  # TODO: Use reverse("shuup:xtheme")?
        "editUrl": "/xtheme/editor/",  # TODO: Use reverse("shuup:xtheme")?
        "themeIdentifier": theme.identifier,
        "viewName": view_config.view_name,
        "edit": is_edit_mode(request),
        "csrfToken": get_token(request),
    }))
    add_resource(context, "body_end", staticfiles_storage.url("xtheme/editor-injection.js"))
Exemplo n.º 7
0
def add_edit_resources(context):
    """
    Possibly inject Xtheme editor injection resources into the given
    context's resources.

    :param context: Jinja rendering context
    :type context: jinja2.runtime.Context
    """
    request = context.get("request")
    if not (request and could_edit(request) and may_inject(context)):
        return
    from ._theme import get_current_theme
    from .rendering import get_view_config  # avoid circular import
    view_config = get_view_config(context)
    theme = get_current_theme(request.shop)
    if not theme:
        return
    add_resource(context, "body_end", InlineScriptResource.from_vars("XthemeEditorConfig", {
        "commandUrl": "/xtheme/",  # TODO: Use reverse("shuup:xtheme")?
        "editUrl": "/xtheme/editor/",  # TODO: Use reverse("shuup:xtheme")?
        "themeIdentifier": theme.identifier,
        "viewName": view_config.view_name,
        "edit": is_edit_mode(request),
        "csrfToken": get_token(request),
    }))
    add_resource(context, "body_end", staticfiles_storage.url("xtheme/editor-injection.js"))
Exemplo n.º 8
0
def test_injecting_into_weird_places():
    request = get_request()
    (template, layout, gibberish, ctx) = get_test_template_bits(request, **{
        RESOURCE_CONTAINER_VAR_NAME: ResourceContainer()
    })
    with pytest.raises(ValueError):
        add_resource(ctx, "yes", "hello.js")
Exemplo n.º 9
0
def add_resources(context, content):
    view_class = getattr(context["view"], "__class__", None) if context.get("view") else None
    if not view_class:
        return
    view_name = getattr(view_class, "__name__", "")
    if view_name == "ProductDetailView":
        add_resource(context, "body_end", "%sshuup/recently_viewed_products/lib.js" % settings.STATIC_URL)
Exemplo n.º 10
0
def add_init_fields_resource(context, country_code_field, region_code_field, region_field=None, placement="body_end"):
    add_resource(context, placement, InlineScriptResource(
        INITIALIZE_FIELDS_FUNCTION % {
            "country_code_field": country_code_field,
            "region_code_field": region_code_field,
            "region_field": region_field if region_field else ""
        })
    )
Exemplo n.º 11
0
    def render(self, context):
        """
        Custom render for to add js resource for banner box

        :param context: current context
        :return: html content for the plugin
        """
        add_resource(context, "body_end", "%sshuup_carousel/js/script.js" % settings.STATIC_URL)
        return super(BannerBoxPlugin, self).render(context)
Exemplo n.º 12
0
    def render(self, context):
        for location, __ in self.fields:
            if location in resources.KNOWN_LOCATIONS:
                resource = self.config.get(location, "")
                add_resource(context, location, JinjaMarkupResource(resource, context))

        in_place = self.config.get("in_place", "")
        if in_place:
            return JinjaMarkupResource(in_place, context).render()
Exemplo n.º 13
0
 def render(self, context):
     """
     Custom render for to add css resource for carousel
     :param context: current context
     :return: html content for the plugin
     """
     add_resource(context, "head_end", "%sshuup_mailchimp/css/style.css" % settings.STATIC_URL)
     add_resource(context, "body_end", "%sshuup_mailchimp/js/script.js" % settings.STATIC_URL)
     return super(NewsletterPlugin, self).render(context)
Exemplo n.º 14
0
def add_resources(context, content):
    request = context.get("request")
    if request:
        match = request.resolver_match
        if match and match.app_name == "shuup_admin":
            return

    add_resource(context, "head_end", static("shuup_product_reviews/shuup_product_reviews.css"))
    add_resource(context, "body_end", static("shuup_product_reviews/shuup_product_reviews.js"))
Exemplo n.º 15
0
    def render(self, context):
        """
        Custom render for to add css resource for carousel

        :param context: current context
        :return: html content for the plugin
        """
        add_resource(context, "head_end", "%sshuup_carousel/css/style.css" % settings.STATIC_URL)
        add_resource(context, "body_end", "%sshuup_carousel/js/vendor/owl.carousel.min.js" % settings.STATIC_URL)
        return super(CarouselPlugin, self).render(context)
Exemplo n.º 16
0
    def render(self, context):
        """
        Custom render for to add js resource for banner box

        :param context: current context
        :return: html content for the plugin
        """
        add_resource(context, "body_end",
                     "%sshuup_carousel/js/script.js" % settings.STATIC_URL)
        return super(BannerBoxPlugin, self).render(context)
Exemplo n.º 17
0
def add_resources(context, content):
    request = context.get("request")
    if request:
        match = request.resolver_match
        if match and match.app_name == "shuup_admin":
            return

    add_resource(
        context, "head_end",
        "%sshuup_wishlist/css/style.css?v=0.3.7.css" % settings.STATIC_URL)
    add_resource(
        context, "body_end",
        "%sshuup_wishlist/js/scripts.js?v=0.3.7.js" % settings.STATIC_URL)
Exemplo n.º 18
0
def add_resources(context, content):
    request = context.get("request")
    if request:
        match = request.resolver_match
        # not a view match or the app is Shuup Admin
        if not match or match.app_name == "shuup_admin":
            return

    if not context.get("view"):
        return

    add_resource(context, "head_end", "%sshuup_wishlist/css/style.css?v=0.4.8.css" % settings.STATIC_URL)
    add_resource(context, "body_end", "%sshuup_wishlist/js/scripts.js?v=0.4.8.js" % settings.STATIC_URL)
Exemplo n.º 19
0
    def render(self, context):
        """
        Custom render for to add css resource for carousel

        :param context: current context
        :return: html content for the plugin
        """
        add_resource(context, "head_end",
                     "%sshuup_carousel/css/style.css" % settings.STATIC_URL)
        add_resource(
            context, "body_end",
            "%sshuup_carousel/js/vendor/owl.carousel.min.js" %
            settings.STATIC_URL)
        return super(CarouselPlugin, self).render(context)
Exemplo n.º 20
0
def add_resources(context, content):
    request = context.get("request")
    if not request:
        return

    match = request.resolver_match
    if match and match.app_name == "shuup_admin":
        settings_provider = cached_load(
            "SHUUP_ADMIN_CHANNEL_SETTINGS_PROVIDER")
        add_resource(
            context, "body_end",
            InlineScriptResource.from_vars(
                "ShuupAdminChannelConfig",
                settings_provider.get_configs(request, context)))
        add_resource(context, "body_end", static("shuup-admin-channel.js"))
Exemplo n.º 21
0
def test_without_rc():
    request = get_request()
    (template, layout, gibberish, ctx) = get_test_template_bits(request)
    assert not add_resource(ctx, "yes", "hello.js")
    content1 = "<html>"
    content2 = inject_resources(ctx, content1)
    assert content1 == content2
Exemplo n.º 22
0
def add_resources(context, content):
    if has_installed("shuup_product_reviews"):
        return

    request = context.get("request")
    if request:
        match = request.resolver_match
        if match and match.app_name == "shuup_admin":
            return

    add_resource(
        context, "head_end", "%s?v=0.4.0.css" %
        static("shuup_vendor_reviews/shuup_vendor_reviews.css"))
    add_resource(
        context, "body_end", "%s?v=0.4.0.js" %
        static("shuup_vendor_reviews/shuup_vendor_reviews.js"))
Exemplo n.º 23
0
def test_without_rc():
    request = get_request()
    (template, layout, gibberish, ctx) = get_test_template_bits(request)
    assert not add_resource(ctx, "yes", "hello.js")
    content1 = "<html>"
    content2 = inject_resources(ctx, content1)
    assert content1 == content2
Exemplo n.º 24
0
def add_resources(context, content):
    request = context.get("request")
    if request:
        match = request.resolver_match
        # not a view match or the app is Shuup Admin
        if not match or match.app_name == "shuup_admin":
            return

    if not context.get("view"):
        return

    add_resource(
        context, "head_end",
        get_shuup_static_url("shuup_wishlist/css/style.css", "shuup-wishlist"))
    add_resource(
        context, "body_end",
        get_shuup_static_url("shuup_wishlist/js/scripts.js", "shuup-wishlist"))
Exemplo n.º 25
0
def add_resources(context, content):
    request = context.get("request")
    if request:
        match = request.resolver_match
        # not a view match or the app is Shuup Admin
        if not match or match.app_name == "shuup_admin":
            return

    if not context.get("view"):
        return

    add_resource(
        context, "head_end",
        "%sshuup_wishlist/css/style.css?v=0.4.10.css" % settings.STATIC_URL)
    add_resource(
        context, "body_end",
        "%sshuup_wishlist/js/scripts.js?v=0.4.10.js" % settings.STATIC_URL)
Exemplo n.º 26
0
def add_gdpr_consent_resources(context, content):
    if not valid_view(context):
        return

    request = context["request"]
    shop = get_shop(request)
    gdpr_settings = GDPRSettings.get_for_shop(shop)

    # GDPR not enabled, nothing to do
    if not gdpr_settings.enabled:
        return

    # always add styles
    add_resource(context, "head_end",
                 static("shuup_gdpr/shuup_gdpr_styles.css"))

    user = request.user
    if not user.is_anonymous() and should_reconsent_privacy_policy(shop, user):
        consent_page = get_privacy_policy_page(shop)
        render_context = {
            "request":
            request,
            "csrf_token":
            context["csrf_token"],
            "url":
            "/%s" % consent_page.url,
            "accept_url":
            reverse("shuup:gdpr_policy_consent",
                    kwargs=dict(page_id=consent_page.id))
        }
        update_resource = InlineMarkupResource(
            loader.render_to_string("shuup/gdpr/privacy_policy_update.jinja",
                                    context=render_context))
        add_resource(context, "body_end", update_resource)

    # consent already added
    if settings.SHUUP_GDPR_CONSENT_COOKIE_NAME in request.COOKIES:
        return

    gdpr_documents = []
    if has_installed("shuup.simple_cms"):
        gdpr_documents = get_active_consent_pages(shop)

    render_context = {
        "request": request,
        "csrf_token": context["csrf_token"],
        "gdpr_settings": gdpr_settings,
        "gdpr_documents": gdpr_documents,
        "gdpr_cookie_categories": GDPRCookieCategory.objects.filter(shop=shop)
    }
    html_resource = InlineMarkupResource(
        loader.render_to_string("shuup/gdpr/gdpr_consent.jinja",
                                context=render_context))
    add_resource(context, "body_end", html_resource)
    add_resource(context, "body_end", static("shuup_gdpr/shuup_gdpr.js"))
Exemplo n.º 27
0
def add_front_resources(context, content):
    view_class = getattr(context["view"], "__class__",
                         None) if context.get("view") else None
    if not view_class:
        return

    if getattr(view_class, "__name__", "") == "AddressesPhase":  # For front
        add_resource(
            context, "body_end",
            InlineScriptResource(
                REGION_CHANGER_JS % {
                    "billing_field_prefix": "#id_billing",
                    "shipping_field_prefix": "#id_shipping",
                    "regions": json.dumps(regions_data)
                }))
    if getattr(view_class, "__name__",
               "") == "ContactEditView":  # For admin contact edit
        add_resource(
            context, "body_end",
            InlineScriptResource(
                REGION_CHANGER_JS % {
                    "billing_field_prefix": "#id_billing_address",
                    "shipping_field_prefix": "#id_shipping_address",
                    "regions": json.dumps(regions_data)
                }))
    if getattr(
            view_class, "__name__", ""
    ) == "OrderEditView":  # For admin order editor only regions is enough
        add_resource(
            context, "body_end",
            InlineScriptResource(REGIONS %
                                 {"regions": json.dumps(regions_data)}))
Exemplo n.º 28
0
def add_edit_resources(context):
    """
    Possibly inject Xtheme editor injection resources into the given
    context's resources.

    :param context: Jinja rendering context
    :type context: jinja2.runtime.Context
    """
    request = context.get("request")
    if not can_edit(context):
        return

    try:
        command_url = reverse("shuup:xtheme")
        edit_url = reverse("shuup:xtheme_editor")
        inject_snipper = reverse("shuup_admin:xtheme_snippet.list")
    except NoReverseMatch:  # No URLs no resources
        return

    from .rendering import get_view_config  # avoid circular import
    view_config = get_view_config(context)
    theme = get_current_theme(request.shop)
    add_resource(context, "body_end", InlineScriptResource.from_vars("XthemeEditorConfig", {
        "commandUrl": command_url,
        "editUrl": edit_url,
        "injectSnipperUrl": inject_snipper,
        "themeIdentifier": theme.identifier,
        "viewName": view_config.view_name,
        "edit": is_edit_mode(request),
        "csrfToken": get_token(request),
    }))
    add_resource(context, "head_end", staticfiles_storage.url("xtheme/editor-injection.css"))
    add_resource(context, "body_end", staticfiles_storage.url("xtheme/editor-injection.js"))
Exemplo n.º 29
0
def add_edit_resources(context):
    """
    Possibly inject Xtheme editor injection resources into the given
    context's resources.

    :param context: Jinja rendering context
    :type context: jinja2.runtime.Context
    """
    request = context.get("request")
    if not can_edit(context):
        return

    try:
        command_url = reverse("shuup:xtheme")
        edit_url = reverse("shuup:xtheme_editor")
        inject_snipper = reverse("shuup_admin:xtheme_snippet.list")
    except NoReverseMatch:  # No URLs no resources
        return

    from .rendering import get_view_config  # avoid circular import
    view_config = get_view_config(context)
    theme = get_current_theme(request.shop)
    add_resource(context, "body_end", InlineScriptResource.from_vars("XthemeEditorConfig", {
        "commandUrl": command_url,
        "editUrl": edit_url,
        "injectSnipperUrl": inject_snipper,
        "themeIdentifier": theme.identifier,
        "viewName": view_config.view_name,
        "edit": is_edit_mode(request),
        "csrfToken": get_token(request),
    }))
    add_resource(context, "head_end", staticfiles_storage.url("xtheme/editor-injection.css"))
    add_resource(context, "body_end", staticfiles_storage.url("xtheme/editor-injection.js"))
Exemplo n.º 30
0
def add_gdpr_consent_resources(context, content):
    if not valid_view(context):
        return

    request = context["request"]
    shop = get_shop(request)
    gdpr_settings = GDPRSettings.get_for_shop(shop)

    # GDPR not enabled, nothing to do
    if not gdpr_settings.enabled:
        return

    # always add styles
    add_resource(context, "head_end", static("shuup-gdpr.css"))

    user = request.user
    if not user.is_anonymous() and should_reconsent_privacy_policy(shop, user):
        consent_page = get_privacy_policy_page(shop)
        render_context = {
            "request": request,
            "csrf_token": context["csrf_token"],
            "url": "/%s" % consent_page.url,
            "accept_url": reverse("shuup:gdpr_policy_consent", kwargs=dict(page_id=consent_page.id))
        }
        update_resource = InlineMarkupResource(
            loader.render_to_string("shuup/gdpr/privacy_policy_update.jinja", context=render_context)
        )
        add_resource(context, "body_end", update_resource)

    # consent already added
    if settings.SHUUP_GDPR_CONSENT_COOKIE_NAME in request.COOKIES:
        return

    gdpr_documents = []
    if has_installed("shuup.simple_cms"):
        gdpr_documents = get_active_consent_pages(shop)

    render_context = {
        "request": request,
        "csrf_token": context["csrf_token"],
        "gdpr_settings": gdpr_settings,
        "gdpr_documents": gdpr_documents,
        "gdpr_cookie_categories": GDPRCookieCategory.objects.filter(shop=shop)
    }
    html_resource = InlineMarkupResource(
        loader.render_to_string("shuup/gdpr/gdpr_consent.jinja", context=render_context)
    )
    add_resource(context, "body_end", html_resource)
    add_resource(context, "body_end", static("shuup-gdpr.js"))
Exemplo n.º 31
0
def add_front_resources(context, content):
    view_class = getattr(context["view"], "__class__",
                         None) if context.get("view") else None
    if not view_class:
        return
    view_name = getattr(view_class, "__name__", "")
    if view_name in ["AddressesPhase", "SingleCheckoutPhase"]:  # For front
        add_resources(context, fields=["#id_billing", "#id_shipping"])
    elif view_name == "ContactEditView":  # For admin contact edit
        add_resources(context,
                      fields=["#id_billing_address", "#id_shipping_address"])
    elif view_name == "OrderEditView":  # For admin order editor only regions is enough
        add_resource(
            context, "body_end",
            InlineScriptResource(REGIONS %
                                 {"regions": json.dumps(regions_data)}))
    elif view_name in ["AddressBookEditView"]:
        add_resources(context, fields=["#id_address"])
    elif view_name in ["WizardView"]:
        add_resource(
            context, "body_end",
            InlineScriptResource(REGIONS %
                                 {"regions": json.dumps(regions_data)}))
Exemplo n.º 32
0
def add_resources(context, placement="body_end", fields=None):
    add_resource(context, placement, InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
    add_resource(context, placement, InlineScriptResource(REGION_CHANGER_JS))
    for function_name, field in fields or []:
        add_resource(
            context,
            placement,
            InlineScriptResource(
                CHANGER_FUNCTIONS % {"initialize_function": function_name, "region_field_prefix": field})
        )
Exemplo n.º 33
0
def add_resources(context, placement="body_end", fields=[""]):
    add_resource(
        context, placement,
        InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
    add_resource(context, placement, InlineScriptResource(REGION_CHANGER_JS))
    for field in fields:
        add_resource(
            context, placement,
            InlineScriptResource(CHANGER_FUNCTIONS %
                                 {"region_field_prefix": field}))
Exemplo n.º 34
0
def add_resources(context, placement="body_end", fields=None):
    add_resource(context, placement, InlineScriptResource(REGIONS % {"regions": json.dumps(regions_data)}))
    add_resource(context, placement, InlineScriptResource(REGION_CHANGER_JS))
    for function_name, field in fields or []:
        add_resource(
            context,
            placement,
            InlineScriptResource(
                CHANGER_FUNCTIONS % {"initialize_function": function_name, "region_field_prefix": field})
        )
Exemplo n.º 35
0
def add_gdpr_consent_resources(context, content):
    # TODO: should we ignore admin urls?
    view_class = getattr(context["view"], "__class__",
                         None) if context.get("view") else None
    if not view_class or not context.get("request"):
        return

    shop = get_shop(context["request"])
    gdpr_settings = GDPRSettings.get_for_shop(shop)

    # GDPR not enabled
    if not gdpr_settings.enabled:
        return

    # consent already added
    # TODO: Should we check for changes and ask the consent again here?
    if settings.SHUUP_GDPR_CONSENT_COOKIE_NAME in context["request"].COOKIES:
        return

    gdpr_documents = []
    if has_installed("shuup.simple_cms"):
        from shuup.simple_cms.models import Page, PageType
        gdpr_documents = Page.objects.visible(shop).filter(
            page_type=PageType.GDPR_CONSENT_DOCUMENT)

    render_context = {
        "request": context["request"],
        "csrf_token": context["csrf_token"],
        "gdpr_settings": gdpr_settings,
        "gdpr_documents": gdpr_documents,
        "gdpr_cookie_categories": GDPRCookieCategory.objects.filter(shop=shop)
    }
    html_resource = InlineMarkupResource(
        loader.render_to_string("shuup/gdpr/gdpr_consent.jinja",
                                context=render_context))
    add_resource(context, "body_end", html_resource)
    add_resource(context, "body_end", static("shuup_gdpr/shuup_gdpr.js"))
    add_resource(context, "head_end",
                 static("shuup_gdpr/shuup_gdpr_styles.css"))
Exemplo n.º 36
0
 def render(self, context):
     add_resource(context, "head_end", static("shuup-cms-blog.css"))
     return super(ShuupCMSBlogArticleListPlugin, self).render(context)
Exemplo n.º 37
0
 def render(self, context):
     for location, __ in self.fields:
         if location in resources.KNOWN_LOCATIONS:
             resource = self.config.get(location, "")
             add_resource(context, location, InlineMarkupResource(resource))
     return self.config.get("in_place", "")
Exemplo n.º 38
0
def add_test_injection(context, content):
    add_resource(context, "body_end",
                 InlineScriptResource("window.injectedFromAddon=true;"))
Exemplo n.º 39
0
def add_test_injection(context, content):
    add_resource(context, "body_end", InlineScriptResource("window.injectedFromAddon=true;"))
Exemplo n.º 40
0
 def render(self, context):
     add_resource(context, "body_start", "://example.com/js.js")
     add_resource(context, "body_start", "://foo/fuzz.png")
     add_resource(context, "head_end", "://example.com/css.css")
     add_resource(context, "body_end", InlineScriptResource("alert('xss')"))
     add_resource(
         context, "head_end",
         InlineScriptResource.from_vars("foos", {"bars": (1, 2, 3)}))
     add_resource(context, "head_end",
                  InlineMarkupResource(self.meta_markup))
     add_resource(context, "head_end",
                  InlineMarkupResource(self.meta_markup))  # Test duplicates
     add_resource(context, "head_end", "")  # Test the no-op branch
     return self.message
Exemplo n.º 41
0
 def render(self, context):
     add_resource(context, "body_start", "://example.com/js.js")
     add_resource(context, "body_start", "://foo/fuzz.png")
     add_resource(context, "head_end", "://example.com/css.css")
     add_resource(context, "body_end", InlineScriptResource("alert('xss')"))
     add_resource(context, "head_end", InlineScriptResource.from_vars("foos", {"bars": (1, 2, 3)}))
     add_resource(context, "head_end", InlineMarkupResource(self.meta_markup))
     add_resource(context, "head_end", InlineMarkupResource(self.meta_markup))  # Test duplicates
     add_resource(context, "head_end", "")  # Test the no-op branch
     return self.message
Exemplo n.º 42
0
 def render(self, context):
     for location, __ in self.fields:
         if location in resources.KNOWN_LOCATIONS:
             resource = self.config.get(location, "")
             add_resource(context, location, InlineMarkupResource(resource))
     return self.config.get("in_place", "")