コード例 #1
0
ファイル: rendering.py プロジェクト: vituocgia/wshop
def get_view_config(context, global_type=False):
    """
    Get a view configuration object for a Jinja2 rendering context.

    :param context: Rendering context
    :type context: jinja2.runtime.Context
    :param global_type: Boolean indicating whether this is a global type
    :type global_type: bool|False
    :return: View config
    :rtype: wshop.xtheme.view_config.ViewConfig
    """
    # This uses the Jinja context's technically-immutable vars dict
    # to cache the view configuration. This is fine in our case, I'd say.
    request = context.get("request")
    config_key = "_xtheme_global_view_config" if global_type else "_xtheme_view_config"
    config = context.vars.get(config_key)
    if (config is None):
        view_object = context.get("view")
        if view_object:
            view_class = view_object.__class__
            view_name = view_class.__name__
        else:
            view_name = "UnknownView"
        config = ViewConfig(
            theme=get_current_theme(request.shop),
            shop=request.shop,
            view_name=view_name,
            draft=is_edit_mode(request),
            global_type=global_type,
        )
        context.vars[config_key] = config
    return config
コード例 #2
0
ファイル: forms.py プロジェクト: vituocgia/wshop
    def _handle_xtheme_save(self):
        svc_pk = config.get(self.shop, CONTENT_FOOTER_KEY)
        svc = SavedViewConfig.objects.filter(pk=svc_pk).first()
        theme = get_current_theme(self.shop)

        if not svc and theme:
            context = {"shop": self.shop}
            rendered_content = template_loader.render_to_string(
                content_data.FOOTER_TEMPLATE, context).strip()
            layout = Layout(theme, "footer-bottom")
            # adds the footer template
            layout.begin_row()
            layout.begin_column({"md": 12})
            layout.add_plugin(SnippetsPlugin.identifier,
                              {"in_place": rendered_content})

            svc = SavedViewConfig(theme_identifier=theme.identifier,
                                  shop=self.shop,
                                  view_name=XTHEME_GLOBAL_VIEW_NAME,
                                  status=SavedViewConfigStatus.CURRENT_DRAFT)
            svc.set_layout_data(layout.placeholder_name, layout)
            svc.save()
            svc.publish()

            config.set(self.shop, CONTENT_FOOTER_KEY, svc.pk)
コード例 #3
0
ファイル: __init__.py プロジェクト: vituocgia/wshop
 def get_help_blocks(self, request, kind):
     theme = get_current_theme(request.shop)
     if kind == "quicklink" and theme:
         yield SimpleHelpBlock(
             text=_("Customize the look and feel of your shop"),
             actions=[{
                 "text":
                 _("Customize theme"),
                 "url":
                 reverse("wshop_admin:xtheme.config_detail",
                         kwargs={"theme_identifier": theme.identifier})
             }],
             priority=200,
             category=HelpBlockCategory.STOREFRONT,
             icon_url="xtheme/theme.png")
コード例 #4
0
ファイル: __init__.py プロジェクト: vituocgia/wshop
    def get_notifications(self, request):
        try:
            engine = engines["jinja2"]
        except KeyError:
            engine = None

        if engine and isinstance(engine,
                                 Jinja2):  # The engine is what we expect...
            if isinstance(engine.env, XthemeEnvironment
                          ):  # ... and it's capable of loading themes...
                if not get_current_theme(
                        request.shop):  # ... but there's no theme active?!
                    # Panic!
                    yield Notification(text=_(
                        "No theme is active. Click here to activate one."),
                                       title=_("Theming"),
                                       url="wshop_admin:xtheme.config")
コード例 #5
0
def extra_view_dispatch(request, view):
    """
    Dispatch to an Xtheme extra view.

    :param request: A request
    :type request: django.http.HttpRequest
    :param view: View name
    :type view: str
    :return: A response of some ilk
    :rtype: django.http.HttpResponse
    """
    theme = get_current_theme(request.shop)
    view_func = get_view_by_name(theme, view)
    if not view_func:
        msg = "%s/%s: Not found" % (getattr(theme, "identifier", None), view)
        return HttpResponseNotFound(msg)
    return view_func(request)
コード例 #6
0
ファイル: template_ns.py プロジェクト: vituocgia/wshop
    def get(self, context, name, default=None):
        """
        Get a theme setting value.

        :param context: Implicit Jinja2 context
        :type context: jinja2.runtime.Context
        :param name: Setting name
        :type name: str
        :param default: Default value if setting is not found
        :type default: object
        :return: Value
        :rtype: object
        """
        request = context["request"]
        theme = get_current_theme(request.shop)
        if theme:
            return theme.get_setting(name, default=default)
        return default