#!/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 MessagesTemplate import MessagesTemplate
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__ = 1225031607.41184
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:27 2008'
__CHEETAH_src__ = 'nav/web/templates/MessagesListTemplate.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 MessagesListTemplate(MessagesTemplate):

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


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

        MessagesTemplate.__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,"msgs",True): # generated from line 34, col 1
            write('''<p>No messages found.</p>
''')
        else: # generated from line 36, col 1
            msgcount = 0
            for msg in VFFSL(SL,"msgs",True): # generated from line 38, col 5
                msgcount += 1
                if VFFSL(SL,"msgcount",True) <= VFFSL(SL,"verbosemsgs",True): # generated from line 40, col 9
                    write('''
<h3>''')
                    _v = VFN(VFN(VFFSL(SL,"msg.title",True),"replace",False)('<', '&lt;'),"replace",False)('>', '&gt;') # "$msg.title.replace('<', '&lt;').replace('>', '&gt;')" on line 42, col 5
                    if _v is not None: write(_filter(_v, rawExpr="$msg.title.replace('<', '&lt;').replace('>', '&gt;')")) # from line 42, col 5.
                    write('''</h3>

<table class="vertitable">
    <tr>
        <th>Published</th>
        <td>''')
                    _v = VFN(VFFSL(SL,"msg.publish_start",True),"strftime",False)('%Y-%m-%d %H:%M') # "$msg.publish_start.strftime('%Y-%m-%d %H:%M')" on line 47, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$msg.publish_start.strftime('%Y-%m-%d %H:%M')")) # from line 47, col 13.
                    write('''</td>
    </tr>
''')
                    if VFFSL(SL,"msg.last_changed",True): # generated from line 49, col 1
                        write('''    <tr>
        <th>Last changed</th>
        <td>''')
                        _v = VFN(VFFSL(SL,"msg.last_changed",True),"strftime",False)('%Y-%m-%d %H:%M') # "$msg.last_changed.strftime('%Y-%m-%d %H:%M')" on line 52, col 13
                        if _v is not None: write(_filter(_v, rawExpr="$msg.last_changed.strftime('%Y-%m-%d %H:%M')")) # from line 52, col 13.
                        write('''</td>
    </tr>
''')
                    write('''    <tr>
        <th>Author</th>
        <td>''')
                    _v = VFFSL(SL,"msg.author",True) # '$msg.author' on line 57, col 13
                    if _v is not None: write(_filter(_v, rawExpr='$msg.author')) # from line 57, col 13.
                    write('''</td>
    </tr>
    <tr>
        <th>Description</th>
        <td>''')
                    _v = VFN(VFN(VFN(VFN(VFFSL(SL,"msg.description",True),"replace",False)('<', '&lt;'),"replace",False)('>', '&gt;'),"replace",False)('\n', '<br />'),"replace",False)('  ', '&nbsp;&nbsp;') # "$msg.description.replace('<', '&lt;').replace('>', '&gt;').replace('\\n', '<br />').replace('  ', '&nbsp;&nbsp;')" on line 61, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$msg.description.replace('<', '&lt;').replace('>', '&gt;').replace('\\n', '<br />').replace('  ', '&nbsp;&nbsp;')")) # from line 61, col 13.
                    write('''</td>
    </tr>
''')
                    if VFFSL(SL,"authorized",True): # generated from line 63, col 1
                        if VFFSL(SL,"msg.tech_description",True): # generated from line 64, col 5
                            write('''    <tr>
        <th>Technical description</th>
        <td>''')
                            _v = VFN(VFN(VFN(VFN(VFFSL(SL,"msg.tech_description",True),"replace",False)('<', '&lt;'),"replace",False)('>', '&gt;'),"replace",False)('\n', '<br />'),"replace",False)('  ', '&nbsp;&nbsp;') # "$msg.tech_description.replace('<', '&lt;').replace('>', '&gt;').replace('\\n', '<br />').replace('  ', '&nbsp;&nbsp;')" on line 67, col 13
                            if _v is not None: write(_filter(_v, rawExpr="$msg.tech_description.replace('<', '&lt;').replace('>', '&gt;').replace('\\n', '<br />').replace('  ', '&nbsp;&nbsp;')")) # from line 67, col 13.
                            write('''</td>
    </tr>
''')
                    if type(VFFSL(SL,"msg.tasks",True)) is list: # generated from line 71, col 5
                        write('''    <tr>
        <th>Related maintenance tasks</th>
        <td><ul>
''')
                        for task in VFFSL(SL,"msg.tasks",True): # generated from line 75, col 9
                            write('''            <li><a href="/maintenance/view?id=''')
                            _v = VFFSL(SL,"task.maint_taskid",True) # '$task.maint_taskid' on line 76, col 47
                            if _v is not None: write(_filter(_v, rawExpr='$task.maint_taskid')) # from line 76, col 47.
                            write('''">''')
                            _v = VFFSL(SL,"task.description",True) # '$task.description' on line 76, col 67
                            if _v is not None: write(_filter(_v, rawExpr='$task.description')) # from line 76, col 67.
                            write('''</a>,
            from ''')
                            _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 77, col 18
                            if _v is not None: write(_filter(_v, rawExpr="$task.maint_start.strftime('%Y-%m-%d %H:%M')")) # from line 77, col 18.
                            write('''
            to ''')
                            _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 78, col 16
                            if _v is not None: write(_filter(_v, rawExpr="$task.maint_end.strftime('%Y-%m-%d %H:%M')")) # from line 78, col 16.
                            write(''',
            current state is <em>''')
                            _v = VFFSL(SL,"task.state",True) # '$task.state' on line 79, col 34
                            if _v is not None: write(_filter(_v, rawExpr='$task.state')) # from line 79, col 34.
                            write('''</em></li>
''')
                        write('''        </ul></td>
    </tr>
''')
                    if VFFSL(SL,"authorized",True): # generated from line 84, col 1
                        if VFFSL(SL,"msg.publish_end",True): # generated from line 85, col 5
                            write('''    <tr>
''')
                            if VFFSL(SL,"msg.publish_end",True) > mx.DateTime.now(): # generated from line 87, col 9
                                write('''        <th>Expires</th>
''')
                            else: # generated from line 89, col 9
                                write('''        <th>Expired</th>
''')
                            write('''        <td>''')
                            _v = VFN(VFFSL(SL,"msg.publish_end",True),"strftime",False)('%Y-%m-%d %H:%M') # "$msg.publish_end.strftime('%Y-%m-%d %H:%M')" on line 92, col 13
                            if _v is not None: write(_filter(_v, rawExpr="$msg.publish_end.strftime('%Y-%m-%d %H:%M')")) # from line 92, col 13.
                            write(''' 
''')
                            if VFFSL(SL,"msg.publish_end",True) > mx.DateTime.now(): # generated from line 93, col 9
                                write('''            | <a href="expire?id=''')
                                _v = VFFSL(SL,"msg.messageid",True) # '$msg.messageid' on line 94, col 34
                                if _v is not None: write(_filter(_v, rawExpr='$msg.messageid')) # from line 94, col 34.
                                write('''">Expire now</a>
''')
                            write('''        </td>
    </tr>
''')
                        if VFFSL(SL,"msg.replaces_message",True): # generated from line 99, col 5
                            write('''    <tr>
        <th>Replaces message</th>
        <td>
            <a href="view?id=''')
                            _v = VFFSL(SL,"msg.replaces_message",True) # '$msg.replaces_message' on line 103, col 30
                            if _v is not None: write(_filter(_v, rawExpr='$msg.replaces_message')) # from line 103, col 30.
                            write('''">''')
                            _v = VFFSL(SL,"msg.replaces_message_title",True) # '$msg.replaces_message_title' on line 103, col 53
                            if _v is not None: write(_filter(_v, rawExpr='$msg.replaces_message_title')) # from line 103, col 53.
                            write('''</a>
            from ''')
                            _v = VFN(VFFSL(SL,"msg.replaces_message_publish_start",True),"strftime",False)('%Y-%m-%d %H:%M') # "$msg.replaces_message_publish_start.strftime('%Y-%m-%d %H:%M')" on line 104, col 18
                            if _v is not None: write(_filter(_v, rawExpr="$msg.replaces_message_publish_start.strftime('%Y-%m-%d %H:%M')")) # from line 104, col 18.
                            write('''
            by ''')
                            _v = VFFSL(SL,"msg.replaces_message_author",True) # '$msg.replaces_message_author' on line 105, col 16
                            if _v is not None: write(_filter(_v, rawExpr='$msg.replaces_message_author')) # from line 105, col 16.
                            write('''
        </td>
    </tr>
''')
                        if VFFSL(SL,"msg.replaced_by",True): # generated from line 109, col 5
                            write('''    <tr>
        <th>Replaced by</th>
        <td>
            <a href="view?id=''')
                            _v = VFFSL(SL,"msg.replaced_by",True) # '$msg.replaced_by' on line 113, col 30
                            if _v is not None: write(_filter(_v, rawExpr='$msg.replaced_by')) # from line 113, col 30.
                            write('''">''')
                            _v = VFFSL(SL,"msg.replaced_by_title",True) # '$msg.replaced_by_title' on line 113, col 48
                            if _v is not None: write(_filter(_v, rawExpr='$msg.replaced_by_title')) # from line 113, col 48.
                            write('''</a>
            from ''')
                            _v = VFN(VFFSL(SL,"msg.replaced_by_publish_start",True),"strftime",False)('%Y-%m-%d %H:%M') # "$msg.replaced_by_publish_start.strftime('%Y-%m-%d %H:%M')" on line 114, col 18
                            if _v is not None: write(_filter(_v, rawExpr="$msg.replaced_by_publish_start.strftime('%Y-%m-%d %H:%M')")) # from line 114, col 18.
                            write('''
            by ''')
                            _v = VFFSL(SL,"msg.replaced_by_author",True) # '$msg.replaced_by_author' on line 115, col 16
                            if _v is not None: write(_filter(_v, rawExpr='$msg.replaced_by_author')) # from line 115, col 16.
                            write('''
        </td>
    </tr>
''')
                        write('''    <tr>
        <th>Actions</th>
        <td><a href="edit?id=''')
                        _v = VFFSL(SL,"msg.messageid",True) # '$msg.messageid' on line 121, col 30
                        if _v is not None: write(_filter(_v, rawExpr='$msg.messageid')) # from line 121, col 30.
                        write('''">Edit</a>
            | <a href="followup?id=''')
                        _v = VFFSL(SL,"msg.messageid",True) # '$msg.messageid' on line 122, col 36
                        if _v is not None: write(_filter(_v, rawExpr='$msg.messageid')) # from line 122, col 36.
                        write('''">Followup</a>
''')
                        if not VFFSL(SL,"msg.publish_end",True): # generated from line 123, col 5
                            write('''            | <a href="expire?id=''')
                            _v = VFFSL(SL,"msg.messageid",True) # '$msg.messageid' on line 124, col 34
                            if _v is not None: write(_filter(_v, rawExpr='$msg.messageid')) # from line 124, col 34.
                            write('''">Expire now</a>
''')
                        write('''        </td>
    </tr>
''')
                    write('''</table>

''')
                else: # generated from line 131, col 9
                    write('''
''')
                    if VFFSL(SL,"msgcount",True) == VFFSL(SL,"verbosemsgs",True)+1: # generated from line 133, col 9
                        write('''<h3>Older Messages</h3>

<table class="vertilist">
    <tr>
        <th>Published</th>
        <th>Title</th>
        <th>Description</th>
    </tr>
''')
                    write('''
''')
                    if len(VFFSL(SL,"msg.description",True)) > 80: # generated from line 144, col 9
                        desc = VFN(VFFSL(SL,"msg",True),"description",True)[:80] + '...'
                    else: # generated from line 146, col 9
                        desc = VFFSL(SL,"msg.description",True)
                    write('''    <tr>
        <td>''')
                    _v = VFN(VFFSL(SL,"msg.publish_start",True),"strftime",False)('%Y-%m-%d %H:%M') # "$msg.publish_start.strftime('%Y-%m-%d %H:%M')" on line 150, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$msg.publish_start.strftime('%Y-%m-%d %H:%M')")) # from line 150, col 13.
                    write('''</td>
        <td><a href="view?id=''')
                    _v = VFFSL(SL,"msg.messageid",True) # '$msg.messageid' on line 151, col 30
                    if _v is not None: write(_filter(_v, rawExpr='$msg.messageid')) # from line 151, col 30.
                    write('''">''')
                    _v = VFN(VFN(VFFSL(SL,"msg.title",True),"replace",False)('<', '&lt;'),"replace",False)('>', '&gt;') # "$msg.title.replace('<', '&lt;').replace('>', '&gt;')" on line 151, col 46
                    if _v is not None: write(_filter(_v, rawExpr="$msg.title.replace('<', '&lt;').replace('>', '&gt;')")) # from line 151, col 46.
                    write('''</a></td>
        <td>''')
                    _v = VFN(VFN(VFFSL(SL,"desc",True),"replace",False)('<', '&lt;'),"replace",False)('>', '&gt;') # "$desc.replace('<', '&lt;').replace('>', '&gt;')" on line 152, col 13
                    if _v is not None: write(_filter(_v, rawExpr="$desc.replace('<', '&lt;').replace('>', '&gt;')")) # from line 152, col 13.
                    write('''</td>
    </tr>
''')
            write('''
''')
            #  End of 'Older Messages' table
            if VFFSL(SL,"msgcount",True) > VFFSL(SL,"verbosemsgs",True): # generated from line 158, 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('''

''')
        #  $verbosemsgs may be adjusted 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__

    verbosemsgs = 5

    _mainCheetahMethod_for_MessagesListTemplate= 'writeBody'

## END CLASS DEFINITION

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


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


