#!/usr/bin/env python




##################################################
## 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 UserAdmin import UserAdmin

##################################################
## 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__ = 1225031613.6980619
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:33 2008'
__CHEETAH_src__ = 'useradmin/AccountList.tmpl'
__CHEETAH_srcLastModified__ = 'Mon Jul 17 06:35:04 2006'
__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 AccountList(UserAdmin):

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


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

        UserAdmin.__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_account(self, account, **KWS):



        ## CHEETAH: generated from #def add_account($account) at line 30, 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('''    <tr class="''')
        _v = VFFSL(SL,"rowcycler",True) # '$rowcycler' on line 31, col 16
        if _v is not None: write(_filter(_v, rawExpr='$rowcycler')) # from line 31, col 16.
        write('''">
        <td><a href="/useradmin/account?id=''')
        _v = VFFSL(SL,"account.id",True) # '$account.id' on line 32, col 44
        if _v is not None: write(_filter(_v, rawExpr='$account.id')) # from line 32, col 44.
        write('''">''')
        _v = VFFSL(SL,"account.login",True) # '$account.login' on line 32, col 57
        if _v is not None: write(_filter(_v, rawExpr='$account.login')) # from line 32, col 57.
        write('''</a></td>
        <td>''')
        _v = VFFSL(SL,"account.name",True) # '$account.name' on line 33, col 13
        if _v is not None: write(_filter(_v, rawExpr='$account.name')) # from line 33, col 13.
        write('''</td>
        <td>''')
        _v = VFFSL(SL,"account.ext_sync",True) # '$account.ext_sync' on line 34, col 13
        if _v is not None: write(_filter(_v, rawExpr='$account.ext_sync')) # from line 34, col 13.
        write('''</td>
        <td style="text-align: center;">''')
        _v = VFFSL(SL,"account.groupcount",True) # '$account.groupcount' on line 35, col 41
        if _v is not None: write(_filter(_v, rawExpr='$account.groupcount')) # from line 35, col 41.
        write('''</td>
    </tr>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def useradmin(self, **KWS):



        ## CHEETAH: generated from #block useradmin at line 40, 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('''
<table class="horiztable">
''')
        accountcount = len(VFFSL(SL,"accounts",True))
        write('''    <caption>
        <span class="cornerkludge"></span>
        Account List<br />
        <span class="subtitle">''')
        _v = VFFSL(SL,"accountcount",True) # '$accountcount' on line 47, col 32
        if _v is not None: write(_filter(_v, rawExpr='$accountcount')) # from line 47, col 32.
        write(''' accounts :
        <a href="account">Create new user</a></span>
    </caption>

''')
        rowcount = len(VFFSL(SL,"accounts",True)) + 1
        write('''    <tr class="header">
        <td class="leftkludge" rowspan="''')
        _v = VFFSL(SL,"rowcount",True) # '$rowcount' on line 53, col 41
        if _v is not None: write(_filter(_v, rawExpr='$rowcount')) # from line 53, col 41.
        write('''"></td>
        <th>Login</th>
        <th>Name</th>
        <th>External</th>
        <th style="text-align: center;"># of groups</th>
        <td class="rightkludge" rowspan="''')
        _v = VFFSL(SL,"rowcount",True) # '$rowcount' on line 58, col 42
        if _v is not None: write(_filter(_v, rawExpr='$rowcount')) # from line 58, col 42.
        write('''"></td>
    </tr>

''')
        for account in VFFSL(SL,"accounts",True): # generated from line 61, col 1
            write('''    ''')
            _v = VFFSL(SL,"add_account",False)(VFFSL(SL,"account",True)) # '$add_account($account)' on line 62, col 5
            if _v is not None: write(_filter(_v, rawExpr='$add_account($account)')) # from line 62, col 5.
            write('''
''')
        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: AccountList.tmpl 3536 2006-07-17 06:35:04Z jodal $
        #  Extends the UserAdmin template for common useradmin structure.
        #  Builds html for the Account list screen of the useradmin module.
        # 
        #  Copyright 2003, 2004 Norwegian University of Science and Technology
        # 
        #  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
        # 
        # 
        #  Authors: Morten Vold <morten.vold@itea.ntnu.no>
        #           Magnar Sveen <magnars@idi.ntnu.no>
        # 
        write('''



''')
        self.useradmin(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_AccountList= 'writeBody'

## END CLASS DEFINITION

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


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


