view MoinMoin/converter/nonexistent_in.py @ 1910:78b7a1136984

use constants in MoinMoin.constans.{item,content}types more
author Cheer Xiao <xiaqqaix@gmail.com>
date Thu, 17 Jan 2013 17:45:41 +0800
parents bff62fea804a
children 384555088cab
line wrap: on
line source
# Copyright: 2010 MoinMoin:ThomasWaldmann
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
MoinMoin - converter for non-existing items

Convert a non-existent item to the DOM Tree.
"""


from emeraldtree import ElementTree as ET

from MoinMoin.i18n import _, L_, N_
from MoinMoin.util.iri import Iri
from MoinMoin.util.tree import moin_page, xlink
from MoinMoin.constants.contenttypes import CONTENTTYPE_NONEXISTENT


class Converter(object):
    """
    Convert a non-existing item to DOM Tree.
    """
    @classmethod
    def _factory(cls, input, output, **kw):
        return cls()

    def __call__(self, rev, contenttype=None, arguments=None):
        item_name = rev.item.name
        attrib = {
            xlink.href: Iri(scheme='wiki', authority='', path='/'+item_name, query='do=modify'),
        }
        a = moin_page.a(attrib=attrib, children=[_("%(item_name)s does not exist. Create it?", item_name=item_name)])
        body = moin_page.body(children=(a, ))
        return moin_page.page(children=(body, ))

from . import default_registry
from MoinMoin.util.mime import Type, type_moin_document
default_registry.register(Converter._factory, Type(CONTENTTYPE_NONEXISTENT), type_moin_document)