#!/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 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__ = 1225031606.24547
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:26 2008'
__CHEETAH_src__ = 'nav/web/templates/MaintenanceListTemplate.tmpl'
__CHEETAH_srcLastModified__ = 'Thu Feb  1 09:57:42 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 MaintenanceListTemplate(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 32, 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
        
        write('''
''')
        if not VFFSL(SL,"tasks",True): # generated from line 34, col 1
            write('''<p>No maintenance tasks found.</p>
''')
        else: # generated from line 36, col 1
            taskcount = 0
            for task in VFFSL(SL,"tasks",True): # generated from line 38, col 5
                taskcount += 1
                if VFFSL(SL,"taskcount",True) <= VFFSL(SL,"verbosetasks",True): # generated from line 40, col 9
                    write('''
<h3>''')
                    _v = VFN(VFFSL(SL,"task",True),"description",True)[:50] # '$task.description[:50]' on line 42, col 5
                    if _v is not None: write(_filter(_v, rawExpr='$task.description[:50]')) # from line 42, col 5.
                    write('''</h3>

<table class="vertitable">
    <tr>
        <th>Start</th>
        <td>''')
                    _v = VFN(VFFSL(SL,"task.maint_start",True),"strftime",False)('%Y-%m-%d %H:%M') # "$task.maint_start.strftime('%Y-%m-%d %H:%M')" on line 47, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$task.maint_start.strftime('%Y-%m-%d %H:%M')")) # from line 47, col 13.
                    write('''</td>
    </tr>
    <tr>
        <th>End</th>
        <td>''')
                    _v = VFN(VFFSL(SL,"task.maint_end",True),"strftime",False)('%Y-%m-%d %H:%M') # "$task.maint_end.strftime('%Y-%m-%d %H:%M')" on line 51, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$task.maint_end.strftime('%Y-%m-%d %H:%M')")) # from line 51, col 13.
                    write('''</td>
    </tr>
    <tr>
        <th>Description</th>
        <td>''')
                    _v = VFFSL(SL,"task.description",True) # '$task.description' on line 55, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$task.description')) # from line 55, col 13.
                    write('''</td>
    </tr>
    <tr>
        <th>Components</th>
        <td>''')
                    _v = VFFSL(SL,"listComponents",False)(VFFSL(SL,"task.components",True)) # '$listComponents($task.components)' on line 59, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$listComponents($task.components)')) # from line 59, col 13.
                    write('''</td>
    </tr>
    <tr>
        <th>Author</th>
        <td>''')
                    _v = VFFSL(SL,"task.author",True) # '$task.author' on line 63, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$task.author')) # from line 63, col 13.
                    write('''</td>
    </tr>
''')
                    if VFFSL(SL,"authorized",True): # generated from line 65, col 1
                        write('''    <tr>
        <th>State</th>
        <td>''')
                        _v = VFN(VFFSL(SL,"task.state",True),"capitalize",False)() # '$task.state.capitalize()' on line 68, col 13
                        if _v is not None: write(_filter(_v, rawExpr='$task.state.capitalize()')) # from line 68, col 13.
                        write('''</td>
    </tr>
    <tr>
        <th>Actions</th>
        <td><a href="edit?id=''')
                        _v = VFFSL(SL,"task.maint_taskid",True) # '$task.maint_taskid' on line 72, col 30
                        if _v is not None: write(_filter(_v, rawExpr='$task.maint_taskid')) # from line 72, col 30.
                        write('''">Edit</a>
''')
                        if not VFFSL(SL,"task.state",True) == 'cancelled': # generated from line 73, col 5
                            write('''            | <a href="cancel?id=''')
                            _v = VFFSL(SL,"task.maint_taskid",True) # '$task.maint_taskid' on line 74, col 34
                            if _v is not None: write(_filter(_v, rawExpr='$task.maint_taskid')) # from line 74, col 34.
                            write('''">Cancel now</a>
''')
                        write('''        </td>
    </tr>
''')
                    write('''</table>

''')
                else: # generated from line 81, col 9
                    write('''        
''')
                    if VFFSL(SL,"taskcount",True) == VFFSL(SL,"verbosetasks",True)+1: # generated from line 83, col 9
                        write('''<h3>Older Maintenance Tasks</h3>

<table class="vertilist">
    <tr>
        <th>Start</th>
        <th>End</th>
        <th>Description</th>
        <th>Components</th>
        <th>Author</th>
        <th>State</th>
    </tr>
''')
                    write('''
''')
                    if len(VFFSL(SL,"task.description",True)) > 50: # generated from line 97, col 9
                        desc = VFN(VFFSL(SL,"task",True),"description",True)[:50] + '...'
                    else: # generated from line 99, col 9
                        desc = VFFSL(SL,"task.description",True)
                    if type(VFFSL(SL,"task.components",True)) is list: # generated from line 102, col 9
                        comp = len(VFFSL(SL,"task.components",True))
                    else: # generated from line 104, col 9
                        comp = 0
                    write('''    <tr>
        <td>''')
                    _v = VFN(VFFSL(SL,"task.maint_start",True),"strftime",False)('%Y-%m-%d %H:%M') # "$task.maint_start.strftime('%Y-%m-%d %H:%M')" on line 108, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$task.maint_start.strftime('%Y-%m-%d %H:%M')")) # from line 108, col 13.
                    write('''</td>
        <td>''')
                    _v = VFN(VFFSL(SL,"task.maint_end",True),"strftime",False)('%Y-%m-%d %H:%M') # "$task.maint_end.strftime('%Y-%m-%d %H:%M')" on line 109, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$task.maint_end.strftime('%Y-%m-%d %H:%M')")) # from line 109, col 13.
                    write('''</td>
        <td><a href="view?id=''')
                    _v = VFFSL(SL,"task.maint_taskid",True) # '$task.maint_taskid' on line 110, col 30
                    if _v is not None: write(_filter(_v, rawExpr='$task.maint_taskid')) # from line 110, col 30.
                    write('''">''')
                    _v = VFFSL(SL,"desc",True) # '$desc' on line 110, col 50
                    if _v is not None: write(_filter(_v, rawExpr='$desc')) # from line 110, col 50.
                    write('''</a></td>
        <td><a href="view?id=''')
                    _v = VFFSL(SL,"task.maint_taskid",True) # '$task.maint_taskid' on line 111, col 30
                    if _v is not None: write(_filter(_v, rawExpr='$task.maint_taskid')) # from line 111, col 30.
                    write('''">''')
                    _v = VFFSL(SL,"comp",True) # '$comp' on line 111, col 50
                    if _v is not None: write(_filter(_v, rawExpr='$comp')) # from line 111, col 50.
                    write('''</a></td>
        <td>''')
                    _v = VFFSL(SL,"task.author",True) # '$task.author' on line 112, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$task.author')) # from line 112, col 13.
                    write('''</td>
        <td>''')
                    _v = VFFSL(SL,"task.state",True) # '$task.state' on line 113, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$task.state')) # from line 113, col 13.
                    write('''</td>
    </tr>
''')
            write('''
''')
            #  End of 'Older Maintenace Tasks' table
            if VFFSL(SL,"taskcount",True) > VFFSL(SL,"verbosetasks",True): # generated from line 119, col 1
                write('''</table>
''')
            write('''
''')
        write('''
''')
        
        ########################################
        ## 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('''

''')
        #  $verbosetasks may be adjusted to according to preference
        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__

    verbosetasks = 5

    _mainCheetahMethod_for_MaintenanceListTemplate= 'writeBody'

## END CLASS DEFINITION

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


# 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=MaintenanceListTemplate()).run()


