#!/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 nav.web.templates.MainTemplate import MainTemplate

##################################################
## 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.1569531
__CHEETAH_genTimestamp__ = 'Sun Oct 26 14:33:33 2008'
__CHEETAH_src__ = 'UserInfo.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 UserInfo(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 grouplist(self, **KWS):



        ## CHEETAH: generated from #def grouplist() 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
        
        _v = ', '.join( [g.name for g in VFFSL(SL,"groups",True)] )
        if _v is not None: write(_filter(_v))
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def orglist(self, **KWS):



        ## CHEETAH: generated from #def orglist() at line 34, 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 = ', '.join(VFFSL(SL,"orgs",True))
        if _v is not None: write(_filter(_v))
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def content(self, **KWS):



        ## CHEETAH: generated from #block content at line 38, 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('''
<h1>User information</h1>

''')
        if VFFSL(SL,"varExists",False)('account'): # generated from line 42, col 1
            write('''<table>
  <tr>
    <td class="attr_name">Login:</td>
    <td class="attr">''')
            _v = VFFSL(SL,"account.login",True) # '$account.login' on line 46, col 22
            if _v is not None: write(_filter(_v, rawExpr='$account.login')) # from line 46, col 22.
            write('''</td>
  </tr>
  <tr>
    <td class="attr_name">Name:</td>
    <td class="attr">''')
            _v = VFFSL(SL,"account.name",True) # '$account.name' on line 50, col 22
            if _v is not None: write(_filter(_v, rawExpr='$account.name')) # from line 50, col 22.
            write('''</td>
  </tr>
  <tr>
    <td class="attr_name">Groups:</td>
    <td class="attr">''')
            _v = VFFSL(SL,"grouplist",False)() # '$grouplist()' on line 54, col 22
            if _v is not None: write(_filter(_v, rawExpr='$grouplist()')) # from line 54, col 22.
            write('''</td>
  </tr>
  <tr>
    <td class="attr_name">Organizations:</td>
    <td class="attr">''')
            _v = VFFSL(SL,"orglist",False)() # '$orglist()' on line 58, col 22
            if _v is not None: write(_filter(_v, rawExpr='$orglist()')) # from line 58, col 22.
            write('''</td>
  </tr>
</table>

''')
            if VFFSL(SL,"changePassword",True): # generated from line 62, col 1
                write('''
<h3>Change your password</h3>
''')
                _v = VFFSL(SL,"messages",False)() # '$messages()' on line 65, col 1
                if _v is not None: write(_filter(_v, rawExpr='$messages()')) # from line 65, col 1.
                write('''
<form action="/index/passwd" method="POST">
  <table>
    <tr>
      <td class="attr_name">Your old password:</td>
      <td class="attr"><input type="password" name="oldpasswd" /></td>
    </tr>
    <tr>
      <td class="attr_name">Choose a new password:</td>
      <td class="attr"><input type="password" name="newpasswd1" /></td>
    </tr>
    <tr>
      <td class="attr_name">Confirm your new password:</td>
      <td class="attr"><input type="password" name="newpasswd2" /></td>
    </tr>
  </table>
  <input type="submit" value="Change password" />
</form>
''')
            else: # generated from line 83, col 1
                _v = VFFSL(SL,"messages",False)() # '$messages()' on line 84, col 1
                if _v is not None: write(_filter(_v, rawExpr='$messages()')) # from line 84, col 1.
                write('''
<p>You are not allowed to change your password from this page.  Your account is
managed through an external system, known as &quot;''')
                _v = VFFSL(SL,"account.ext_sync",True) # '$account.ext_sync' on line 86, col 52
                if _v is not None: write(_filter(_v, rawExpr='$account.ext_sync')) # from line 86, col 52.
                write('''&quot;.</p>
''')
            write('''

''')
        else: # generated from line 90, col 1
            _v = VFFSL(SL,"messages",False)() # '$messages()' on line 91, col 1
            if _v is not None: write(_filter(_v, rawExpr='$messages()')) # from line 91, col 1.
            write('''
<p>You are not logged in.</p>

<p><a href="/">Click here to return to the main page.</a></p>

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

    def messages(self, **KWS):



        ## CHEETAH: generated from #block messages at line 99, 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,"varExists",False)('errorMessage'): # generated from line 100, col 1
            write('''<p style="color: red">ERROR: ''')
            _v = VFFSL(SL,"errorMessage",True) # '$errorMessage' on line 101, col 30
            if _v is not None: write(_filter(_v, rawExpr='$errorMessage')) # from line 101, col 30.
            write('''</p>
''')
        if VFFSL(SL,"varExists",False)('message'): # generated from line 103, col 1
            write('''<p style="color: green">NOTICE: ''')
            _v = VFFSL(SL,"message",True) # '$message' on line 104, col 33
            if _v is not None: write(_filter(_v, rawExpr='$message')) # from line 104, col 33.
            write('''</p>
''')
        
        ########################################
        ## END - generated method body
        
        return _dummyTrans and trans.response().getvalue() or ""
        

    def additionalCSS(self, **KWS):



        ## CHEETAH: generated from #block additionalCSS at line 108, 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 109, col 1
        if _v is not None: write(_filter(_v, rawExpr='$default_table_CSS')) # from line 109, col 1.
        write('''
<link rel="stylesheet" type="text/css" href="/style/UserInfo.css" />
''')
        
        ########################################
        ## 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: UserInfo.tmpl 3809 2007-01-19 14:16:23Z jodal $
        #  Extends the MainTemplate for header-information, nav-logo and navigation-bar.
        #  Defines the user information page, which includes a password changing form.
        # 
        #  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.content(trans=trans)
        write('''
''')
        self.messages(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__

    _mainCheetahMethod_for_UserInfo= 'writeBody'

## END CLASS DEFINITION

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


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


