#!/usr/bin/env python
# -*- coding: UTF-8 -*-



##################################################
## DEPENDENCIES
import sys
import os
import os.path
from os.path import getmtime, exists
import time
import types
import __builtin__
from Cheetah.Version import MinCompatibleVersion as RequiredCheetahVersion
from Cheetah.Version import MinCompatibleVersionTuple as RequiredCheetahVersionTuple
from Cheetah.Template import Template
from Cheetah.DummyTransaction import DummyTransaction
from Cheetah.NameMapper import NotFound, valueForName, valueFromSearchList, valueFromFrameOrSearchList
from Cheetah.CacheRegion import CacheRegion
import Cheetah.Filters as Filters
import Cheetah.ErrorCatchers as ErrorCatchers
from MaintenanceTemplate import MaintenanceTemplate
import calendar
import time
import mx.DateTime

##################################################
## MODULE CONSTANTS
try:
    True, False
except NameError:
    True, False = (1==1), (1==0)
VFFSL=valueFromFrameOrSearchList
VFSL=valueFromSearchList
VFN=valueForName
currentTime=time.time
__CHEETAH_version__ = '2.0.1'
__CHEETAH_versionTuple__ = (2, 0, 1, 'final', 0)
__CHEETAH_genTime__ = 1225031605.598937
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:25 2008'
__CHEETAH_src__ = 'nav/web/templates/MaintenanceCalTemplate.tmpl'
__CHEETAH_srcLastModified__ = 'Fri Jan 19 14:16:23 2007'
__CHEETAH_docstring__ = 'Autogenerated by CHEETAH: The Python-Powered Template Engine'

if __CHEETAH_versionTuple__ < RequiredCheetahVersionTuple:
    raise AssertionError(
      'This template was compiled with Cheetah version'
      ' %s. Templates compiled before version %s must be recompiled.'%(
         __CHEETAH_version__, RequiredCheetahVersion))

##################################################
## CLASSES

