Пример #1
0
    def build_namespace(self, context):
        namespace = BaseSkin.build_namespace(self, context)
        namespace['column'] = None
        if context.user is None:
            namespace['location'].tabs = None

        # Right Column
        resource = context.resource
        if resource is not resource.get_site_root():
            return namespace

        if context.view is not resource.get_view(None):
            return namespace

        try:
            column = resource.get_resource('columnright')
        except LookupError:
            return namespace

        namespace['column'] = column.get_handler().events
        return namespace
Пример #2
0
Файл: skins.py Проект: TZM/zmgc
 def build_namespace(self, context):
     namespace = merge_dicts(BaseSkin.build_namespace(self, context), {
     'upper_footer': self.upper_footer(context=context),
     })
     #print namespace
     return namespace
Пример #3
0
    def build_namespace(self, context):
        namespace = BaseSkin.build_namespace(self, context)

        here = context.resource
        here_ac = here.get_access_control()
        site_root = context.site_root
        theme = site_root.get_resource('theme')
        # banner namespace
        banner_ns = {}
        banner_ns['title'] = theme.get_property('banner_title')
        banner_ns['description'] = site_root.get_property('description')
        banner_path = None
        path = theme.get_property('banner_path')
        if path:
            banner = theme.get_resource(path, soft=True)
            if banner:
                ac = banner.get_access_control()
                if ac.is_allowed_to_view(context.user, banner):
                    banner_path = context.get_link(banner)
        banner_ns['path'] = banner_path
        namespace['banner'] = banner_ns

        # Site search
        text = context.get_form_value('text', type=Unicode)
        namespace['text'] = text.strip()

        # Specific class based on the current resource format
        class_id = getattr(here, 'class_id', None)
        if class_id:
            class_id = class_id.replace('/', '-slash-')
            view_name = context.view_name or here.get_default_view_name()
            page_css_class = '%s-%s' % (class_id, view_name)
            page_css_class = page_css_class.replace('_', '-')
            namespace['page_css_class'] = page_css_class.lower()
            # resources classes
            resource_classes = []
            r = here
            while not isinstance(r, type(site_root)):
                resource_classes.append(r)
                r = r.parent
            resource_classes = [ r.name for r in reversed(resource_classes) ]
            namespace['resource_class'] = ' '.join(resource_classes)
        else:
            namespace['page_css_class'] = None
            namespace['resource_class'] = None

        # Add custom data inside the template
        custom_data = theme.get_property('custom_data') or ''
        namespace['custom_data'] = XMLParser(custom_data)

        # RSS Feeds title
        namespace['rss_feeds'] = self.get_rss_feeds(context)

        # Turning footer
        turning_footer = site_root.get_resource('theme/turning-footer',
                                                soft=True)
        if turning_footer:
            view = turning_footer.view
            namespace['turning_footer'] = view.GET(turning_footer, context)
        else:
            namespace['turning_footer'] = None

        # backoffice class
        namespace['bo_class'] = self.get_backoffice_class(context)

        # Readonly
        body_css = None
        if here_ac.is_allowed_to_edit(context.user, here) \
                and type(context.database) is ROGitDatabase:
            body_css = 'readonly'
        namespace['body_css'] = body_css

        # Sidebar
        sidebar = None
        display_sidebar = (getattr(here, 'display_sidebar', True)
                and getattr(context.view, 'display_sidebar', True))
        if display_sidebar and here_ac.is_allowed_to_view(context.user, here):
            sidebar_resource = self.get_sidebar_resource(context)
            if sidebar_resource:
                order_name = sidebar_resource.sidebar_name
                sidebar_view = SideBar_View(order_name=order_name)
                if not sidebar_view.is_empty(sidebar_resource, context):
                    # Heuristic, do not compute sidebar view
                    # if there is no items
                    sidebar = sidebar_view.GET(sidebar_resource, context)

        namespace['sidebar_view'] = sidebar
        namespace['sidebar'] = sidebar or namespace['context_menus']

        # Language
        ws_languages = site_root.get_property('website_languages')
        accept = context.accept_language
        namespace['lang'] = accept.select_language(ws_languages)

        # Nav
        # If there is no template specify we simply return the namespace
        nav = self.build_nav_namespace(context)
        namespace['nav'] = nav
        namespace['nav_length'] = len(nav['items'])
        nav_template = self.nav_data['template']
        if nav_template is not None:
            nav_template = self.get_resource(nav_template)
            namespace['nav'] = stl(nav_template, {'items': nav['items']})

        # Footer
        namespace['footer'] = None
        footer_template = self.footer_data['template']
        if footer_template is not None:
            ns_footer = self.build_footer_namespace(context)
            footer = None
            if len(ns_footer['items']):
                footer_template = self.get_resource(footer_template)
                footer = stl(footer_template, ns_footer)
            namespace['footer'] = footer

        # Hide context menus if no user authenticated
        if context.user is None:
            namespace['context_menus'] = []

        # Allow to hide the menu if there is only one item
        namespace['display_menu'] = (namespace['nav_length'] > 1)

        # Admin bar
        site_root = context.site_root
        site_root_ac = site_root.get_access_control()
        if site_root_ac.is_allowed_to_edit(context.user, site_root):
            namespace['admin_bar'] = AdminBarTemplate(context=context)
        else:
            namespace['admin_bar'] = None
        return namespace
