Exemple #1
0
 def xhr_filemgr(self):
     cmd = ''
     cmd_args = dict()
     for k in self.request.params:
         if k == '_':
             continue
         if k == 'cmd':
             cmd = self.request.params[k]
         else:
             if k.endswith("[]"):
                 k2 = k.rstrip("[]")
                 cmd_args[k2] = self.request.params.getall(k)
             else:
                 cmd_args[k] = self.request.params[k]
     finder = create_finder(self.context, self.request)
     try:
         finder.run(cmd, cmd_args)
     except FinderError as e:
         L.exception(e)
         if e.status:
             self.request.response.status = e.status
     if 'file' in finder.response:
         resp = Response()
         resp.app_iter = finder.response['file']
         if finder.headers:
             for k, v in finder.headers.items():
                 resp.headers[k] = v
         return resp
     else:
         if finder.headers:
             for k, v in finder.headers.items():
                 self.request.response.headers[k] = v
         return finder.response
Exemple #2
0
    def _inject_wysiwyg(self, html):
        plugins = [
            'common/align',
            'common/block',
            'common/dom-to-xhtml',
            'common/format',
            'common/highlighteditables',
            'common/image',
            'common/link',
            'common/list',
            'common/paste',
            'common/table',
            'common/ui',
            'common/undo',
            'extra/metaview'
        ]
        data = dict(
            aloha_css_url=self.request.static_url(
                'pysite:static/app/libs/aloha/css/aloha.css'),
            jqui_css_url=self.request.static_url(
                'pysite:static/app/libs/jquery/ui/themes/'
                'humanity/jquery-ui.css'),
            pnotify_css_url=self.request.static_url(
                'pysite:static/app/libs/jquery/ui/pnotify/'
                'jquery.pnotify.default.css'),
            wysiwyg_css_url=self.request.static_url(
                'pysite:static/css/pym.editor.wysiwyg.css'),
            base_url=self.request.static_url(
                'pysite:static/app'),
            plugins_js_url=self.request.static_url(
                'pysite:static/app/libs/plugins.js'),
            require_js_url=self.request.static_url(
                'pysite:static/app/libs/aloha/lib/require.js'),
            aloha_js_url=self.request.static_url(
                'pysite:static/app/libs/aloha/lib/aloha.js'),
            plugins=','.join(plugins)
        )
        html = re.sub(r'</head\s*>',
            WYSIWYG_LOAD.format(**data),
            html,
            flags=re.I
        )

        from pysite.filemgr import create_finder
        finder = create_finder(self.context.site, self.request)
        filename = self.context.__name__ + '.jinja2'
        path = os.path.join(self.context.dir_, filename)
        hash_ = finder.default_volume.encode(path)

        data = dict(
            GUI_TOKEN=self.request.session.get_csrf_token().decode('utf-8'),
            USERNAME=self.request.user.display_name,
            LOGOUT_URL=self.request.resource_url(self.context.site,
                '@@logout'),
            SAVE_URL=self.request.resource_url(self.context,
                '@@xhr_save_content'),
            SOURCE_URL=self.request.resource_url(self.context.site,
                '@@editor'),
            FILEMGR_URL=self.request.resource_url(self.context.site,
                '@@filemgr'),
            MIME='text/html',
            FILENAME=filename,
            HASH=hash_,
            SELECTOR='.editable'
        )
        wysiwyg_start = string.Template(WYSIWYG_START).substitute(data)
        html = re.sub(r'</body\s*>', wysiwyg_start, html, flags=re.I)
        return html