def test_get_shuup_static_url(): assert "test.js?v=%s" % get_shuup_version() in get_shuup_static_url( "test.js") assert get_shuup_static_url("test.js") == shuup_static("test.js") assert "test.css?v=" in get_shuup_static_url("test.css", "django") assert get_shuup_static_url("test2.js", "django") == shuup_static( "test2.js", "django") assert shuup_static("test3.js") != shuup_static("test3.js", "django")
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", get_shuup_static_url("shuup-gdpr.css")) user = request.user if not is_anonymous(user) 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", get_shuup_static_url("shuup-gdpr.js"))
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", get_shuup_static_url("shuup_product_reviews/shuup_product_reviews.css", "shuup-product-reviews")) add_resource( context, "body_end", get_shuup_static_url("shuup_product_reviews/shuup_product_reviews.js", "shuup-product-reviews"))
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"))
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"))
def shuup_static(path, package=None): """ `path` is the static source path, e.g. myapp/styles.css `package` is the package name to get the version from. If not set, Shuup version is used. You can pass the name if any installed pacakge and use that version as a base. """ from shuup.core.utils.static import get_shuup_static_url return get_shuup_static_url(path, package)
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 = getattr(request, "theme", None) or 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", get_shuup_static_url("xtheme/editor-injection.css")) add_resource(context, "body_end", get_shuup_static_url("xtheme/editor-injection.js"))
def shuup_static(path): from shuup.core.utils.static import get_shuup_static_url return get_shuup_static_url(path)
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", get_shuup_static_url("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, get_shuup_static_url("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", get_shuup_static_url("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", get_shuup_static_url("shuup-regions.js")) elif view_name in [ "AddressBookEditView", "WizardView", "ShopEditView", "SupplierEditView" ]: add_resource(context, "body_end", get_shuup_static_url("shuup-regions.js")) add_init_fields_resource(context, "#id_address-country", "#id_address-region_code", "#id_address-region")