コード例 #1
0
def execute(pagename, request):
    enter_page(request, pagename, "Group Editor")
    macro = wikiutil.importPlugin(request.cfg, "macro", "GroupEditor", "do_macro")
    request.write(macro(request))
    page = Page(request, pagename)
    request.write(page.link_to(request, text=request.getText("back")))
    exit_page(request, pagename)
コード例 #2
0
def execute(pagename, request):
    enter_page(request, pagename, "Group Editor")
    macro = wikiutil.importPlugin(request.cfg, "macro", "GroupEditor",
                                  "do_macro")
    request.write(macro(request))
    page = Page(request, pagename)
    request.write(page.link_to(request, text=request.getText("back")))
    exit_page(request, pagename)
コード例 #3
0
def execute(pagename, request):
    _ = request.getText

    def wr(fmt, *args):
        request.write(form_writer(fmt, *args))

    # This action generates data using the user language
    request.setContentLanguage(request.lang)
    form = values_to_form(request.values)

    if form.has_key('cancel'):
        request.reset()
        backto = form.get('backto', [None])[0]
        request.theme.add_msg(_('Edit was cancelled.'), "error")
        if backto:
            page = Page(request, backto)
            request.http_redirect(page.url(request))
            request.page = page

        request.page.send_page()
    elif form.has_key('save') or form.has_key('saveform'):
        if request.environ['REQUEST_METHOD'] != 'POST':
            request.page.send_page()
            return

        template = form.get('template', [None])[0]

        # MetaFormEdit is much closer to set_meta in function
        if form.has_key('saveform'):
            added, cleared = {pagename: dict()}, {pagename: list()}

            # Pre-create page if it does not exist, using the template specified
            if template:
                added[pagename]['gwikitemplate'] = template

            # Ignore form clutter
            ignore = set()
            files = dict()
            for key in request.files:
                ignore.add(key)
                _file = request.files.get(key)
                filename = _file.filename
                fileobj = _file.stream

#                    if type(fileobj) != file:
#                        continue

                banana = key.split(SEPARATOR)
                keys = files.setdefault(banana[0], dict())
                values = keys.setdefault(banana[1], list())
                values.append((filename, fileobj))

            keys = list()
            for key in form:
                if key not in ignore and SEPARATOR in key:
                    keys.append(key.split(SEPARATOR)[1])
#            keys = [x.split(SEPARATOR)[1] for x in form if SEPARATOR in x]

            for key in keys:
                cleared[pagename].append(key)
                vals = [x.strip() for x in form[pagename + SEPARATOR + key]
                            if x.strip()]
                if vals:
                    added[pagename].setdefault(key, list()).extend(vals)

            msgs = list()
            # Add attachments
            for pname in files:
                for key in files[pname]:
                    for value in files[pname][key]:
                        name = value[0]
                        try:
                            t, s = add_attachment(request, pname,
                                                  name, value[1])
                            added.setdefault(pname, dict()).setdefault(
                                key, list()).append("[[attachment:%s]]" % name)
                        except AttachmentAlreadyExists:
                            msgs = ["Attachment '%s' already exists." % name]

            _, msgss = set_metas(request, cleared, dict(), added)
            msgs.extend(msgss)

        else:
            # MetaEdit
            pages, msgs, files = parse_editform(request, form)

            if pages:
                saved_templates = False

                for page, _ in pages.iteritems():
                    # Save the template if needed
                    if not Page(request, page).exists() and template:
                        msgs.append(save_template(request, page, template))
                        saved_templates = True

                # If new pages were changed we need to redo parsing
                # the form to know what we really need to edit
                if saved_templates:
                    pages, newmsgs, files = parse_editform(request, form)

                for page, (oldMeta, newMeta) in pages.iteritems():
                    msgs.append('%s: ' % page +
                                edit_meta(request, page, oldMeta, newMeta))

                for page in files:
                    for key in files[page]:
                        name, content = files[page][key]
                        t, s = add_attachment(request, page, name, content)
            else:
                msgs.append(request.getText('No pages changed'))

        msg = ''
        for line in msgs:
            msg += line + request.formatter.linebreak(0)

        request.reset()
        backto = form.get('backto', [None])[0]
        if backto:
            page = Page(request, backto)
            request.http_redirect(page.url(request))
        else:
            page = Page(request, pagename)

        request.theme.add_msg(msg)
        request.page = page
        page.send_page()
    elif form.has_key('args'):
        enter_page(request, pagename, 'Metatable editor')
        formatter = request.page.formatter

        request.write(formatter.heading(1, 2))
        request.write(formatter.text(_("Edit metatable")))
        request.write(formatter.heading(0, 2))
        args = ', '.join(form['args'])
        show_editform(wr, request, pagename, args)

        exit_page(request, pagename)
    else:
        enter_page(request, pagename, 'Metatable editor')
        formatter = request.page.formatter

        request.write(formatter.heading(1, 2))
        request.write(formatter.text(_("Edit current page")))
        request.write(formatter.heading(0, 2))
        show_editform(wr, request, pagename, pagename)

        request.write(formatter.heading(1, 2))
        request.write(formatter.text(_("Edit metatable")))
        request.write(formatter.heading(0, 2))
        show_queryform(wr, request, pagename)

        exit_page(request, pagename)
    return
