|
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 | 3 | """WWW request handler (also used in the stand-alone server). |
4 | 4 | """ |
@@ -219,9 +219,6 @@ def inner_main(self): |
219 | 219 | self.determine_user() |
220 | 220 |
|
221 | 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 | 222 | self.determine_context() |
226 | 223 |
|
227 | 224 | # possibly handle a form submit action (may change self.classname |
@@ -432,6 +429,28 @@ def determine_user(self): |
432 | 429 | # reopen the database as the correct user |
433 | 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 | 454 | def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')): |
436 | 455 | """Determine the context of this page from the URL: |
437 | 456 |
|
@@ -510,9 +529,6 @@ def determine_context(self, dre=re.compile(r'([^\d]+)0*(\d+)')): |
510 | 529 | # send the file identified by the designator in path[0] |
511 | 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 | 532 | # see if we got a designator |
517 | 533 | m = dre.match(self.classname) |
518 | 534 | if m: |
@@ -544,7 +560,6 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')): |
544 | 560 | raise NotFound, str(designator) |
545 | 561 | classname, nodeid = m.group(1), m.group(2) |
546 | 562 |
|
547 | | - self.opendb('admin') |
548 | 563 | klass = self.db.getclass(classname) |
549 | 564 |
|
550 | 565 | # make sure we have the appropriate properties |
@@ -822,28 +837,6 @@ def make_user_anonymous(self): |
822 | 837 | self.userid = self.db.user.lookup('anonymous') |
823 | 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 | 840 | def standard_message(self, to, subject, body, author=None): |
848 | 841 | '''Send a standard email message from Roundup. |
849 | 842 |
|
|
0 commit comments