#!/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.965687
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:33 2008'
__CHEETAH_src__ = 'useradmin/AccountPage.tmpl'
__CHEETAH_srcLastModified__ = 'Wed Jan 19 10:21:30 2005'
__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 AccountPage(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 textfield(self, name, value, maxLength=0, forceEditable=0, password=False, **KWS):



        ## CHEETAH: generated from #def textfield($name, $value, $maxLength=0, $forceEditable=0, $password=False) at line 29, 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
        
        if VFFSL(SL,"password",True): # generated from line 30, col 1
            inputtype = "password"
        else: # generated from line 32, col 1
            inputtype = "text"
        write('''
''')
        if VFFSL(SL,"editable",True) or VFFSL(SL,"forceEditable",True): # generated from line 36, col 1
            write('''  <input type="''')
            _v = VFFSL(SL,"inputtype",True) # '$inputtype' on line 37, col 16
            if _v is not None: write(_filter(_v, rawExpr='$inputtype')) # from line 37, col 16.
            write('''" name="''')
            _v = VFFSL(SL,"name",True) # '$name' on line 37, col 34
            if _v is not None: write(_filter(_v, rawExpr='$name')) # from line 37, col 34.
            write('''" value="''')
            _v = VFFSL(SL,"value",True) # '$value' on line 37, col 48
            if _v is not None: write(_filter(_v, rawExpr='$value')) # from line 37, col 48.
            write('''" />
''')
        else: # generated from line 38, col 1
            write('''  <i>''')
            _v = VFFSL(SL,"value",True) # '$value' on line 39, col 6
            if _v is not None: write(_filter(_v, rawExpr='$value')) # from line 39, col 6.
            write('''</i>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def add_group(self, group, add=False, **KWS):



        ## CHEETAH: generated from #def add_group($group, $add=False) at line 44, 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('''  <a href="/useradmin/group?id=''')
        _v = VFFSL(SL,"group.id",True) # '$group.id' on line 45, col 32
        if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 45, col 32.
        write('''">''')
        _v = VFFSL(SL,"group.name",True) # '$group.name' on line 45, col 43
        if _v is not None: write(_filter(_v, rawExpr='$group.name')) # from line 45, col 43.
        write('''</a> - ''')
        _v = VFFSL(SL,"group.description",True) # '$group.description' on line 45, col 61
        if _v is not None: write(_filter(_v, rawExpr='$group.description')) # from line 45, col 61.
        write(''' -
''')
        if VFFSL(SL,"add",True): # generated from line 46, col 1
            write('''  <a href="/useradmin/link?gid=''')
            _v = VFFSL(SL,"group.id",True) # '$group.id' on line 47, col 32
            if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 47, col 32.
            write('''&uid=''')
            _v = VFFSL(SL,"account.id",True) # '$account.id' on line 47, col 46
            if _v is not None: write(_filter(_v, rawExpr='$account.id')) # from line 47, col 46.
            write('''&source=account">ADD</a>
''')
        else: # generated from line 48, col 1
            write('''  <a href="/useradmin/unlink?gid=''')
            _v = VFFSL(SL,"group.id",True) # '$group.id' on line 49, col 34
            if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 49, col 34.
            write('''&uid=''')
            _v = VFFSL(SL,"account.id",True) # '$account.id' on line 49, col 48
            if _v is not None: write(_filter(_v, rawExpr='$account.id')) # from line 49, col 48.
            write('''&source=account">REMOVE</a>  
''')
        write('''  <br>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def add_orgtree(self, tree, level=0, **KWS):



        ## CHEETAH: generated from #def add_orgtree($tree, $level=0) at line 55, 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
        
        levelled = '&nbsp;&nbsp;' * VFFSL(SL,"level",True)
        orgs = VFN(VFFSL(SL,"tree",True),"keys",False)()
        _v = VFN(VFFSL(SL,"orgs",True),"sort",False)() # '$orgs.sort()' on line 58, col 1
        if _v is not None: write(_filter(_v, rawExpr='$orgs.sort()')) # from line 58, col 1.
        write('''
''')
        for org in VFFSL(SL,"orgs",True): # generated from line 59, col 1
            write('''    <option value="''')
            _v = VFFSL(SL,"org",True) # '$org' on line 60, col 20
            if _v is not None: write(_filter(_v, rawExpr='$org')) # from line 60, col 20.
            write('''">''')
            _v = VFFSL(SL,"levelled",True) # '$levelled' on line 60, col 26
            if _v is not None: write(_filter(_v, rawExpr='$levelled')) # from line 60, col 26.
            _v = VFFSL(SL,"org",True) # '$org' on line 60, col 35
            if _v is not None: write(_filter(_v, rawExpr='$org')) # from line 60, col 35.
            write('''</option>
''')
            if len(VFFSL(SL,"tree",True)[VFFSL(SL,"org",True)]) > 0: # generated from line 61, col 1
                _v = VFFSL(SL,"add_orgtree",False)(VFFSL(SL,"tree",True)[VFFSL(SL,"org",True)], VFFSL(SL,"level",True)+1) # '$add_orgtree($tree[$org], $level+1)' on line 62, col 1
                if _v is not None: write(_filter(_v, rawExpr='$add_orgtree($tree[$org], $level+1)')) # from line 62, col 1.
                write('''
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def useradmin(self, **KWS):



        ## CHEETAH: generated from #block useradmin at line 68, 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 border=0>
<form method="POST" action="accountsubmit">
''')
        if not VFFSL(SL,"newAccount",True): # generated from line 71, col 1
            write('''  <input type="hidden" name="id" value="''')
            _v = VFFSL(SL,"account.id",True) # '$account.id' on line 72, col 41
            if _v is not None: write(_filter(_v, rawExpr='$account.id')) # from line 72, col 41.
            write('''">
''')
        write('''  <tr><td><b>Login:</b></td><td>''')
        _v = VFFSL(SL,"textfield",False)('login', VFFSL(SL,"account.login",True)) # "$textfield('login', $account.login)" on line 74, col 33
        if _v is not None: write(_filter(_v, rawExpr="$textfield('login', $account.login)")) # from line 74, col 33.
        write('''</td></tr>
  <tr><td><b>Name:</b></td><td>''')
        _v = VFFSL(SL,"textfield",False)('name', VFFSL(SL,"account.name",True), forceEditable=1) # "$textfield('name', $account.name, forceEditable=1)" on line 75, col 32
        if _v is not None: write(_filter(_v, rawExpr="$textfield('name', $account.name, forceEditable=1)")) # from line 75, col 32.
        write('''</td></tr>
  <tr><td><b>External:</b></td><td> <i>
''')
        if VFFSL(SL,"account.ext_sync",True): # generated from line 77, col 1
            _v = VFFSL(SL,"account.ext_sync",True) # '$account.ext_sync' on line 78, col 1
            if _v is not None: write(_filter(_v, rawExpr='$account.ext_sync')) # from line 78, col 1.
            write('''
''')
        else: # generated from line 79, col 1
            write('''[None]
''')
        write('''  </i></td></tr>
''')
        if not (VFFSL(SL,"account.ext_sync",True)):
            write('''  <tr><td><b>Password:</b></td><td>''')
            _v = VFFSL(SL,"textfield",False)('password', '', password=True) # "$textfield('password', '', password=True)" on line 84, col 36
            if _v is not None: write(_filter(_v, rawExpr="$textfield('password', '', password=True)")) # from line 84, col 36.
            write('''</td></tr>
  <tr><td><b>Confirm password:</b></td><td>''')
            _v = VFFSL(SL,"textfield",False)('passwordConfirm', '', password=True) # "$textfield('passwordConfirm', '', password=True)" on line 85, col 44
            if _v is not None: write(_filter(_v, rawExpr="$textfield('passwordConfirm', '', password=True)")) # from line 85, col 44.
            write('''</td></tr>
''')
        write('''  <tr><td colspan="2"><input type="submit" value="Submit changes" /></td></tr>
</form>
</table>

''')
        if not VFFSL(SL,"newAccount",True): # generated from line 91, col 1
            write('''
<p><a href="accountdel?id=''')
            _v = VFFSL(SL,"account.id",True) # '$account.id' on line 93, col 27
            if _v is not None: write(_filter(_v, rawExpr='$account.id')) # from line 93, col 27.
            write('''">DELETE</a> this account</p>

<h3>Organizations</h3>

<p>
''')
            if len(VFFSL(SL,"account.organizations",True)) > 0: # generated from line 98, col 1
                organizations = map(lambda s: "<a href=\"orgunlink?uid=%s&orgid=%s\">%s</a>" % (VFFSL(SL,"account.id",True), s,s), VFFSL(SL,"account.organizations",True))
                orglist = ", ".join(VFFSL(SL,"organizations",True))
                write('''  Member of the following organizations (click one to remove): <i>''')
                _v = VFFSL(SL,"orglist",True) # '$orglist' on line 101, col 67
                if _v is not None: write(_filter(_v, rawExpr='$orglist')) # from line 101, col 67.
                write('''</i>
''')
            else: # generated from line 102, col 1
                write('''  Not a member of any organizations.
''')
            write('''</p>
<form name="organizations" method="POST" action="orglink">
  <input type="hidden" name="uid" value="''')
            _v = VFFSL(SL,"account.id",True) # '$account.id' on line 107, col 42
            if _v is not None: write(_filter(_v, rawExpr='$account.id')) # from line 107, col 42.
            write('''" />
  <select name="orgid" size="8" multiple>
''')
            _v = VFFSL(SL,"add_orgtree",False)(VFFSL(SL,"orgTree",True)) # '$add_orgtree($orgTree)' on line 109, col 1
            if _v is not None: write(_filter(_v, rawExpr='$add_orgtree($orgTree)')) # from line 109, col 1.
            write('''
  </select><br>
  <input type="submit" value="Add to selected organizations" />
</form>

<h3>Group memberships</h3>

''')
            for group in VFFSL(SL,"account.groups",True): # generated from line 116, col 1
                _v = VFFSL(SL,"add_group",False)(VFFSL(SL,"group",True)) # '$add_group($group)' on line 117, col 1
                if _v is not None: write(_filter(_v, rawExpr='$add_group($group)')) # from line 117, col 1.
                write('''
''')
            write('''
<h3>Group non-memberships</h3>

''')
            for group in VFFSL(SL,"account.nongroups",True): # generated from line 122, col 1
                _v = VFFSL(SL,"add_group",False)(VFFSL(SL,"group",True), add=True) # '$add_group($group, add=True)' on line 123, col 1
                if _v is not None: write(_filter(_v, rawExpr='$add_group($group, add=True)')) # from line 123, col 1.
                write('''
''')
            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: AccountPage.tmpl 3104 2005-01-19 10:21:30Z mortenv $
        #  Extends the UserAdmin template for common useradmin structure.
        #  Builds html for the edit Account 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>
        # 
        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_AccountPage= 'writeBody'

## END CLASS DEFINITION

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


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


