Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 2940:00f609d53a8c
tweaks to last patch
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 21 Nov 2004 21:55:03 +0000 |
| parents | 463902a0fbbb |
| children | a50e4f7c9276 |
comparison
equal
deleted
inserted
replaced
| 2938:463902a0fbbb | 2940:00f609d53a8c |
|---|---|
| 1 # $Id: client.py,v 1.204 2004-11-21 13:27:03 a1s Exp $ | 1 # $Id: client.py,v 1.205 2004-11-21 21:55:03 richard Exp $ |
| 2 | 2 |
| 3 """WWW request handler (also used in the stand-alone server). | 3 """WWW request handler (also used in the stand-alone server). |
| 4 """ | 4 """ |
| 5 __docformat__ = 'restructuredtext' | 5 __docformat__ = 'restructuredtext' |
| 6 | 6 |
| 217 | 217 |
| 218 # make sure we're identified (even anonymously) | 218 # make sure we're identified (even anonymously) |
| 219 self.determine_user() | 219 self.determine_user() |
| 220 | 220 |
| 221 # figure out the context and desired content template | 221 # figure out the context and desired content template |
| 222 # do this first so we don't authenticate for static files | |
| 223 # Note: this method opens the database as "admin" in order to | |
| 224 # perform context checks | |
| 225 self.determine_context() | 222 self.determine_context() |
| 226 | 223 |
| 227 # possibly handle a form submit action (may change self.classname | 224 # possibly handle a form submit action (may change self.classname |
| 228 # and self.template, and may also append error/ok_messages) | 225 # and self.template, and may also append error/ok_messages) |
| 229 html = self.handle_action() | 226 html = self.handle_action() |
| 430 self.user = user | 427 self.user = user |
| 431 | 428 |
| 432 # reopen the database as the correct user | 429 # reopen the database as the correct user |
| 433 self.opendb(self.user) | 430 self.opendb(self.user) |
| 434 | 431 |
| 432 def opendb(self, username): | |
| 433 ''' Open the database and set the current user. | |
| 434 | |
| 435 Opens a database once. On subsequent calls only the user is set on | |
| 436 the database object the instance.optimize is set. If we are in | |
| 437 "Development Mode" (cf. roundup_server) then the database is always | |
| 438 re-opened. | |
| 439 ''' | |
| 440 # don't do anything if the db is open and the user has not changed | |
| 441 if hasattr(self, 'db') and self.db.isCurrentUser(username): | |
| 442 return | |
| 443 | |
| 444 # open the database or only set the user | |
| 445 if not hasattr(self, 'db'): | |
| 446 self.db = self.instance.open(username) | |
| 447 else: | |
| 448 if self.instance.optimize: | |
| 449 self.db.setCurrentUser(username) | |
| 450 else: | |
| 451 self.db.close() | |
| 452 self.db = self.instance.open(username) | |
| 453 | |
| 435 def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')): | 454 def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')): |
| 436 """Determine the context of this page from the URL: | 455 """Determine the context of this page from the URL: |
| 437 | 456 |
| 438 The URL path after the instance identifier is examined. The path | 457 The URL path after the instance identifier is examined. The path |
| 439 is generally only one entry long. | 458 is generally only one entry long. |
| 508 self.classname = path[0] | 527 self.classname = path[0] |
| 509 if len(path) > 1: | 528 if len(path) > 1: |
| 510 # send the file identified by the designator in path[0] | 529 # send the file identified by the designator in path[0] |
| 511 raise SendFile, path[0] | 530 raise SendFile, path[0] |
| 512 | 531 |
| 513 # we need the db for further context stuff - open it as admin | |
| 514 self.opendb('admin') | |
| 515 | |
| 516 # see if we got a designator | 532 # see if we got a designator |
| 517 m = dre.match(self.classname) | 533 m = dre.match(self.classname) |
| 518 if m: | 534 if m: |
| 519 self.classname = m.group(1) | 535 self.classname = m.group(1) |
| 520 self.nodeid = m.group(2) | 536 self.nodeid = m.group(2) |
| 542 m = dre.match(str(designator)) | 558 m = dre.match(str(designator)) |
| 543 if not m: | 559 if not m: |
| 544 raise NotFound, str(designator) | 560 raise NotFound, str(designator) |
| 545 classname, nodeid = m.group(1), m.group(2) | 561 classname, nodeid = m.group(1), m.group(2) |
| 546 | 562 |
| 547 self.opendb('admin') | |
| 548 klass = self.db.getclass(classname) | 563 klass = self.db.getclass(classname) |
| 549 | 564 |
| 550 # make sure we have the appropriate properties | 565 # make sure we have the appropriate properties |
| 551 props = klass.getprops() | 566 props = klass.getprops() |
| 552 if not props.has_key('type'): | 567 if not props.has_key('type'): |
| 820 user, but that user is mandatory now. | 835 user, but that user is mandatory now. |
| 821 ''' | 836 ''' |
| 822 self.userid = self.db.user.lookup('anonymous') | 837 self.userid = self.db.user.lookup('anonymous') |
| 823 self.user = 'anonymous' | 838 self.user = 'anonymous' |
| 824 | 839 |
| 825 def opendb(self, username): | |
| 826 ''' Open the database and set the current user. | |
| 827 | |
| 828 Opens a database once. On subsequent calls only the user is set on | |
| 829 the database object the instance.optimize is set. If we are in | |
| 830 "Development Mode" (cf. roundup_server) then the database is always | |
| 831 re-opened. | |
| 832 ''' | |
| 833 # don't do anything if the db is open and the user has not changed | |
| 834 if hasattr(self, 'db') and self.db.isCurrentUser(username): | |
| 835 return | |
| 836 | |
| 837 # open the database or only set the user | |
| 838 if not hasattr(self, 'db'): | |
| 839 self.db = self.instance.open(username) | |
| 840 else: | |
| 841 if self.instance.optimize: | |
| 842 self.db.setCurrentUser(username) | |
| 843 else: | |
| 844 self.db.close() | |
| 845 self.db = self.instance.open(username) | |
| 846 | |
| 847 def standard_message(self, to, subject, body, author=None): | 840 def standard_message(self, to, subject, body, author=None): |
| 848 '''Send a standard email message from Roundup. | 841 '''Send a standard email message from Roundup. |
| 849 | 842 |
| 850 "to" - recipients list | 843 "to" - recipients list |
| 851 "subject" - Subject | 844 "subject" - Subject |
