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

##################################################
## 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__ = 1225031614.7767179
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:34 2008'
__CHEETAH_src__ = 'useradmin/GroupPage.tmpl'
__CHEETAH_srcLastModified__ = 'Wed Apr 28 13:03:41 2004'
__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 GroupPage(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, **KWS):



        ## CHEETAH: generated from #def textfield($name, $value, $maxLength=0, $forceEditable=0) 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
        
        if VFFSL(SL,"editable",True) or VFFSL(SL,"forceEditable",True): # generated from line 31, col 1
            write('''  <input type="text" name="''')
            _v = VFFSL(SL,"name",True) # '$name' on line 32, col 28
            if _v is not None: write(_filter(_v, rawExpr='$name')) # from line 32, col 28.
            write('''" value="''')
            _v = VFFSL(SL,"value",True) # '$value' on line 32, col 42
            if _v is not None: write(_filter(_v, rawExpr='$value')) # from line 32, col 42.
            write('''" />
''')
        else: # generated from line 33, col 1
            write('''  <i>''')
            _v = VFFSL(SL,"value",True) # '$value' on line 34, col 6
            if _v is not None: write(_filter(_v, rawExpr='$value')) # from line 34, col 6.
            write('''</i>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def add_account(self, account, add=False, **KWS):



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

    def add_privilege(self, privilege, **KWS):



        ## CHEETAH: generated from #def add_privilege($privilege) at line 49, 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('''  <b>''')
        _v = VFFSL(SL,"privilege.privilegename",True) # '$privilege.privilegename' on line 50, col 6
        if _v is not None: write(_filter(_v, rawExpr='$privilege.privilegename')) # from line 50, col 6.
        write('''</b> for <code>''')
        _v = VFFSL(SL,"privilege.target",True) # '$privilege.target' on line 50, col 45
        if _v is not None: write(_filter(_v, rawExpr='$privilege.target')) # from line 50, col 45.
        write('''</code>
  (<a href="revoke?gid=''')
        _v = VFFSL(SL,"group.id",True) # '$group.id' on line 51, col 24
        if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 51, col 24.
        write('''&pid=''')
        _v = VFFSL(SL,"privilege.privilegeid",True) # '$privilege.privilegeid' on line 51, col 38
        if _v is not None: write(_filter(_v, rawExpr='$privilege.privilegeid')) # from line 51, col 38.
        write('''&target=''')
        _v = VFN(VFFSL(SL,"urllib",True),"quote",False)(VFFSL(SL,"privilege.target",True)) # '$urllib.quote($privilege.target)' on line 51, col 68
        if _v is not None: write(_filter(_v, rawExpr='$urllib.quote($privilege.target)')) # from line 51, col 68.
        write('''">Revoke</a>)
  <br>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def useradmin(self, **KWS):



        ## CHEETAH: generated from #block useradmin at line 60, 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('''<form method="POST" action="groupsubmit">
''')
        if not VFFSL(SL,"newGroup",True): # generated from line 62, col 1
            write('''  <input type="hidden" name="id" value="''')
            _v = VFFSL(SL,"group.id",True) # '$group.id' on line 63, col 41
            if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 63, col 41.
            write('''">
''')
        write('''  <b>Name:</b> ''')
        _v = VFFSL(SL,"textfield",False)('name', VFFSL(SL,"group.name",True)) # "$textfield('name', $group.name)" on line 65, col 16
        if _v is not None: write(_filter(_v, rawExpr="$textfield('name', $group.name)")) # from line 65, col 16.
        write('''<br>
  <b>Description:</b> ''')
        _v = VFFSL(SL,"textfield",False)('description', VFFSL(SL,"group.description",True)) # "$textfield('description', $group.description)" on line 66, col 23
        if _v is not None: write(_filter(_v, rawExpr="$textfield('description', $group.description)")) # from line 66, col 23.
        write('''<br>
  <input type="submit" value="Submit changes" />
</form>

''')
        if not VFFSL(SL,"newGroup",True): # generated from line 70, col 1
            write('''
<p><a href="groupdel?id=''')
            _v = VFFSL(SL,"group.id",True) # '$group.id' on line 72, col 25
            if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 72, col 25.
            write('''">DELETE</a> this group</p>

<h3>Privileges</h3>

<p><font size=-1>(See <a
href="http://www.amk.ca/python/howto/regex/">http://www.amk.ca/python/howto/regex/</a>
for a HOWTO on the Regular expressions used for matching targets for privileges
like \'web_access\'.)</font></p>

''')
            for privilege in VFFSL(SL,"group.privileges",True): # generated from line 81, col 1
                _v = VFFSL(SL,"add_privilege",False)(VFFSL(SL,"privilege",True)) # '$add_privilege($privilege)' on line 82, col 1
                if _v is not None: write(_filter(_v, rawExpr='$add_privilege($privilege)')) # from line 82, col 1.
                write('''
''')
            write('''
  <h4>Grant privileges:</h4>
  <form name="privileges" action="grant">
    <p>
      <input type="hidden" name="gid" value="''')
            _v = VFFSL(SL,"group.id",True) # '$group.id' on line 88, col 46
            if _v is not None: write(_filter(_v, rawExpr='$group.id')) # from line 88, col 46.
            write('''" />
      <select name="pid" size="1">
''')
            for privilege in VFFSL(SL,"privileges",True): # generated from line 90, col 1
                write('''        <option value="''')
                _v = VFFSL(SL,"privilege.id",True) # '$privilege.id' on line 91, col 24
                if _v is not None: write(_filter(_v, rawExpr='$privilege.id')) # from line 91, col 24.
                write('''">''')
                _v = VFFSL(SL,"privilege.name",True) # '$privilege.name' on line 91, col 39
                if _v is not None: write(_filter(_v, rawExpr='$privilege.name')) # from line 91, col 39.
                write('''</option>
''')
            write('''      </select>
      <b>Target:</b><input type="text" name="target" value="" size="60" /><br>
      <input type="submit" value="Grant" />
    </p>
  </form>

<h3>Member list</h3>

''')
            for account in VFFSL(SL,"group.members",True): # generated from line 101, col 1
                _v = VFFSL(SL,"add_account",False)(VFFSL(SL,"account",True), False) # '$add_account($account, False)' on line 102, col 1
                if _v is not None: write(_filter(_v, rawExpr='$add_account($account, False)')) # from line 102, col 1.
                write('''
''')
            write('''
<h3>Non-member list</h3>

''')
            for account in VFFSL(SL,"group.nonmembers",True): # generated from line 107, col 1
                _v = VFFSL(SL,"add_account",False)(VFFSL(SL,"account",True), True) # '$add_account($account, True)' on line 108, col 1
                if _v is not None: write(_filter(_v, rawExpr='$add_account($account, True)')) # from line 108, 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: GroupPage.tmpl 2674 2004-04-28 13:03:41Z mortenv $
        #  Extends the UserAdmin template for common useradmin structure.
        #  Builds html for the edit Group 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('''





''')
        #  
        #  useradmin is the content block for all useradmin pages
        #  it begins here
        # 
        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_GroupPage= 'writeBody'

## END CLASS DEFINITION

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


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


