#!/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 MainTemplate import MainTemplate

##################################################
## 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.875448
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:26 2008'
__CHEETAH_src__ = 'nav/web/templates/MaintenanceTemplate.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 MaintenanceTemplate(MainTemplate):

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


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

        MainTemplate.__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 makeMenu(self, menu, current=False, **KWS):



        ## CHEETAH: generated from #def $makeMenu($menu, $current = False) 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
        
        write('''<div style="border: 1px solid black; margin: 36px 0px 15px 0px; padding: 0px 19px;">
<div id="tabs" style="margin: -24px -10px;">
<ul>
''')
        for item in VFFSL(SL,"menu",True): # generated from line 35, col 1
            if VFFSL(SL,"item.link",True) == VFFSL(SL,"current",True): # generated from line 36, col 5
                write('''    <li id="current"><a>''')
                _v = VFFSL(SL,"item.text",True) # '$item.text' on line 37, col 25
                if _v is not None: write(_filter(_v, rawExpr='$item.text')) # from line 37, col 25.
                write('''</a></li>
''')
            elif VFFSL(SL,"item.admin",True): # generated from line 38, col 5
                write('''    <li class="admin"><a href="''')
                _v = VFFSL(SL,"item.link",True) # '$item.link' on line 39, col 32
                if _v is not None: write(_filter(_v, rawExpr='$item.link')) # from line 39, col 32.
                write('''">''')
                _v = VFFSL(SL,"item.text",True) # '$item.text' on line 39, col 44
                if _v is not None: write(_filter(_v, rawExpr='$item.text')) # from line 39, col 44.
                write('''</a></li>
''')
            else: # generated from line 40, col 5
                write('''    <li class="open"><a href="''')
                _v = VFFSL(SL,"item.link",True) # '$item.link' on line 41, col 31
                if _v is not None: write(_filter(_v, rawExpr='$item.link')) # from line 41, col 31.
                write('''">''')
                _v = VFFSL(SL,"item.text",True) # '$item.text' on line 41, col 43
                if _v is not None: write(_filter(_v, rawExpr='$item.text')) # from line 41, col 43.
                write('''</a></li>
''')
        write('''</ul>
</div>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def listComponents(self, components, edit=False, **KWS):



        ## CHEETAH: generated from #def $listComponents($components, $edit = False) at line 48, 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('''    <ul>
''')
        if not VFFSL(SL,"components",True): # generated from line 50, col 5
            write('''        <li>(none)</li>
''')
        compcounter = 0
        for component in VFFSL(SL,"components",True): # generated from line 54, col 5
            write('''        <li>
''')
            if VFFSL(SL,"edit",True): # generated from line 56, col 9
                write('''            <input type="hidden" name="component-''')
                _v = VFFSL(SL,"compcounter",True) # '$compcounter' on line 57, col 50
                if _v is not None: write(_filter(_v, rawExpr='$compcounter')) # from line 57, col 50.
                write('''" value="''')
                _v = VFFSL(SL,"component.key",True) # '$component.key' on line 57, col 71
                if _v is not None: write(_filter(_v, rawExpr='$component.key')) # from line 57, col 71.
                write(''',''')
                _v = VFFSL(SL,"component.value",True) # '$component.value' on line 57, col 86
                if _v is not None: write(_filter(_v, rawExpr='$component.value')) # from line 57, col 86.
                write('''" />
            <input type="checkbox" name="remove-''')
                _v = VFFSL(SL,"compcounter",True) # '$compcounter' on line 58, col 49
                if _v is not None: write(_filter(_v, rawExpr='$compcounter')) # from line 58, col 49.
                write('''" value="''')
                _v = VFFSL(SL,"component.key",True) # '$component.key' on line 58, col 70
                if _v is not None: write(_filter(_v, rawExpr='$component.key')) # from line 58, col 70.
                write(''',''')
                _v = VFFSL(SL,"component.value",True) # '$component.value' on line 58, col 85
                if _v is not None: write(_filter(_v, rawExpr='$component.value')) # from line 58, col 85.
                write('''" />
''')
                compcounter += 1
            if VFFSL(SL,"component.key",True) == 'netbox': # generated from line 61, col 9
                write('''            IP device:
''')
            else: # generated from line 63, col 9
                write('''            ''')
                _v = VFN(VFFSL(SL,"component.key",True),"capitalize",False)() # '$component.key.capitalize()' on line 64, col 13
                if _v is not None: write(_filter(_v, rawExpr='$component.key.capitalize()')) # from line 64, col 13.
                write(''':
''')
            if VFFSL(SL,"component.info",True) is None: # generated from line 66, col 9
                write('''            ID ''')
                _v = VFFSL(SL,"component.value",True) # '$component.value' on line 67, col 16
                if _v is not None: write(_filter(_v, rawExpr='$component.value')) # from line 67, col 16.
                write(''' (Details not available)
''')
            else: # generated from line 68, col 9
                if VFFSL(SL,"component.key",True) in ('location', 'room', 'netbox', 'service'): # generated from line 69, col 13
                    write('''            <a href="/report/room?locationid=''')
                    _v = VFFSL(SL,"component.info.locationid",True) # '$component.info.locationid' on line 70, col 46
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.locationid')) # from line 70, col 46.
                    write('''"
                title="''')
                    _v = VFFSL(SL,"component.info.locationdescr",True) # '$component.info.locationdescr' on line 71, col 24
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.locationdescr')) # from line 71, col 24.
                    write('''">
                ''')
                    _v = VFFSL(SL,"component.info.locationid",True) # '$component.info.locationid' on line 72, col 17
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.locationid')) # from line 72, col 17.
                    write('''</a>
''')
                if VFFSL(SL,"component.key",True) in ('room', 'netbox', 'service'): # generated from line 74, col 13
                    write('''            &rarr;
            <a href="/report/netbox?roomid=''')
                    _v = VFFSL(SL,"component.info.roomid",True) # '$component.info.roomid' on line 76, col 44
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.roomid')) # from line 76, col 44.
                    write('''"
                title="''')
                    _v = VFFSL(SL,"component.info.roomdescr",True) # '$component.info.roomdescr' on line 77, col 24
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.roomdescr')) # from line 77, col 24.
                    write('''">
                ''')
                    _v = VFFSL(SL,"component.info.roomid",True) # '$component.info.roomid' on line 78, col 17
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.roomid')) # from line 78, col 17.
                    write('''</a>
''')
                if VFFSL(SL,"component.key",True) in ('netbox', 'service'): # generated from line 80, col 13
                    write('''            &rarr;
            <a href="/browse/''')
                    _v = VFFSL(SL,"component.info.sysname",True) # '$component.info.sysname' on line 82, col 30
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.sysname')) # from line 82, col 30.
                    write('''"
                title="''')
                    _v = VFFSL(SL,"component.info.ip",True) # '$component.info.ip' on line 83, col 24
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.ip')) # from line 83, col 24.
                    write('''">
                ''')
                    _v = VFFSL(SL,"component.info.sysname",True) # '$component.info.sysname' on line 84, col 17
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.sysname')) # from line 84, col 17.
                    write('''</a>
''')
                if VFFSL(SL,"component.key",True) in ('service'): # generated from line 86, col 13
                    write('''            &rarr;
            ''')
                    _v = VFFSL(SL,"component.info.handler",True) # '$component.info.handler' on line 88, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$component.info.handler')) # from line 88, col 13.
                    write('''
''')
                if VFFSL(SL,"component.key",True) not in ('location', 'room', 'netbox', 'service'): # generated from line 90, col 13
                    write('''                ''')
                    _v = VFFSL(SL,"component.value",True) # '$component.value' on line 91, col 17
                    if _v is not None: write(_filter(_v, rawExpr='$component.value')) # from line 91, col 17.
                    write('''
                (Warning: Modules can no longer be a maintenance component.)
''')
            write('''        </li>
''')
        write('''    </ul>
''')
        if VFFSL(SL,"edit",True): # generated from line 98, col 5
            write('''    <input type="submit" name="submit_comp_remove" value="Remove selected components" />
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def tabcontent(self, **KWS):



        ## CHEETAH: generated from #block tabcontent at line 129, 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('''<p>Intentionally left blank.</p>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def content(self, **KWS):



        ## CHEETAH: generated from #block content at line 103, 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('''
''')
        _v = VFFSL(SL,"makeMenu",False)(VFFSL(SL,"menu",True), VFFSL(SL,"current",True)) # '$makeMenu($menu, $current)' on line 105, col 1
        if _v is not None: write(_filter(_v, rawExpr='$makeMenu($menu, $current)')) # from line 105, col 1.
        write('''

<h2>''')
        _v = VFFSL(SL,"title",True) # '$title' on line 107, col 5
        if _v is not None: write(_filter(_v, rawExpr='$title')) # from line 107, col 5.
        write('''</h2>

''')
        infomsgs = VFFSL(SL,"getVar",False)('infomsgs', [])
        if len(VFFSL(SL,"infomsgs",True)): # generated from line 110, col 1
            write('''<ul>
''')
            for infomsg in VFFSL(SL,"infomsgs",True): # generated from line 112, col 1
                write('''    <li>''')
                _v = VFFSL(SL,"infomsg",True) # '$infomsg' on line 113, col 9
                if _v is not None: write(_filter(_v, rawExpr='$infomsg')) # from line 113, col 9.
                write('''</li>
''')
            write('''</ul>
''')
        write('''
''')
        errors = VFFSL(SL,"getVar",False)('errors', [])
        if len(VFFSL(SL,"errors",True)): # generated from line 119, col 1
            write('''<p>The following errors occured:</p>

<ul>
''')
            for error in VFFSL(SL,"errors",True): # generated from line 123, col 1
                write('''    <li>''')
                _v = VFFSL(SL,"error",True) # '$error' on line 124, col 9
                if _v is not None: write(_filter(_v, rawExpr='$error')) # from line 124, col 9.
                write('''</li>
''')
            write('''</ul>
''')
        write('''
''')
        self.tabcontent(trans=trans)
        write('''
</div> <!-- tab area -->

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

    def additionalCSS(self, **KWS):



        ## CHEETAH: generated from #block additionalCSS at line 137, 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
        
        _v = VFFSL(SL,"default_tabs_CSS",True) # '$default_tabs_CSS' on line 138, col 1
        if _v is not None: write(_filter(_v, rawExpr='$default_tabs_CSS')) # from line 138, col 1.
        write('''
''')
        _v = VFFSL(SL,"default_table_CSS",True) # '$default_table_CSS' on line 139, col 1
        if _v is not None: write(_filter(_v, rawExpr='$default_table_CSS')) # from line 139, col 1.
        write('''
''')
        _v = VFFSL(SL,"default_calendar_CSS",True) # '$default_calendar_CSS' on line 140, col 1
        if _v is not None: write(_filter(_v, rawExpr='$default_calendar_CSS')) # from line 140, col 1.
        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('''

''')
        # attr $title = 'Maintenance'
        write('''


''')
        self.content(trans=trans)
        write('''
''')
        self.additionalCSS(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__

    path = [("Home", "/"), ("Maintenance Tasks", "")]

    _mainCheetahMethod_for_MaintenanceTemplate= 'writeBody'

## END CLASS DEFINITION

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


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


