#!/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
import 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__ = 1225031608.462832
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:28 2008'
__CHEETAH_src__ = 'nav/web/templates/MySMSTemplate.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 MySMSTemplate(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 add_message(self, message, **KWS):



        ## CHEETAH: generated from #def add_message($message) at line 33, 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('''\t<tr class="''')
        _v = VFFSL(SL,"rowcycler",True) # '$rowcycler' on line 34, col 13
        if _v is not None: write(_filter(_v, rawExpr='$rowcycler')) # from line 34, col 13.
        write('''">
\t\t<td>''')
        _v = VFN(VFFSL(SL,"message",True)['time'],"strftime",False)('%Y-%m-%d %H:%M:%S') # "$message['time'].strftime('%Y-%m-%d %H:%M:%S')" on line 35, col 7
        if _v is not None: write(_filter(_v, rawExpr="$message['time'].strftime('%Y-%m-%d %H:%M:%S')")) # from line 35, col 7.
        write('''</td>
''')
        if VFFSL(SL,"message",True)['timesent']: # generated from line 36, col 2
            write('''\t\t<td>''')
            _v = VFN(VFFSL(SL,"message",True)['timesent'],"strftime",False)('%Y-%m-%d %H:%M:%S') # "$message['timesent'].strftime('%Y-%m-%d %H:%M:%S')" on line 37, col 7
            if _v is not None: write(_filter(_v, rawExpr="$message['timesent'].strftime('%Y-%m-%d %H:%M:%S')")) # from line 37, col 7.
            write('''</td>
''')
        else: # generated from line 38, col 2
            write('''\t\t<td></td>
''')
        write('''\t\t<td>''')
        _v = VFFSL(SL,"message",True)['phone'] # "$message['phone']" on line 41, col 7
        if _v is not None: write(_filter(_v, rawExpr="$message['phone']")) # from line 41, col 7.
        write('''</td>
\t\t<td>''')
        _v = VFFSL(SL,"message",True)['msg'] # "$message['msg']" on line 42, col 7
        if _v is not None: write(_filter(_v, rawExpr="$message['msg']")) # from line 42, col 7.
        write('''</td>
\t\t<td>''')
        _v = VFFSL(SL,"message",True)['severity'] # "$message['severity']" on line 43, col 7
        if _v is not None: write(_filter(_v, rawExpr="$message['severity']")) # from line 43, col 7.
        write('''</td>
''')
        if VFFSL(SL,"message",True)['sent'] == 'Y': # generated from line 44, col 2
            write('''\t\t<td style="color: green">Sent</td>
''')
        elif VFFSL(SL,"message",True)['sent'] == 'N': # generated from line 46, col 2
            write('''\t\t<td style="color: red">Not sent</td>
''')
        elif VFFSL(SL,"message",True)['sent'] == 'I': # generated from line 48, col 2
            write('''\t\t<td style="color: gray">Ignored</td>
''')
        write('''\t</tr>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def content(self, **KWS):



        ## CHEETAH: generated from #block content at line 54, 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('''
<h2>My SMS</h2>

<form id="searchform" action="" method="get"><p>
\tShow messages from the last
\t<input type="text" name="days" size="3" value="''')
        _v = VFFSL(SL,"days",True) # '$days' on line 60, col 49
        if _v is not None: write(_filter(_v, rawExpr='$days')) # from line 60, col 49.
        write('''" />
\tdays for the phone numbers: ''')
        _v = VFFSL(SL,"phones",True) # '$phones' on line 61, col 30
        if _v is not None: write(_filter(_v, rawExpr='$phones')) # from line 61, col 30.
        write('''.
\t<input type="submit" value="Search" />
</p></form>

''')
        msgcount = len(VFFSL(SL,"messages",True))
        rowcount = len(VFFSL(SL,"messages",True)) + 1
        write('''
<table class="horiztable">
\t<caption>
\t\t<span class="cornerkludge"></span>
\t\tMessage list<br />
\t\t<span class="subtitle">''')
        _v = VFFSL(SL,"msgcount",True) # '$msgcount' on line 72, col 26
        if _v is not None: write(_filter(_v, rawExpr='$msgcount')) # from line 72, col 26.
        write(''' messages</span>
\t</caption>

\t<tr class="header">
\t\t<td class="leftkludge" rowspan="''')
        _v = VFFSL(SL,"rowcount",True) # '$rowcount' on line 76, col 35
        if _v is not None: write(_filter(_v, rawExpr='$rowcount')) # from line 76, col 35.
        write('''"></td>
\t\t<th>Time</th>
\t\t<th>Time Sent</th>
\t\t<th>Phone No.</th>
\t\t<th>Message</th>
\t\t<th>Severity</th>
\t\t<th>Status</th>
\t\t<td class="rightkludge" rowspan="''')
        _v = VFFSL(SL,"rowcount",True) # '$rowcount' on line 83, col 36
        if _v is not None: write(_filter(_v, rawExpr='$rowcount')) # from line 83, col 36.
        write('''"></td>
\t</tr>

''')
        for message in VFFSL(SL,"messages",True): # generated from line 86, col 1
            write('''\t''')
            _v = VFFSL(SL,"add_message",False)(VFFSL(SL,"message",True)) # '$add_message($message)' on line 87, col 2
            if _v is not None: write(_filter(_v, rawExpr='$add_message($message)')) # from line 87, col 2.
            write('''
''')
        write('''</table>

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

    def additionalCSS(self, **KWS):



        ## CHEETAH: generated from #block additionalCSS at line 93, 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_table_CSS",True) # '$default_table_CSS' on line 94, col 1
        if _v is not None: write(_filter(_v, rawExpr='$default_table_CSS')) # from line 94, 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('''



''')
        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__

    title = 'My SMS'

    path = [("Home", "/"), ("AlertProfiles", "/alertprofiles/"), ("My SMS","")]

    _mainCheetahMethod_for_MySMSTemplate= 'writeBody'

## END CLASS DEFINITION

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


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