class MaintenanceCalTemplate(MaintenanceTemplate):

    ##################################################
    ## CHEETAH GENERATED METHODS


    def __init__(self, *args, **KWs):

        MaintenanceTemplate.__init__(self, *args, **KWs)
        if not self._CHEETAH__instanceInitialized:
            cheetahKWArgs = {}
            allowedKWs = 'searchList namespaces filter filtersLib errorCatcher'.split()
            for k,v in KWs.items():
                if k in allowedKWs: cheetahKWArgs[k] = v
            self._initCheetahInstance(**cheetahKWArgs)
        

    def tabcontent(self, **KWS):



        ## CHEETAH: generated from #block tabcontent at line 31, col 1.
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        cal = calendar.monthcalendar(int(VFFSL(SL,"year",True)), int(VFFSL(SL,"month",True)))
        today = time.strftime('%Y-%m-%d')
        write('''
<table class="calendar">
    <caption>
''')
        thismonth = time.strptime('%04d-%02d-01' % (VFFSL(SL,"year",True), VFFSL(SL,"month",True)), '%Y-%m-%d')
        prevmonth = time.gmtime(time.mktime(VFFSL(SL,"thismonth",True)) - 28*24*60*60)
        prevmonthy = int(time.strftime('%Y', VFFSL(SL,"prevmonth",True)))
        prevmonthm = int(time.strftime('%m', VFFSL(SL,"prevmonth",True)))
        write('''        <a href="?y=''')
        _v = VFFSL(SL,"prevmonthy",True) # '$prevmonthy' on line 41, col 21
        if _v is not None: write(_filter(_v, rawExpr='$prevmonthy')) # from line 41, col 21.
        write('''&amp;m=''')
        _v = VFFSL(SL,"prevmonthm",True) # '$prevmonthm' on line 41, col 39
        if _v is not None: write(_filter(_v, rawExpr='$prevmonthm')) # from line 41, col 39.
        write('''">&lt;&lt;</a>
''')
        monthname = time.strftime('%B %Y', VFFSL(SL,"thismonth",True))
        write('''        ''')
        _v = VFFSL(SL,"monthname",True) # '$monthname' on line 43, col 9
        if _v is not None: write(_filter(_v, rawExpr='$monthname')) # from line 43, col 9.
        write('''
''')
        nextmonth = time.gmtime(time.mktime(VFFSL(SL,"thismonth",True)) + 32*24*60*60)
        nextmonthy = int(time.strftime('%Y', VFFSL(SL,"nextmonth",True)))
        nextmonthm = int(time.strftime('%m', VFFSL(SL,"nextmonth",True)))
        write('''        <a href="?y=''')
        _v = VFFSL(SL,"nextmonthy",True) # '$nextmonthy' on line 47, col 21
        if _v is not None: write(_filter(_v, rawExpr='$nextmonthy')) # from line 47, col 21.
        write('''&amp;m=''')
        _v = VFFSL(SL,"nextmonthm",True) # '$nextmonthm' on line 47, col 39
        if _v is not None: write(_filter(_v, rawExpr='$nextmonthm')) # from line 47, col 39.
        write('''">&gt;&gt;</a>
    </caption>
    <tr>
''')
        for day in calendar.weekheader(9).split(' '): # generated from line 50, col 1
            if len(VFFSL(SL,"day",True)) > 0: # generated from line 51, col 5
                write('''        <th>''')
                _v = VFFSL(SL,"day",True) # '$day' on line 52, col 13
                if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 52, col 13.
                write('''</th>
''')
        write('''    </tr>
''')
        for week in VFFSL(SL,"cal",True): # generated from line 56, col 1
            write('''    <tr>
''')
            for day in VFFSL(SL,"week",True): # generated from line 58, col 5
                if VFFSL(SL,"day",True) == 0: # generated from line 59, col 9
                    write('''        <td>&nbsp;</td>
''')
                else: # generated from line 61, col 9
                    date = '%04d-%02d-%02d' % (VFFSL(SL,"year",True), VFFSL(SL,"month",True), VFFSL(SL,"day",True))
                    write('''        <td>
''')
                    if VFFSL(SL,"date",True) == VFFSL(SL,"today",True): # generated from line 64, col 13
                        todays = 'Today - '
                        write('''            <div class="dayheader" style="background: #beb;">
''')
                    else: # generated from line 67, col 13
                        todays = ''
                        write('''            <div class="dayheader">
''')
                    if calendar.weekday(VFFSL(SL,"year",True), VFFSL(SL,"month",True), VFFSL(SL,"day",True)) == 5: # generated from line 71, col 13
                        write('''                <span style="color: gray;">
''')
                    elif calendar.weekday(VFFSL(SL,"year",True), VFFSL(SL,"month",True), VFFSL(SL,"day",True)) == 6: # generated from line 73, col 13
                        write('''                <span style="color: red;">
''')
                    else: # generated from line 75, col 13
                        write('''                <span>
''')
                    write('''                <strong>''')
                    _v = VFFSL(SL,"todays",True) # '$todays' on line 78, col 25
                    if _v is not None: write(_filter(_v, rawExpr='$todays')) # from line 78, col 25.
                    _v = VFFSL(SL,"day",True) # '$day' on line 78, col 32
                    if _v is not None: write(_filter(_v, rawExpr='$day')) # from line 78, col 32.
                    write('''</strong>
            </span></div>
''')
                    if VFN(VFFSL(SL,"tasks",True),"has_key",False)(VFFSL(SL,"date",True)): # generated from line 80, col 13
                        for task in VFFSL(SL,"tasks",True)[VFFSL(SL,"date",True)]: # generated from line 81, col 17
                            write('''            <strong>''')
                            _v = VFN(VFFSL(SL,"task.maint_start",True),"strftime",False)('%H:%M') # "$task.maint_start.strftime('%H:%M')" on line 82, col 21
                            if _v is not None: write(_filter(_v, rawExpr="$task.maint_start.strftime('%H:%M')")) # from line 82, col 21.
                            write(''':</strong>
            <a href="view?id=''')
                            _v = VFFSL(SL,"task.maint_taskid",True) # '$task.maint_taskid' on line 83, col 30
                            if _v is not None: write(_filter(_v, rawExpr='$task.maint_taskid')) # from line 83, col 30.
                            write('''" title="''')
                            _v = VFFSL(SL,"task.description",True) # '$task.description' on line 83, col 57
                            if _v is not None: write(_filter(_v, rawExpr='$task.description')) # from line 83, col 57.
                            write('''">
''')
                            if len(VFFSL(SL,"task.description",True)) > 16: # generated from line 84, col 21
                                write('''            ''')
                                _v = VFN(VFFSL(SL,"task",True),"description",True)[:16] # '$task.description[:16]' on line 85, col 13
                                if _v is not None: write(_filter(_v, rawExpr='$task.description[:16]')) # from line 85, col 13.
                                write('''...</a>
''')
                            else: # generated from line 86, col 21
                                write('''            ''')
                                _v = VFFSL(SL,"task.description",True) # '$task.description' on line 87, col 13
                                if _v is not None: write(_filter(_v, rawExpr='$task.description')) # from line 87, col 13.
                                write('''</a>
''')
                            if int(VFN(VFFSL(SL,"task.interval",True),"strftime",False)('%d')) > 0: # generated from line 89, col 21
                                interval = int(VFN(VFFSL(SL,"task.interval",True),"strftime",False)('%d'))
                                write('''            (''')
                                _v = VFFSL(SL,"interval",True) # '$(interval)' on line 91, col 14
                                if _v is not None: write(_filter(_v, rawExpr='$(interval)')) # from line 91, col 14.
                                write('''d)
''')
                            else: # generated from line 92, col 21
                                interval = int(VFN(VFFSL(SL,"task.interval",True),"strftime",False)('%H'))
                                write('''            (''')
                                _v = VFFSL(SL,"interval",True) # '$(interval)' on line 94, col 14
                                if _v is not None: write(_filter(_v, rawExpr='$(interval)')) # from line 94, col 14.
                                write('''h)
''')
                            write('''            <br />
''')
                    else: # generated from line 98, col 13
                        write('''            &nbsp;
''')
                    write('''        </td>
''')
            write('''    </tr>
''')
        write('''</table>

''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def writeBody(self, **KWS):



        ## CHEETAH: main method generated for this template
        trans = KWS.get("trans")
        if (not trans and not self._CHEETAH__isBuffering and not callable(self.transaction)):
            trans = self.transaction # is None unless self.awake() was called
        if not trans:
            trans = DummyTransaction()
            _dummyTrans = True
        else: _dummyTrans = False
        write = trans.response().write
        SL = self._CHEETAH__searchList
        _filter = self._CHEETAH__currentFilter
        
        ########################################
        ## START - generated method body
        
        #  $Id:$
        # 
        #  Copyright 2006 UNINETT AS
        # 
        #  This file is part of Network Administration Visualized (NAV)
        # 
        #  NAV is free software; you can redistribute it and/or modify
        #  it under the terms of the GNU General Public License as published by
        #  the Free Software Foundation; either version 2 of the License, or
        #  (at your option) any later version.
        # 
        #  NAV is distributed in the hope that it will be useful,
        #  but WITHOUT ANY WARRANTY; without even the implied warranty of
        #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        #  GNU General Public License for more details.
        # 
        #  You should have received a copy of the GNU General Public License
        #  along with NAV; if not, write to the Free Software
        #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        # 
        # 
        #  Author: Stein Magnus Jodal <stein.magnus.jodal@uninett.no>
        # 
        write('''

''')
        self.tabcontent(trans=trans)
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        
    ##################################################
    ## CHEETAH GENERATED ATTRIBUTES


    _CHEETAH__instanceInitialized = False

    _CHEETAH_version = __CHEETAH_version__

    _CHEETAH_versionTuple = __CHEETAH_versionTuple__

    _CHEETAH_genTime = __CHEETAH_genTime__

    _CHEETAH_genTimestamp = __CHEETAH_genTimestamp__

    _CHEETAH_src = __CHEETAH_src__

    _CHEETAH_srcLastModified = __CHEETAH_srcLastModified__

    _mainCheetahMethod_for_MaintenanceCalTemplate= 'writeBody'

## END CLASS DEFINITION

if not hasattr(MaintenanceCalTemplate, '_initCheetahAttributes'):
    templateAPIClass = getattr(MaintenanceCalTemplate, '_CHEETAH_templateClass', Template)
    templateAPIClass._addCheetahPlumbingCodeToClass(MaintenanceCalTemplate)


# CHEETAH was developed by Tavis Rudd and Mike Orr
# with code, advice and input from many other volunteers.
# For more information visit http://www.CheetahTemplate.org/

##################################################
## if run from command line:
if __name__ == '__main__':
    from Cheetah.TemplateCmdLineIface import CmdLineIface
    CmdLineIface(templateObj=MaintenanceCalTemplate()).run()


