Esempio n. 1
0
    def _update(self, portal):
        self.log.debug('Updating standard_template')
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        todo = {
            'jquery-ui.css': '<metal:block define-macro="standard-head-links">\n            <link rel="stylesheet" type="text/css" media="screen" tal:attributes="href string:${site_url}/www/js/css/jquery-ui.css" />',
            'additional_style_css': '<metal:block define-macro="standard-head-links">\n            <link rel="stylesheet" type="text/css" media="screen" tal:attributes="href string:${here/absolute_url}/additional_style_css" />',
        }

        entry_point = '<metal:block define-macro="standard-head-links">'

        changed = False
        for k, v in todo.items():
            if k in tal:
                self.log.debug('%s in standard_template' % k)
            else:
                self.log.debug('%s not in standard_template' % k)
                tal = tal.replace(entry_point, v)
                self.log.debug('added %s link', k)
                changed = True
        if changed:
            self.log.debug('standard_template changed')
            standard_template.write(tal)
        else:
            self.log.debug('standard_template not changed')
        return True
Esempio n. 2
0
    def _update(self, portal):
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        if 'HelpDesk/" accesskey="9" i18n:translate="">Feedback and helpdesk' not in tal:
            if 'Helpdesk' in tal:
                self.log.error(
                    "Helpdesk present in standard_template, but the code is not what we expect it to be..."
                )
            else:
                self.log.debug('Link to helpdesk not in standard_template')
        else:
            tal = tal.replace(
                'HelpDesk/" accesskey="9" i18n:translate="">Feedback and helpdesk',
                'feedback_html" accesskey="9" i18n:translate="">Feedback', 1)
            self.log.debug('Helpdesk link removed')
            standard_template.write(tal)

        helpdesks = [
            ob.getId() for ob in portal.objectValues('Naaya HelpDesk')
        ]
        if len(helpdesks) > 0:
            self.log.debug('Helpdesk objects %s removed' % helpdesks)
            portal.manage_delObjects(helpdesks)
        else:
            self.log.debug('No Naaya HelpDesk object in the portal root')
        return True