Пример #4
0
 def build_namespace(self, context):
     return merge_dicts(BaseSkin.build_namespace(self, context),
               title=context.view.get_title(context),
               context_menus=list(self._get_context_menus(context)))
Пример #5
0
    def build_namespace(self, context):
        namespace = BaseSkin.build_namespace(self, context)
        here = context.resource
        here_ac = here.get_access_control()
        site_root = context.site_root
        theme = site_root.get_resource("theme")
        # banner namespace
        banner_ns = {}
        banner_ns["title"] = theme.get_property("banner_title")
        banner_ns["description"] = site_root.get_property("description")
        banner_path = None
        path = theme.get_property("banner_path")
        if path:
            banner = theme.get_resource(path, soft=True)
            if banner:
                ac = banner.get_access_control()
                if ac.is_allowed_to_view(context.user, banner):
                    banner_path = context.get_link(banner)
        banner_ns["path"] = banner_path
        namespace["banner"] = banner_ns

        # Site search
        text = context.get_form_value("search_text", type=Unicode)
        namespace["text"] = text.strip()

        # Specific class based on the current resource format
        class_id = getattr(here, "class_id", None)
        if class_id:
            class_id = class_id.replace("/", "-slash-")
            view_name = context.view_name or here.get_default_view_name()
            page_css_class = "%s-%s" % (class_id, view_name)
            page_css_class = page_css_class.replace("_", "-")
            namespace["page_css_class"] = page_css_class.lower()
            # resources classes
            resource_classes = []
            r = here
            while not isinstance(r, type(site_root)):
                resource_classes.append(r)
                r = r.parent
            resource_classes = [r.name for r in reversed(resource_classes)]
            namespace["resource_class"] = " ".join(resource_classes)
        else:
            namespace["page_css_class"] = None
            namespace["resource_class"] = None

        # Add custom data inside the template
        custom_data = theme.get_property("custom_data") or ""
        namespace["custom_data"] = XMLParser(custom_data)

        # RSS Feeds title
        namespace["rss_feeds"] = self.get_rss_feeds(context)

        # Turning footer
        turning_footer = site_root.get_resource("theme/turning-footer", soft=True)
        if turning_footer:
            view = turning_footer.view
            namespace["turning_footer"] = view.GET(turning_footer, context)
        else:
            namespace["turning_footer"] = None

        # backoffice class
        namespace["bo_class"] = self.get_backoffice_class(context)

        # Readonly
        body_css = None
        if here_ac.is_allowed_to_edit(context.user, here) and type(context.database) is ROGitDatabase:
            body_css = "readonly"
        namespace["body_css"] = body_css

        # Sidebar
        sidebar = None
        nacfsv = tuple(not_allowed_cls_for_sidebar_view)
        is_allowed_cls = not isinstance(here, nacfsv)
        if is_allowed_cls:
            iasocv = self.is_allowed_sidebar_on_current_view(context)
            if iasocv:
                sidebar_resource = self.get_sidebar_resource(context)
                if sidebar_resource:
                    order_name = sidebar_resource.sidebar_name
                    sidebar_view = SideBar_View(order_name=order_name)
                    if not sidebar_view.is_empty(sidebar_resource, context):
                        # Heuristic, do not compute sidebar view
                        # if there is no items
                        sidebar = sidebar_view.GET(sidebar_resource, context)

        namespace["sidebar_view"] = sidebar
        namespace["sidebar"] = sidebar or namespace["context_menus"]

        # Language
        ws_languages = site_root.get_property("website_languages")
        accept = context.accept_language
        namespace["lang"] = accept.select_language(ws_languages)

        # Nav
        # If there is no template specify we simply return the namespace
        nav = self.build_nav_namespace(context)
        namespace["nav"] = nav
        namespace["nav_length"] = len(nav["items"])
        nav_template = self.nav_data["template"]
        if nav_template is not None:
            nav_template = self.get_resource(nav_template)
            namespace["nav"] = stl(nav_template, {"items": nav["items"]})

        # Footer
        namespace["footer"] = None
        footer_template = self.footer_data["template"]
        if footer_template is not None:
            ns_footer = self.build_footer_namespace(context)
            footer = None
            if len(ns_footer["items"]):
                footer_template = self.get_resource(footer_template)
                footer = stl(footer_template, ns_footer)
            namespace["footer"] = footer

        # Hide context menus if no user authenticated
        if context.user is None:
            namespace["context_menus"] = []

        # Allow to hide the menu if there is only one item
        namespace["display_menu"] = namespace["nav_length"] > 1

        # Admin bar
        if here_ac.is_allowed_to_edit(context.user, here):
            namespace["admin_bar"] = AdminBarTemplate(context=context)
        else:
            namespace["admin_bar"] = None

        # Search Template
        namespace["search"] = SearchTemplate(context=context)

        return namespace