# -*- coding: iso-8859-1 -*-
"""
    MoinMoin - NewMonthCalendarEntry macro

    Thanks to Jos Yule's "blogpost" action and his modified Form for
    giving me the pieces I needed to figure all this stuff out: MoinMoin:JosYule

    @copyright: 2004 Vito Miliano (vito_moinnewpagewithtemplate@perilith.com),
                2004 by Nir Soffer <nirs@freeshell.org>,
                2004 Alexander Schremmer <alex AT alexanderweb DOT de>,
                2006-2008 MoinMoin:ReimarBauer
                2008 MoinMoin:RadomirDopieralski
    @license: GNU GPL, see COPYING for details.
"""

from MoinMoin import wikiutil
from MoinMoin.macro.NewPage import NewPage
import time

Dependencies = ["language"]

class NewMonthCalendarEntry(NewPage):
    def __init__(self, macro, template=u'', button_label=u'',
                 parent_page=u''):
        
        request = macro.request
        currentyear, currentmonth, currentday, h, m, s, wd, yd, ds = request.user.getTime(time.time()) 
        name_template = u'%4d-%02d-%02d' % (currentyear, currentmonth, currentday)
        NewPage.__init__(self,macro, template, button_label, parent_page, name_template)


def macro_NewMonthCalendarEntry(macro, template=u'', button_label=u'',
                  parent_page=u''):
    """ Temporary glue code to use with moin current macro system """

    # hide if user cannot use it
    request = macro.request
    if not request.user.may.write(request.page.page_name):
        return ''

    return NewMonthCalendarEntry(macro, template, button_label, parent_page).renderInPage()