Esempio n. 3
0
    def _update(self, portal):
        old_logout = [
            ('<a tal:condition="python:username != \'Anonymous User\'" '
             'tal:attributes="href string:${site_url}/login_html" '
             'i18n:translate="">Logout <tal:block tal:content="string:'
             '(${username})" i18n:name="username" /></a>'),
            ('<a tal:condition="python:username != \'Anonymous User\'" '
             'tal:attributes="href string:${site_url}/login_html" '
             'i18n:translate="">Logout <tal:block tal:content="string:'
             '(${username})" i18n:name="username"/></a>'),
            ('<a tal:condition="python:username != \'Anonymous User\'" '
             'tal:attributes="href string:${site_url}/login/logout" '
             'i18n:translate="">Logout</a> <a tal:condition="python:'
             'username != \'Anonymous User\'" tal:define="'
             'user_full_name python:here.getAuthenticationTool().'
             'name_from_userid(username) or username" tal:attributes="'
             'href string:${site_url}/login_html" tal:content="string:'
             '(${user_full_name})" />'),
            ('<a tal:condition="python:username != \'Anonymous User\'" '
             'tal:attributes="href string:${site_url}/login/logout" '
             'i18n:translate="">Logout</a> <a tal:condition="'
             'python:username != \'Anonymous User\'" tal:define="'
             'user_full_name python:here.getAuthenticationTool().'
             'name_from_userid(username) or username" tal:attributes="'
             'href string:${site_url}/member_search?${username}" '
             'tal:content="string:(${user_full_name})" />')
        ]
        new_logout = (
            '<a tal:condition="python:username != \'Anonymous User\'" '
            'tal:attributes="href string:${site_url}/login/logout" '
            'i18n:translate="">Logout</a> <a tal:condition="python:username != '
            '\'Anonymous User\'" tal:define="user_full_name python:'
            'here.getAuthenticationTool().name_from_userid(username) '
            'or username" tal:attributes="href string:${site_url}/'
            'member_search?search_string=${username}" '
            'tal:content="string:(${user_full_name})" />')

        standard_template = get_standard_template(portal)
        tal = standard_template.read()
        if new_logout in tal:
            self.log.debug('Standard_template already updated')
        else:
            changed = False
            for tal_code in old_logout:
                if tal_code in tal:
                    tal = tal.replace(tal_code, new_logout)
                    changed = True
            if changed:
                standard_template.write(tal)
                self.log.debug('Standard_template updated')
            else:
                self.log.error('Old and new code not in standard_template')
                return False

        return True
    def update_standard_template(self, portal):
        self.log.debug('Updating standard_template')
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        if 'here/leftLogoUrl' in tal:
            self.log.debug(
                'before update here/leftLogoUrl in standard_template')
        else:
            self.log.debug(
                'before update here/leftLogoUrl not in standard_template')
        if 'here/rightLogoUrl' in tal:
            self.log.debug(
                'before update here/rightLogoUrl in standard_template')
        else:
            self.log.debug(
                'before update here/rightLogoUrl not in standard_template')

        mapping = [
            # change to leftLogoUrl
            ('python:test(here.hasLeftLogo(), here.leftLogoUrl(), here.defaultLeftLogoUrl())',
             'here/leftLogoUrl'),
            ('string:${here/getLayoutToolPath}/logo.gif', 'here/leftLogoUrl'),
            ('tal:condition="here/hasLeftLogo"',
             'tal:condition="here/leftLogoUrl"'),
            # change to rightLogoUrl
            ('python:test(here.hasRightLogo(), here.rightLogoUrl(), here.defaultRightLogoUrl())',
             'here/rightLogoUrl'),
            ('string:${here/getLayoutToolPath}/logobis.gif',
             'here/rightLogoUrl'),
            ('string:${here/getLayoutToolPath}/logobis', 'here/rightLogoUrl'),
            ('tal:condition="here/hasRightLogo"',
             'tal:condition="here/rightLogoUrl"'),
            # change right logo id
            ('id="logobis"', 'id="right_logo"'),
        ]
        changed = False
        for before, after in mapping:
            if before not in tal:
                continue
            tal = tal.replace(before, after)
            self.log.debug('changed to %r from %r', after, before)
            changed = True
        if changed:
            self.log.debug('standard_template changed')
            standard_template.write(tal)
        else:
            self.log.debug('standard_template not changed')
    def _update(self, portal):
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        if 'HelpDesk/" accesskey="9" i18n:translate="">Feedback and helpdesk' not in tal:
            if 'Helpdesk' in tal:
                self.log.error("Helpdesk present in standard_template, but the code is not what we expect it to be...")
            else:
                self.log.debug('Link to helpdesk not in standard_template')
        else:
            tal = tal.replace('HelpDesk/" accesskey="9" i18n:translate="">Feedback and helpdesk', 'feedback_html" accesskey="9" i18n:translate="">Feedback', 1)
            self.log.debug('Helpdesk link removed')
            standard_template.write(tal)

        helpdesks = [ob.getId() for ob in portal.objectValues('Naaya HelpDesk')]
        if len(helpdesks) > 0:
            self.log.debug('Helpdesk objects %s removed' % helpdesks)
            portal.manage_delObjects(helpdesks)
        else:
            self.log.debug('No Naaya HelpDesk object in the portal root')
        return True
    def _update(self, portal):

        policy_in_info = True
        standard_template = get_standard_template(portal)
        skin = portal.portal_layout.getCurrentSkin()
        scheme = portal.portal_layout.getCurrentSkinScheme()
        if hasattr(skin, 'common.css'):
            chm3 = True
        else:
            chm3 = False

        if not hasattr(skin, 'element_disclaimer'):
            self.log.debug('   element_disclaimer not in skin')
        else:
            if policy_in_info:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_info)
            else:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_About)
            self.log.debug('   element_disclaimer successfully updated')

        return True    
    def _update(self, portal):

        policy_in_info = True
        standard_template = get_standard_template(portal)
        skin = portal.portal_layout.getCurrentSkin()
        scheme = portal.portal_layout.getCurrentSkinScheme()
        if hasattr(skin, 'common.css'):
            chm3 = True
        else:
            chm3 = False

        if not hasattr(skin, 'element_disclaimer'):
            self.log.debug('   element_disclaimer not in skin')
        else:
            if policy_in_info:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_info)
            else:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_About)
            self.log.debug('   element_disclaimer successfully updated')

        return True
    def update_standard_template(self, portal):
        self.log.debug('Updating standard_template')
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        if 'here/leftLogoUrl' in tal:
            self.log.debug('before update here/leftLogoUrl in standard_template')
        else:
            self.log.debug('before update here/leftLogoUrl not in standard_template')
        if 'here/rightLogoUrl' in tal:
            self.log.debug('before update here/rightLogoUrl in standard_template')
        else:
            self.log.debug('before update here/rightLogoUrl not in standard_template')

        mapping = [
            # change to leftLogoUrl
            ('python:test(here.hasLeftLogo(), here.leftLogoUrl(), here.defaultLeftLogoUrl())', 'here/leftLogoUrl'),
            ('string:${here/getLayoutToolPath}/logo.gif', 'here/leftLogoUrl'),
            ('tal:condition="here/hasLeftLogo"', 'tal:condition="here/leftLogoUrl"'),
            # change to rightLogoUrl
            ('python:test(here.hasRightLogo(), here.rightLogoUrl(), here.defaultRightLogoUrl())', 'here/rightLogoUrl'),
            ('string:${here/getLayoutToolPath}/logobis.gif', 'here/rightLogoUrl'),
            ('string:${here/getLayoutToolPath}/logobis', 'here/rightLogoUrl'),
            ('tal:condition="here/hasRightLogo"', 'tal:condition="here/rightLogoUrl"'),
            # change right logo id
            ('id="logobis"', 'id="right_logo"'),
        ]
        changed = False
        for before, after in mapping:
            if before not in tal:
                continue
            tal = tal.replace(before, after)
            self.log.debug('changed to %r from %r', after, before)
            changed = True
        if changed:
            self.log.debug('standard_template changed')
            standard_template.write(tal)
        else:
            self.log.debug('standard_template not changed')
    def _update(self, portal):
        old_logout = [
            (
                "<a tal:condition=\"python:username != 'Anonymous User'\" "
                'tal:attributes="href string:${site_url}/login_html" '
                'i18n:translate="">Logout <tal:block tal:content="string:'
                '(${username})" i18n:name="username" /></a>'
            ),
            (
                "<a tal:condition=\"python:username != 'Anonymous User'\" "
                'tal:attributes="href string:${site_url}/login_html" '
                'i18n:translate="">Logout <tal:block tal:content="string:'
                '(${username})" i18n:name="username"/></a>'
            ),
            (
                "<a tal:condition=\"python:username != 'Anonymous User'\" "
                'tal:attributes="href string:${site_url}/login/logout" '
                'i18n:translate="">Logout</a> <a tal:condition="python:'
                "username != 'Anonymous User'\" tal:define=\""
                "user_full_name python:here.getAuthenticationTool()."
                'name_from_userid(username) or username" tal:attributes="'
                'href string:${site_url}/login_html" tal:content="string:'
                '(${user_full_name})" />'
            ),
            (
                "<a tal:condition=\"python:username != 'Anonymous User'\" "
                'tal:attributes="href string:${site_url}/login/logout" '
                'i18n:translate="">Logout</a> <a tal:condition="'
                "python:username != 'Anonymous User'\" tal:define=\""
                "user_full_name python:here.getAuthenticationTool()."
                'name_from_userid(username) or username" tal:attributes="'
                'href string:${site_url}/member_search?${username}" '
                'tal:content="string:(${user_full_name})" />'
            ),
        ]
        new_logout = (
            "<a tal:condition=\"python:username != 'Anonymous User'\" "
            'tal:attributes="href string:${site_url}/login/logout" '
            'i18n:translate="">Logout</a> <a tal:condition="python:username != '
            "'Anonymous User'\" tal:define=\"user_full_name python:"
            "here.getAuthenticationTool().name_from_userid(username) "
            'or username" tal:attributes="href string:${site_url}/'
            'member_search?search_string=${username}" '
            'tal:content="string:(${user_full_name})" />'
        )

        standard_template = get_standard_template(portal)
        tal = standard_template.read()
        if new_logout in tal:
            self.log.debug("Standard_template already updated")
        else:
            changed = False
            for tal_code in old_logout:
                if tal_code in tal:
                    tal = tal.replace(tal_code, new_logout)
                    changed = True
            if changed:
                standard_template.write(tal)
                self.log.debug("Standard_template updated")
            else:
                self.log.error("Old and new code not in standard_template")
                return False

        return True
