If you use the BasePage / SiteTemplate concept from Webware then it sort of conflicts
with the Skeleton page from Cheetah.
I started a project w/ a SitePage(webkit.Page) and then decided to use cheetah for the
'writeContent' bit.
I do not use the .tmpl files, but rather I call templates directly from the servlet.
-Aaron
Login.py
templateDef = """
<div align=center>
$rf.start
$rf.hidden
<table>
#if ($rf.errorText())
<tr><td colspan="2" align="center">Warning:
<b>$rf.errorText()</b></td></tr>
#end if
#for $f in $rf.visibleFields
#if (not $f.isSubmit)
<tr><td align="right">$f.description:</td><td>$f
$f.error</td></tr>
#end if
#end for
<tr><td align="center" colspan="2">
#for $f in $rf.submitFields
$f $f.error
#end for
</td></tr>
</table>
$rf.end
</div>
"""
from SitePage import SitePage
from FunFormKit.Form import *
from FunFormKit.Field import *
from FunFormKit.Validator import *
from Cheetah.Template import Template
from CSUserManager import UserManager
class loginUser(FormValidator):
def validate(self,fieldDict):
print('in Validate: ', fieldDict['userName'],fieldDict['password'])
#user = UserManager.login(fieldDict['userName'],fieldDict['password'])
user=UserManager.login(fieldDict['userName'],fieldDict['password'])
#user='aaron'
if (user==None):
print "Invalid User/Pass"
return {"form":'This is not a valid User Name / Password'}
else:
print 'Valid user in loginUser - FV'
return None
class NotExists(ValidatorConverter):
def validate(self, value):
#if value != "Admin":
# return 'For this example, please use "Admin"'
#else:
return None
fields = [
TextField('userName', size=30, maxLength=30,validators =
[NotEmpty(),NotExists()]),
PasswordField('password', size=30, maxLength=30,validators = [NotEmpty()]),
SubmitButton('submitLogin', description='Login', methodToInvoke='loginUser'),
]
formDefs = [
FormDefinition('Login','writeForm',fields,formValidators=[loginUser()])
]
class Login(SitePage, FormServlet):
def __init__(self):
FormServlet.__init__(self, 'writeContent', formDefs)
SitePage.__init__(self)
def writeForm(self):
defaults = {}
options = {}
#uncomment the defaults for testing
#defaults['userName']='[EMAIL PROTECTED]'
#defaults['password']='I almost sent this to the list...'
#if not len(permissionID):
# options['update'] = {'hide': 1}
#else:
# options['add'] = {'hide': 1}
rf = self.renderableForm(defaults=defaults, optionSet=options)
t = Template(templateDef,[{'rf':rf}])
self.writeln(t)
self.setUpLog('Login','Anonymous User is viewing the login page' )
def loginUser(self,fields):
self._user = UserManager.login(fields['userName'],fields['password'])
self.session().setValue('user',self._user)
self.response().sendRedirect('Welcome')
self.setUpLog('LoginUser','%s is Logging in' % fields['userName'] )
def title(self):
return "Please Login"
>
> From: Baruch Even <[EMAIL PROTECTED]>
> Date: 2002/03/01 Fri PM 05:52:20 EST
> To: Webware Discuss <[EMAIL PROTECTED]>
> Subject: [Webware-discuss] FFK and Cheetah (and WebKit)
>
> Hi,
>
> I'm trying to build an application with Cheetah and FunFormKit under
> WebKit. I'm having a problem to use a templated page setup and use FFK.
>
> My current way to work is that I have a SkeletonPage class which is
> equivalent to that of Cheetah, from that I create using a .tmpl file a
> SiteTemplate class. This stage works and I have some pages that inherit
> the template and change the content. Neat and easy.
>
> Now I want to create a login page and use FFK to do the form itself.
>
> I've tried to create Python subclass Login.py that inherits from Cheetah
> and from FFK and replace the writeContent method that I use to display
> the page content. But it simply doesn't work and I get only the
> SiteTemplate result.
>
> I'd be happy if someone can explain to me where I'm wrong and possibly
> provide an example on how to build together with all these components.
>
> Thanks,
> Baruch
>
>
> _______________________________________________
> Webware-discuss mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/webware-discuss
>
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss