def get_placeholder_layouts(self, context, placeholder_name, default_layout={}): """ Get a layout objects for the given placeholder and context. :param context: Rendering context. :type context: jinja2.runtime.Context :param placeholder_name: The name of the placeholder to load. :type placeholder_name: str :param default_layout: Default layout configuration (either a dict or an actual Layout). :type default_layout: dict|Layout :return: List of layouts available for current placeholder and context. :rtype: list """ layouts = [ self.get_placeholder_layout(Layout, placeholder_name, default_layout=default_layout, context=context) ] for layout_cls in get_provided_layouts(): layout = self.get_placeholder_layout(layout_cls, placeholder_name, context=context) if layout is not None: layouts.append(layout) return layouts
def _populate_vars(self): theme = get_theme_by_identifier(self.request.GET["theme"], self.request.shop) if not theme: raise Problem(_("Unable to determine the current theme.")) view_name = self.request.GET["view"] global_type = self.request.GET.get("global_type", None) self.view_config = ViewConfig( theme=theme, shop=self.request.shop, view_name=view_name, draft=True, global_type=global_type, ) # Let's store the layout data key for save here self.layout_data_key = self.request.GET.get("layout_data_key", None) # Let's use the layout identifier passed by the view to # fetch correct layout layout_identifier = self.request.GET.get("layout_identifier", None) layout_cls = Layout for provided_layout in get_provided_layouts(): if provided_layout.identifier == layout_identifier: layout_cls = provided_layout self.placeholder_name = self.request.GET["ph"] self.default_layout = self._get_default_layout() self.layout = self.view_config.get_placeholder_layout( layout_cls=layout_cls, placeholder_name=self.placeholder_name, default_layout=self.default_layout, layout_data_key=self.layout_data_key, ) (x, y) = self.current_cell_coords = ( int(self.request.GET.get("x", -1)), int(self.request.GET.get("y", -1)), ) self.current_cell = self.layout.get_cell(x=x, y=y) self.build_form()
def _populate_vars(self): theme = get_theme_by_identifier(self.request.GET["theme"], self.request.shop) if not theme: raise Problem(_("Unable to determine current theme.")) view_name = self.request.GET["view"] global_type = self.request.GET.get("global_type", None) self.view_config = ViewConfig( theme=theme, shop=self.request.shop, view_name=view_name, draft=True, global_type=global_type, ) # Let's store the layout data key for save here self.layout_data_key = self.request.GET.get("layout_data_key", None) # Let's use the layout identifier passed by the view to # fetch correct layout layout_identifier = self.request.GET.get("layout_identifier", None) layout_cls = Layout for provided_layout in get_provided_layouts(): if provided_layout.identifier == layout_identifier: layout_cls = provided_layout self.placeholder_name = self.request.GET["ph"] self.default_layout = self._get_default_layout() self.layout = self.view_config.get_placeholder_layout( layout_cls=layout_cls, placeholder_name=self.placeholder_name, default_layout=self.default_layout, layout_data_key=self.layout_data_key ) (x, y) = self.current_cell_coords = ( int(self.request.GET.get("x", -1)), int(self.request.GET.get("y", -1)), ) self.current_cell = self.layout.get_cell(x=x, y=y) self.build_form()
def get_placeholder_layouts(self, context, placeholder_name, default_layout={}): """ Get a layout objects for the given placeholder and context. :param context: Rendering context :type context: jinja2.runtime.Context :param placeholder_name: The name of the placeholder to load. :type placeholder_name: str :param default_layout: Default layout configuration (either a dict or an actual Layout) :type default_layout: dict|Layout :return: List of layouts available for current placeholder and context :rtype: list """ layouts = [ self.get_placeholder_layout( Layout, placeholder_name, default_layout=default_layout, context=context)] for layout_cls in get_provided_layouts(): layout = self.get_placeholder_layout(layout_cls, placeholder_name, context=context) if layout is not None: layouts.append(layout) return layouts