1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: cgi_client.py,v 1.38 2001-10-22 03:25:01 richard Exp $
18+ # $Id: cgi_client.py,v 1.39 2001-10-23 01:00:18 richard Exp $
1919
2020import os , cgi , pprint , StringIO , urlparse , re , traceback , mimetypes
2121import base64 , Cookie , time
@@ -240,8 +240,8 @@ def list(self, sort=None, group=None, filter=None, columns=None,
240240 if show_customization is None :
241241 show_customization = self .customization_widget ()
242242
243- htmltemplate .index (self , self .TEMPLATES , self . db , cn , filterspec ,
244- filter , columns , sort , group ,
243+ index = htmltemplate .IndexTemplate (self , self .TEMPLATES , cn )
244+ index . render ( filterspec , filter , columns , sort , group ,
245245 show_customization = show_customization )
246246 self .pagefoot ()
247247
@@ -276,7 +276,9 @@ def shownode(self, message=None):
276276 nodeid = self .nodeid
277277
278278 # use the template to display the item
279- htmltemplate .item (self , self .TEMPLATES , self .db , self .classname , nodeid )
279+ item = htmltemplate .ItemTemplate (self , self .TEMPLATES , self .classname )
280+ item .render (nodeid )
281+
280282 self .pagefoot ()
281283 showissue = shownode
282284 showmsg = shownode
@@ -433,8 +435,12 @@ def newnode(self, message=None):
433435 traceback .print_exc (None , s )
434436 message = '<pre>%s</pre>' % cgi .escape (s .getvalue ())
435437 self .pagehead ('New %s' % self .classname .capitalize (), message )
436- htmltemplate .newitem (self , self .TEMPLATES , self .db , self .classname ,
437- self .form )
438+
439+ # call the template
440+ newitem = htmltemplate .NewItemTemplate (self , self .TEMPLATES ,
441+ self .classname )
442+ newitem .render (self .form )
443+
438444 self .pagefoot ()
439445 newissue = newnode
440446 newuser = newnode
@@ -466,8 +472,9 @@ def newfile(self, message=None):
466472 message = '<pre>%s</pre>' % cgi .escape (s .getvalue ())
467473
468474 self .pagehead ('New %s' % self .classname .capitalize (), message )
469- htmltemplate .newitem (self , self .TEMPLATES , self .db , self .classname ,
470- self .form )
475+ newitem = htmltemplate .NewItemTemplate (self , self .TEMPLATES ,
476+ self .classname )
477+ newitem .render (self .form )
471478 self .pagefoot ()
472479
473480 def classes (self , message = None ):
@@ -541,6 +548,7 @@ def login_action(self, message=None):
541548 password = self .form ['__login_password' ].value
542549 else :
543550 password = ''
551+ print self .user , password
544552 # make sure the user exists
545553 try :
546554 uid = self .db .user .lookup (self .user )
@@ -585,6 +593,10 @@ def newuser_action(self, message=None):
585593 ''' create a new user based on the contents of the form and then
586594 set the cookie
587595 '''
596+ # re-open the database as "admin"
597+ self .db .close ()
598+ self .db = self .instance .open ('admin' )
599+
588600 # TODO: pre-check the required fields and username key property
589601 cl = self .db .classes ['user' ]
590602 props , dummy = parsePropsFromForm (self .db , cl , self .form )
@@ -626,10 +638,6 @@ def main(self, dre=re.compile(r'([^\d]+)(\d+)'),
626638 self .user = user
627639 self .db .close ()
628640
629- # make sure totally anonymous access is OK
630- if self .ANONYMOUS_ACCESS == 'deny' and self .user is None :
631- return self .login ()
632-
633641 # re-open the database for real, using the user
634642 self .db = self .instance .open (self .user )
635643
@@ -647,18 +655,28 @@ def main(self, dre=re.compile(r'([^\d]+)(\d+)'),
647655 # appends the name of the file to the URL so the download file name
648656 # is correct, but doesn't actually use it.
649657 action = path [0 ]
650- if action == 'list_classes' :
651- self .classes ()
652- return
653- if action == 'login' :
654- self .login ()
655- return
656658 if action == 'login_action' :
657659 self .login_action ()
658660 return
661+
662+ # make sure anonymous are allowed to register
663+ if self .ANONYMOUS_REGISTER == 'deny' and self .user is None :
664+ return self .login ()
665+
659666 if action == 'newuser_action' :
660667 self .newuser_action ()
661668 return
669+
670+ # make sure totally anonymous access is OK
671+ if self .ANONYMOUS_ACCESS == 'deny' and self .user is None :
672+ return self .login ()
673+
674+ if action == 'list_classes' :
675+ self .classes ()
676+ return
677+ if action == 'login' :
678+ self .login ()
679+ return
662680 if action == 'logout' :
663681 self .logout ()
664682 return
@@ -834,6 +852,12 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
834852
835853#
836854# $Log: not supported by cvs2svn $
855+ # Revision 1.38 2001/10/22 03:25:01 richard
856+ # Added configuration for:
857+ # . anonymous user access and registration (deny/allow)
858+ # . filter "widget" location on index page (top, bottom, both)
859+ # Updated some documentation.
860+ #
837861# Revision 1.37 2001/10/21 07:26:35 richard
838862# feature #473127: Filenames. I modified the file.index and htmltemplate
839863# source so that the filename is used in the link and the creation
0 commit comments