Esempio n. 10
0
    def _update(self, portal):
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        if 'epFromCookiesToSession' not in tal:
            self.log.debug('No need to update')
            return True

        self.log.debug('This portal needs update')

        chm_new_expandable = """
            <!--expandable portlets-->
            <tal:block replace="structure here/epFromCookiesToSession" />
            <tal:block replace='structure string:<script type="text/javascript">' />
                var ep_path = '<tal:block replace="python:here.absolute_url(1)" />'
                var ep_collapse_path = '<tal:block replace="string:${skin_files_path}/ep_collapse.gif" />'
                var ep_expand_path = '<tal:block replace="string:${skin_files_path}/ep_expand.gif" />'
            <tal:block replace='structure string:</script>' />
            <!--end expandable portlets-->
"""
        chm_new_expandable = pat(chm_new_expandable)
        chm_new_expandable = re.sub(' {4,}', '\s+', chm_new_expandable)

        chm_expandable = """
            <!--expandable portlets-->
            <tal:block replace="structure here/epFromCookiesToSession" />
            <tal:block replace='structure string:<script type="text/javascript">' />
                var ep_path = '<tal:block replace="python:here.absolute_url(1)" />'
                var ep_collapse_path = '<tal:block replace="string:${skin_files_path}/ep_collapse.gif" />'
                var ep_expand_path = '<tal:block replace="string:${skin_files_path}/ep_expand.gif" />'
                var expandedPortlet = ''
            <tal:block replace='structure string:</script>' />
            <script type="text/javascript" tal:attributes="src python:here.getLayoutTool().getCurrentSkin().absolute_url() + '/script_expandableportlets_js'"></script>
            <!--end expandable portlets-->
"""
        chm_expandable = pat(chm_expandable)
        chm_expandable = re.sub(' {4,}', '\s+', chm_expandable)

        chm_expandable2 = """
            <!--expandable portlets-->
            <tal:block replace="structure here/epFromCookiesToSession" />
            <tal:block replace='structure string:<script type="text/javascript">' />
                var ep_path = '<tal:block replace="python:here.absolute_url(1)" />'
                var ep_collapse_path = '<tal:block replace="string:${skin_files_path}/ep_collapse.gif" />'
                var ep_expand_path = '<tal:block replace="string:${skin_files_path}/ep_expand.gif" />'
            <tal:block replace='structure string:</script>' />
            <script type="text/javascript" tal:attributes="src python:here.getLayoutTool().getCurrentSkin().absolute_url() + '/script_expandableportlets_js'"></script>
            <!--end expandable portlets-->
"""
        chm_expandable2 = pat(chm_expandable2)
        chm_expandable2 = re.sub(' {4,}', '\s+', chm_expandable2)

        if re.search(chm_new_expandable, tal):
            self.log.debug('Replacing the chm_new expandable portlets tags')
            tal = re.sub(chm_new_expandable, '', tal, count=1)
        elif re.search(chm_expandable, tal):
            self.log.debug(
                'Replacing the chm expandable portlets tags, version1')
            tal = re.sub(chm_expandable, '', tal, count=1)
        elif re.search(chm_expandable2, tal):
            self.log.debug(
                'Replacing the chm expandable portlets tags, version2')
            tal = re.sub(chm_expandable2, '', tal, count=1)
        else:
            self.log.error("Can't match any expandable portlets tags")
            return False

        standard_template.write(tal)
        return True
    def _update(self, portal):

        policy_in_info = True
        standard_template = get_standard_template(portal)
        skin = portal.portal_layout.getCurrentSkin()
        scheme = portal.portal_layout.getCurrentSkinScheme()
        if hasattr(skin, 'common.css'):
            chm3 = True
        else:
            chm3 = False

        self.log.debug('1. element_footer')
        if hasattr(skin, 'element_footer'):
            element_footer = skin.element_footer.read()
            if 'cookie_policy' in element_footer:
                self.log.debug('   cookie_policy already in element_footer')
            elif 'Feedback</a>' in element_footer:
                if 'info/copyright' in element_footer:
                    element_footer = element_footer.replace('Feedback</a>',
                        '%s\n%s' % ('Feedback</a>', COOKIE_POLICY_info))
                    self.log.debug('   element_footer uses "info"')
                elif 'About/copyright' in element_footer:
                    policy_in_info = False
                    element_footer = element_footer.replace('Feedback</a>',
                        '%s\n%s' % ('Feedback</a>', COOKIE_POLICY_About))
                    self.log.debug('   element_footer uses "About"')
                else:
                    self.log.error("   element_footer doesn't have the expected format")
                    return False
                skin.element_footer.write(element_footer)
                self.log.debug('   cookie_policy added to element_footer')
            else:
                self.log.error("   element_footer doesn't have the expected format")
                self.log.error("   element_footer NOT updated")
        else:
            self.log.debug('   no element_footer, so we use standard_template')
            tal = standard_template.read()
            if 'cookie_policy' in tal:
                self.log.debug('   cookie_policy already in standard_template')
            elif 'Feedback</a>]' in tal:
                if 'info/copyright' in tal:
                    tal = tal.replace('Feedback</a>]',
                        '%s\n[%s]' % ('Feedback</a>]', COOKIE_POLICY_info))
                    self.log.debug('   standard_template uses "info"')
                elif 'About/copyright' in tal:
                    policy_in_info = False
                    tal = tal.replace('Feedback</a>]',
                        '%s\n[%s]' % ('Feedback</a>]', COOKIE_POLICY_About))
                    self.log.debug('   standard_template uses "About"')
                else:
                    self.log.error("   element_footer doesn't have the expected format")
                    return False
                standard_template.write(tal)
                self.log.debug('   standard template updated with cookie_policy link')
            else:
                self.log.error("   element_footer doesn't have the expected format")
                self.log.error("   element_footer NOT updated")

        self.log.debug('2. element_disclaimer')
        if hasattr(skin, 'element_disclaimer'):
            self.log.debug('   element_disclaimer already in skin')
        else:
            skin.manage_addTemplate(id='element_disclaimer')
            if policy_in_info:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_info)
            else:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_About)
            self.log.debug('   element_disclaimer successfully added')

        self.log.debug('3. create document')
        if policy_in_info:
            container = portal.info
        else:
            container = portal.About
        if hasattr(container, 'cookie_policy'):
            self.log.debug('   cookie_policy already present')
        else:
            from naaya.content.document.document_item import _create_NyDocument_object
            _create_NyDocument_object(container, 'cookie_policy', self.REQUEST.AUTHENTICATED_USER.getUserName())
            container.cookie_policy.saveProperties(
                title="Cookie policy", body=COOKIE_POLICY_DOCUMENT)
            container.cookie_policy.submit_this()
            self.log.debug('   cookie_policy document created in %s' % container.getId())

        self.log.debug('4. standard_template')
        tal = standard_template.read()
        if '"disclaimer">' in tal:
            self.log.debug('   disclaimer slot already in standard_template')
        elif '<div id="header">' not in tal:
            self.log.error("   standard_template doesn't have the expected <div id='header'>")
            return False
        else:
            if chm3:
                tal = tal.replace('<div id="header">',
                    '%s\n%s' % (DISCLAIMER_SLOT_CHM3, '<div id="header">'))
            else:
                tal = tal.replace('<div id="header">',
                    '%s\n%s' % (DISCLAIMER_SLOT_CHM2, '<div id="header">'))
            standard_template.write(tal)
            self.log.debug('   disclaimer slot added to standard_template')

        self.log.debug('5. common.css')
        if chm3:
            if skin['common.css'].meta_type == 'Naaya Disk File':
                self.log.debug('   common.css is DiskFile, no need for an update')
            else:
                common_css = skin['common.css'].data
                if 'Styling for the Cookies Disclaimer message' in common_css:
                    self.log.debug('   common.css already updated')
                else:
                    common_css = '%s\n%s' % (common_css, DISCLAIMER_CSS)
                    skin['common.css'].data = common_css
                    self.log.debug('   common.css updated')
        else:
            common_css = scheme.style_common.read()
            if 'Styling for the Cookies Disclaimer message' in common_css:
                self.log.debug('   style_common already updated')
            else:
                common_css = '%s\n%s' % (common_css, DISCLAIMER_CSS)
                scheme.style_common.write(common_css)
                self.log.debug('   style_common updated')
        return True
    def _update(self, portal):

        policy_in_info = True
        standard_template = get_standard_template(portal)
        skin = portal.portal_layout.getCurrentSkin()
        scheme = portal.portal_layout.getCurrentSkinScheme()
        if hasattr(skin, 'common.css'):
            chm3 = True
        else:
            chm3 = False

        self.log.debug('1. element_footer')
        if hasattr(skin, 'element_footer'):
            element_footer = skin.element_footer.read()
            if 'cookie_policy' in element_footer:
                self.log.debug('   cookie_policy already in element_footer')
            elif 'Feedback</a>' in element_footer:
                if 'info/copyright' in element_footer:
                    element_footer = element_footer.replace(
                        'Feedback</a>',
                        '%s\n%s' % ('Feedback</a>', COOKIE_POLICY_info))
                    self.log.debug('   element_footer uses "info"')
                elif 'About/copyright' in element_footer:
                    policy_in_info = False
                    element_footer = element_footer.replace(
                        'Feedback</a>',
                        '%s\n%s' % ('Feedback</a>', COOKIE_POLICY_About))
                    self.log.debug('   element_footer uses "About"')
                else:
                    self.log.error(
                        "   element_footer doesn't have the expected format")
                    return False
                skin.element_footer.write(element_footer)
                self.log.debug('   cookie_policy added to element_footer')
            else:
                self.log.error(
                    "   element_footer doesn't have the expected format")
                self.log.error("   element_footer NOT updated")
        else:
            self.log.debug('   no element_footer, so we use standard_template')
            tal = standard_template.read()
            if 'cookie_policy' in tal:
                self.log.debug('   cookie_policy already in standard_template')
            elif 'Feedback</a>]' in tal:
                if 'info/copyright' in tal:
                    tal = tal.replace(
                        'Feedback</a>]',
                        '%s\n[%s]' % ('Feedback</a>]', COOKIE_POLICY_info))
                    self.log.debug('   standard_template uses "info"')
                elif 'About/copyright' in tal:
                    policy_in_info = False
                    tal = tal.replace(
                        'Feedback</a>]',
                        '%s\n[%s]' % ('Feedback</a>]', COOKIE_POLICY_About))
                    self.log.debug('   standard_template uses "About"')
                else:
                    self.log.error(
                        "   element_footer doesn't have the expected format")
                    return False
                standard_template.write(tal)
                self.log.debug(
                    '   standard template updated with cookie_policy link')
            else:
                self.log.error(
                    "   element_footer doesn't have the expected format")
                self.log.error("   element_footer NOT updated")

        self.log.debug('2. element_disclaimer')
        if hasattr(skin, 'element_disclaimer'):
            self.log.debug('   element_disclaimer already in skin')
        else:
            skin.manage_addTemplate(id='element_disclaimer')
            if policy_in_info:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_info)
            else:
                skin.element_disclaimer.write(ELEMENT_DISCLAIMER_About)
            self.log.debug('   element_disclaimer successfully added')

        self.log.debug('3. create document')
        if policy_in_info:
            container = portal.info
        else:
            container = portal.About
        if hasattr(container, 'cookie_policy'):
            self.log.debug('   cookie_policy already present')
        else:
            from naaya.content.document.document_item import _create_NyDocument_object
            _create_NyDocument_object(
                container, 'cookie_policy',
                self.REQUEST.AUTHENTICATED_USER.getUserName())
            container.cookie_policy.saveProperties(title="Cookie policy",
                                                   body=COOKIE_POLICY_DOCUMENT)
            container.cookie_policy.submit_this()
            self.log.debug('   cookie_policy document created in %s' %
                           container.getId())

        self.log.debug('4. standard_template')
        tal = standard_template.read()
        if '"disclaimer">' in tal:
            self.log.debug('   disclaimer slot already in standard_template')
        elif '<div id="header">' not in tal:
            self.log.error(
                "   standard_template doesn't have the expected <div id='header'>"
            )
            return False
        else:
            if chm3:
                tal = tal.replace(
                    '<div id="header">',
                    '%s\n%s' % (DISCLAIMER_SLOT_CHM3, '<div id="header">'))
            else:
                tal = tal.replace(
                    '<div id="header">',
                    '%s\n%s' % (DISCLAIMER_SLOT_CHM2, '<div id="header">'))
            standard_template.write(tal)
            self.log.debug('   disclaimer slot added to standard_template')

        self.log.debug('5. common.css')
        if chm3:
            if skin['common.css'].meta_type == 'Naaya Disk File':
                self.log.debug(
                    '   common.css is DiskFile, no need for an update')
            else:
                common_css = skin['common.css'].data
                if 'Styling for the Cookies Disclaimer message' in common_css:
                    self.log.debug('   common.css already updated')
                else:
                    common_css = '%s\n%s' % (common_css, DISCLAIMER_CSS)
                    skin['common.css'].data = common_css
                    self.log.debug('   common.css updated')
        else:
            common_css = scheme.style_common.read()
            if 'Styling for the Cookies Disclaimer message' in common_css:
                self.log.debug('   style_common already updated')
            else:
                common_css = '%s\n%s' % (common_css, DISCLAIMER_CSS)
                scheme.style_common.write(common_css)
                self.log.debug('   style_common updated')
        return True
    def _update(self, portal):
        standard_template = get_standard_template(portal)
        tal = standard_template.read()

        if "epFromCookiesToSession" not in tal:
            self.log.debug("No need to update")
            return True

        self.log.debug("This portal needs update")

        chm_new_expandable = """
            <!--expandable portlets-->
            <tal:block replace="structure here/epFromCookiesToSession" />
            <tal:block replace='structure string:<script type="text/javascript">' />
                var ep_path = '<tal:block replace="python:here.absolute_url(1)" />'
                var ep_collapse_path = '<tal:block replace="string:${skin_files_path}/ep_collapse.gif" />'
                var ep_expand_path = '<tal:block replace="string:${skin_files_path}/ep_expand.gif" />'
            <tal:block replace='structure string:</script>' />
            <!--end expandable portlets-->
"""
        chm_new_expandable = pat(chm_new_expandable)
        chm_new_expandable = re.sub(" {4,}", "\s+", chm_new_expandable)

        chm_expandable = """
            <!--expandable portlets-->
            <tal:block replace="structure here/epFromCookiesToSession" />
            <tal:block replace='structure string:<script type="text/javascript">' />
                var ep_path = '<tal:block replace="python:here.absolute_url(1)" />'
                var ep_collapse_path = '<tal:block replace="string:${skin_files_path}/ep_collapse.gif" />'
                var ep_expand_path = '<tal:block replace="string:${skin_files_path}/ep_expand.gif" />'
                var expandedPortlet = ''
            <tal:block replace='structure string:</script>' />
            <script type="text/javascript" tal:attributes="src python:here.getLayoutTool().getCurrentSkin().absolute_url() + '/script_expandableportlets_js'"></script>
            <!--end expandable portlets-->
"""
        chm_expandable = pat(chm_expandable)
        chm_expandable = re.sub(" {4,}", "\s+", chm_expandable)

        chm_expandable2 = """
            <!--expandable portlets-->
            <tal:block replace="structure here/epFromCookiesToSession" />
            <tal:block replace='structure string:<script type="text/javascript">' />
                var ep_path = '<tal:block replace="python:here.absolute_url(1)" />'
                var ep_collapse_path = '<tal:block replace="string:${skin_files_path}/ep_collapse.gif" />'
                var ep_expand_path = '<tal:block replace="string:${skin_files_path}/ep_expand.gif" />'
            <tal:block replace='structure string:</script>' />
            <script type="text/javascript" tal:attributes="src python:here.getLayoutTool().getCurrentSkin().absolute_url() + '/script_expandableportlets_js'"></script>
            <!--end expandable portlets-->
"""
        chm_expandable2 = pat(chm_expandable2)
        chm_expandable2 = re.sub(" {4,}", "\s+", chm_expandable2)

        if re.search(chm_new_expandable, tal):
            self.log.debug("Replacing the chm_new expandable portlets tags")
            tal = re.sub(chm_new_expandable, "", tal, count=1)
        elif re.search(chm_expandable, tal):
            self.log.debug("Replacing the chm expandable portlets tags, version1")
            tal = re.sub(chm_expandable, "", tal, count=1)
        elif re.search(chm_expandable2, tal):
            self.log.debug("Replacing the chm expandable portlets tags, version2")
            tal = re.sub(chm_expandable2, "", tal, count=1)
        else:
            self.log.error("Can't match any expandable portlets tags")
            return False

        standard_template.write(tal)
        return True