コード例 #4
0
    def execute(self):
        request = self.request
        _ = request.getText

        pagename = request.page.page_name
        if not request.user.may.read(pagename):
            fault = _(u'Can not read page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        form = values_to_form(request.values)
        self.formargs(form)

        if self.help or not self.attachment:
            enter_page(request, pagename, 'View .gv attachment')

            self.sendForm()

            if self.help:
                # This is the URL addition to the nodes that have graph data
                self.urladd = url_parameters(form)
                self.urladd = self.urladd.replace('&help=Inline', '')
                request.write('<<ViewDot(' + self.urladd + ')>>')

            exit_page(request, pagename)
            return

        if not self.attachment[:10].lower() == 'attachment':
            fault = _(u'No attachment defined') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.attachment = self.attachment[11:]

        pagename, filename = AttachFile.absoluteName(self.attachment,
                                                     self.pagename)
        if not request.user.may.read(pagename):
            fault = _(u'Can not read attachment page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        fname = wikiutil.taintfilename(filename)
        fpath = AttachFile.getFilename(request, pagename, fname)

        try:
            data = file(fpath, 'r').read()
        except IOError:
            fault = _(u'Can not read attachment') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        if not have_gv():
            fault = _(u"ERROR: Graphviz Python extensions not installed. " +\
                      u"Not performing layout.")
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.cache_key = cache_key(self.request,
                                   [data, self.graphengine, self.format])
        key = "%s-%s" % (self.cache_key, self.format)

        if self.format in ['zgr', 'svg']:
            formatcontent = 'svg+xml'
        else:
            formatcontent = self.format

        if not cache_exists(request, key):
            graphviz = Graphviz(engine=self.graphengine, string=data)
            data = self.getLayoutInFormat(graphviz, self.format)

            cache.put(self.request, key, data, content_type=formatcontent)

        if self.format in ['zgr', 'svg']:
            # Display zgr graphs as applets
            if self.format == 'zgr':
                image_p = lambda url, text: \
                    '<applet code="net.claribole.zgrviewer.ZGRApplet.class"'+ \
                    ' archive="%s/gwikicommon/zgrviewer/zvtm.jar,' % \
                    (self.request.cfg.url_prefix_static) + \
                    '%s/gwikicommon/zgrviewer/zgrviewer.jar" ' % \
                    (self.request.cfg.url_prefix_static) + \
                    'width="%s" height="%s">' % (form_escape(self.width), form_escape(self.height))+\
                    '<param name="type" ' + \
                    'value="application/x-java-applet;version=1.4" />' + \
                    '<param name="scriptable" value="false" />' + \
                    '<param name="svgURL" value="%s" />' % (url) + \
                    '<param name="title" value="ZGRViewer - Applet" />'+ \
                    '<param name="appletBackgroundColor" value="#DDD" />' + \
                    '<param name="graphBackgroundColor" value="#DDD" />' + \
                    '<param name="highlightColor" value="red" />' + \
                    ' </applet><br>\n'
            else:
                image_p = lambda url, text: \
                    '<object data="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml">\n' + \
                    '<embed src="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml"/>\n</object>'
        else:
            image_p = lambda url, text: \
                '<img src="%s" alt="%s">\n' % (url, text)

        image_uri = cache.url(self.request, key)

        if not self.inline:
            if self.format == 'zgr':
                request.write('<html><body>')

        request.write(image_p(image_uri, _('visualisation')))

        if not self.inline and self.format == 'zgr':
            request.write('</html></body>')
        else:
            pass # No footer
コード例 #5
0
ファイル: MetaEdit.py プロジェクト: execgit/graphingwiki
def execute(pagename, request):
    _ = request.getText

    def wr(fmt, *args):
        request.write(form_writer(fmt, *args))

    # This action generates data using the user language
    request.setContentLanguage(request.lang)
    form = values_to_form(request.values)

    if form.has_key('cancel'):
        request.reset()
        backto = form.get('backto', [None])[0]
        request.theme.add_msg(_('Edit was cancelled.'), "error")
        if backto:
            page = Page(request, backto)
            request.http_redirect(page.url(request))
            request.page = page

        request.page.send_page()
    elif form.has_key('save') or form.has_key('saveform'):
        if request.environ['REQUEST_METHOD'] != 'POST':
            request.page.send_page()
            return

        template = form.get('template', [None])[0]

        # MetaFormEdit is much closer to set_meta in function
        if form.has_key('saveform'):
            added, cleared = {pagename: dict()}, {pagename: list()}

            # Pre-create page if it does not exist, using the template specified
            if template:
                added[pagename]['gwikitemplate'] = template

            # Ignore form clutter
            ignore = set()
            files = dict()
            for key in request.files:
                ignore.add(key)
                _file = request.files.get(key)
                filename = _file.filename
                fileobj = _file.stream

                #                    if type(fileobj) != file:
                #                        continue

                banana = key.split(SEPARATOR)
                keys = files.setdefault(banana[0], dict())
                values = keys.setdefault(banana[1], list())
                values.append((filename, fileobj))

            keys = list()
            for key in form:
                if key not in ignore and SEPARATOR in key:
                    keys.append(key.split(SEPARATOR)[1])


#            keys = [x.split(SEPARATOR)[1] for x in form if SEPARATOR in x]

            for key in keys:
                cleared[pagename].append(key)
                vals = [
                    x.strip() for x in form[pagename + SEPARATOR + key]
                    if x.strip()
                ]
                if vals:
                    added[pagename].setdefault(key, list()).extend(vals)

            msgs = list()
            # Add attachments
            for pname in files:
                for key in files[pname]:
                    for value in files[pname][key]:
                        name = value[0]
                        try:
                            t, s = add_attachment(request, pname, name,
                                                  value[1])
                            added.setdefault(pname, dict()).setdefault(
                                key, list()).append("[[attachment:%s]]" % name)
                        except AttachmentAlreadyExists:
                            msgs = ["Attachment '%s' already exists." % name]

            _, msgss = set_metas(request, cleared, dict(), added)
            msgs.extend(msgss)

        else:
            # MetaEdit
            pages, msgs, files = parse_editform(request, form)

            if pages:
                saved_templates = False

                for page, _ in pages.iteritems():
                    # Save the template if needed
                    if not Page(request, page).exists() and template:
                        msgs.append(save_template(request, page, template))
                        saved_templates = True

                # If new pages were changed we need to redo parsing
                # the form to know what we really need to edit
                if saved_templates:
                    pages, newmsgs, files = parse_editform(request, form)

                for page, (oldMeta, newMeta) in pages.iteritems():
                    msgs.append('%s: ' % page +
                                edit_meta(request, page, oldMeta, newMeta))

                for page in files:
                    for key in files[page]:
                        name, content = files[page][key]
                        t, s = add_attachment(request, page, name, content)
            else:
                msgs.append(request.getText('No pages changed'))

        msg = ''
        for line in msgs:
            msg += line + request.formatter.linebreak(0)

        request.reset()
        backto = form.get('backto', [None])[0]
        if backto:
            page = Page(request, backto)
            request.http_redirect(page.url(request))
        else:
            page = Page(request, pagename)

        request.theme.add_msg(msg)
        request.page = page
        page.send_page()
    elif form.has_key('args'):
        enter_page(request, pagename, 'Metatable editor')
        formatter = request.page.formatter

        request.write(formatter.heading(1, 2))
        request.write(formatter.text(_("Edit metatable")))
        request.write(formatter.heading(0, 2))
        args = ', '.join(form['args'])
        show_editform(wr, request, pagename, args)

        exit_page(request, pagename)
    else:
        enter_page(request, pagename, 'Metatable editor')
        formatter = request.page.formatter

        request.write(formatter.heading(1, 2))
        request.write(formatter.text(_("Edit current page")))
        request.write(formatter.heading(0, 2))
        show_editform(wr, request, pagename, pagename)

        request.write(formatter.heading(1, 2))
        request.write(formatter.text(_("Edit metatable")))
        request.write(formatter.heading(0, 2))
        show_queryform(wr, request, pagename)

        exit_page(request, pagename)
    return
コード例 #6
0
ファイル: ViewDot.py プロジェクト: execgit/graphingwiki
    def execute(self):
        request = self.request
        _ = request.getText

        pagename = request.page.page_name
        if not request.user.may.read(pagename):
            fault = _(u'Can not read page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        form = values_to_form(request.values)
        self.formargs(form)

        if self.help or not self.attachment:
            enter_page(request, pagename, 'View .gv attachment')

            self.sendForm()

            if self.help:
                # This is the URL addition to the nodes that have graph data
                self.urladd = url_parameters(form)
                self.urladd = self.urladd.replace('&help=Inline', '')
                request.write('&lt;&lt;ViewDot(' + self.urladd + ')&gt;&gt;')

            exit_page(request, pagename)
            return

        if not self.attachment[:10].lower() == 'attachment':
            fault = _(u'No attachment defined') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.attachment = self.attachment[11:]

        pagename, filename = AttachFile.absoluteName(self.attachment,
                                                     self.pagename)
        if not request.user.may.read(pagename):
            fault = _(u'Can not read attachment page') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        fname = wikiutil.taintfilename(filename)
        fpath = AttachFile.getFilename(request, pagename, fname)

        try:
            data = file(fpath, 'r').read()
        except IOError:
            fault = _(u'Can not read attachment') + u'\n'
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        if not gv_found:
            fault = _(u"ERROR: Graphviz Python extensions not installed. " +\
                      u"Not performing layout.")
            if self.inline:
                request.write(request.formatter.text(fault))
                return
            request.content_type = 'text/plain'
            request.write(fault)
            return

        self.cache_key = cache_key(self.request,
                                   [data, self.graphengine, self.format])
        key = "%s-%s" % (self.cache_key, self.format)

        if self.format in ['zgr', 'svg']:
            formatcontent = 'svg+xml'
        else:
            formatcontent = self.format

        if not cache_exists(request, key):
            graphviz = Graphviz(engine=self.graphengine, string=data)
            data = self.getLayoutInFormat(graphviz, self.format)

            cache.put(self.request, key, data, content_type=formatcontent)

        if self.format in ['zgr', 'svg']:
            # Display zgr graphs as applets
            if self.format == 'zgr':
                image_p = lambda url, text: \
                    '<applet code="net.claribole.zgrviewer.ZGRApplet.class"'+ \
                    ' archive="%s/gwikicommon/zgrviewer/zvtm.jar,' % \
                    (self.request.cfg.url_prefix_static) + \
                    '%s/gwikicommon/zgrviewer/zgrviewer.jar" ' % \
                    (self.request.cfg.url_prefix_static) + \
                    'width="%s" height="%s">' % (form_escape(self.width), form_escape(self.height))+\
                    '<param name="type" ' + \
                    'value="application/x-java-applet;version=1.4" />' + \
                    '<param name="scriptable" value="false" />' + \
                    '<param name="svgURL" value="%s" />' % (url) + \
                    '<param name="title" value="ZGRViewer - Applet" />'+ \
                    '<param name="appletBackgroundColor" value="#DDD" />' + \
                    '<param name="graphBackgroundColor" value="#DDD" />' + \
                    '<param name="highlightColor" value="red" />' + \
                    ' </applet><br>\n'
            else:
                image_p = lambda url, text: \
                    '<object data="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml">\n' + \
                    '<embed src="%s" alt="%s" ' % (url, text) + \
                    'type="image/svg+xml"/>\n</object>'
        else:
            image_p = lambda url, text: \
                '<img src="%s" alt="%s">\n' % (url, text)

        image_uri = cache.url(self.request, key)

        if not self.inline:
            if self.format == 'zgr':
                request.write('<html><body>')

        request.write(image_p(image_uri, _('visualisation')))

        if not self.inline and self.format == 'zgr':
            request.write('</html></body>')
        else:
            pass  # No footer