# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - Action for exchanging the category of the page

    @copyright: 2012 MoinMoin:ReimarBauer
    @license: GNU GPL, see COPYING for details.
"""

from MoinMoin.Page import Page
from MoinMoin.PageEditor import PageEditor

def execute(pagename, request):
    if not request.user.may.read(pagename):
        msg = "You are not allowed to view this page."
        request.theme.add_msg(msg, "error")
        Page(request, pagename).send_page()
    else:
        text = Page(request, pagename).get_raw_body()
        '''
        ADD here the code to replace the category
        '''
        msg = "Changed category foo to bar."
        try:
            PageEditor(request, pagename).saveText(text, 0)
        except PageEditor.Unchanged:
            msg = "You did not change the page content, not saved!"
        request.theme.add_msg(msg, "info")
        Page(request, pagename).send_page()