Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 2934:c8ee5907f1e2
pychecker cleanup
| author | Alexander Smishlajev <a1s@users.sourceforge.net> |
|---|---|
| date | Thu, 18 Nov 2004 17:20:40 +0000 |
| parents | 9ecca789544f |
| children | 3dca84b1a8f5 |
comparison
equal
deleted
inserted
replaced
| 2933:6574d6736b57 | 2934:c8ee5907f1e2 |
|---|---|
| 1 #$Id: actions.py,v 1.38 2004-11-18 15:58:23 a1s Exp $ | 1 #$Id: actions.py,v 1.39 2004-11-18 17:20:40 a1s Exp $ |
| 2 | 2 |
| 3 import re, cgi, StringIO, urllib, Cookie, time, random | 3 import re, cgi, StringIO, urllib, Cookie, time, random |
| 4 | 4 |
| 5 from roundup import hyperdb, token, date, password, rcsv, exceptions | 5 from roundup import hyperdb, token, date, password, rcsv, exceptions |
| 6 from roundup.i18n import _ | 6 from roundup.i18n import _ |
| 26 self.userid = client.userid | 26 self.userid = client.userid |
| 27 self.base = client.base | 27 self.base = client.base |
| 28 self.user = client.user | 28 self.user = client.user |
| 29 self.context = templating.context(client) | 29 self.context = templating.context(client) |
| 30 | 30 |
| 31 def handle(self): | |
| 32 """Action handler procedure""" | |
| 33 raise NotImplementedError | |
| 34 | |
| 31 def execute(self): | 35 def execute(self): |
| 32 """Execute the action specified by this object.""" | 36 """Execute the action specified by this object.""" |
| 33 self.permission() | 37 self.permission() |
| 34 return self.handle() | 38 return self.handle() |
| 35 | 39 |
| 66 return self.client.translator.gettext(msgid) | 70 return self.client.translator.gettext(msgid) |
| 67 | 71 |
| 68 _ = gettext | 72 _ = gettext |
| 69 | 73 |
| 70 class ShowAction(Action): | 74 class ShowAction(Action): |
| 71 def handle(self, typere=re.compile('[@:]type'), | 75 |
| 72 numre=re.compile('[@:]number')): | 76 typere=re.compile('[@:]type') |
| 77 numre=re.compile('[@:]number') | |
| 78 | |
| 79 def handle(self): | |
| 73 """Show a node of a particular class/id.""" | 80 """Show a node of a particular class/id.""" |
| 74 t = n = '' | 81 t = n = '' |
| 75 for key in self.form.keys(): | 82 for key in self.form.keys(): |
| 76 if typere.match(key): | 83 if self.typere.match(key): |
| 77 t = self.form[key].value.strip() | 84 t = self.form[key].value.strip() |
| 78 elif numre.match(key): | 85 elif self.numre.match(key): |
| 79 n = self.form[key].value.strip() | 86 n = self.form[key].value.strip() |
| 80 if not t: | 87 if not t: |
| 81 raise ValueError, self._('No type specified') | 88 raise ValueError, self._('No type specified') |
| 82 if not n: | 89 if not n: |
| 83 raise exceptions.SeriousError, self._('No ID entered') | 90 raise exceptions.SeriousError, self._('No ID entered') |
| 118 | 125 |
| 119 class SearchAction(Action): | 126 class SearchAction(Action): |
| 120 name = 'search' | 127 name = 'search' |
| 121 permissionType = 'View' | 128 permissionType = 'View' |
| 122 | 129 |
| 123 def handle(self, wcre=re.compile(r'[\s,]+')): | 130 def handle(self): |
| 124 """Mangle some of the form variables. | 131 """Mangle some of the form variables. |
| 125 | 132 |
| 126 Set the form ":filter" variable based on the values of the filter | 133 Set the form ":filter" variable based on the values of the filter |
| 127 variables - if they're set to anything other than "dontcare" then add | 134 variables - if they're set to anything other than "dontcare" then add |
| 128 them to :filter. | 135 them to :filter. |
| 315 # all OK | 322 # all OK |
| 316 self.db.commit() | 323 self.db.commit() |
| 317 | 324 |
| 318 self.client.ok_message.append(self._('Items edited OK')) | 325 self.client.ok_message.append(self._('Items edited OK')) |
| 319 | 326 |
| 320 class EditCommon: | 327 class EditCommon(Action): |
| 321 '''Utility methods for editing.''' | 328 '''Utility methods for editing.''' |
| 322 def _editnodes(self, all_props, all_links, newids=None): | 329 |
| 330 def _editnodes(self, all_props, all_links): | |
| 323 ''' Use the props in all_props to perform edit and creation, then | 331 ''' Use the props in all_props to perform edit and creation, then |
| 324 use the link specs in all_links to do linking. | 332 use the link specs in all_links to do linking. |
| 325 ''' | 333 ''' |
| 326 # figure dependencies and re-work links | 334 # figure dependencies and re-work links |
| 327 deps = {} | 335 deps = {} |
| 469 Base behaviour is to check the user can edit this class. No additional | 477 Base behaviour is to check the user can edit this class. No additional |
| 470 property checks are made. | 478 property checks are made. |
| 471 """ | 479 """ |
| 472 return self.hasPermission('Create', self.classname) | 480 return self.hasPermission('Create', self.classname) |
| 473 | 481 |
| 474 class EditItemAction(EditCommon, Action): | 482 class EditItemAction(EditCommon): |
| 475 def lastUserActivity(self): | 483 def lastUserActivity(self): |
| 476 if self.form.has_key(':lastactivity'): | 484 if self.form.has_key(':lastactivity'): |
| 477 d = date.Date(self.form[':lastactivity'].value) | 485 d = date.Date(self.form[':lastactivity'].value) |
| 478 elif self.form.has_key('@lastactivity'): | 486 elif self.form.has_key('@lastactivity'): |
| 479 d = date.Date(self.form['@lastactivity'].value) | 487 d = date.Date(self.form['@lastactivity'].value) |
| 489 return activity | 497 return activity |
| 490 | 498 |
| 491 def detectCollision(self, user_activity, node_activity): | 499 def detectCollision(self, user_activity, node_activity): |
| 492 if user_activity: | 500 if user_activity: |
| 493 return user_activity < node_activity | 501 return user_activity < node_activity |
| 502 else: | |
| 503 return 0 | |
| 494 | 504 |
| 495 def handleCollision(self): | 505 def handleCollision(self): |
| 496 self.client.template = 'collision' | 506 self.client.template = 'collision' |
| 497 | 507 |
| 498 def handle(self): | 508 def handle(self): |
| 533 if self.nodeid is None: | 543 if self.nodeid is None: |
| 534 req = templating.HTMLRequest(self.client) | 544 req = templating.HTMLRequest(self.client) |
| 535 url += '&' + req.indexargs_href('', {})[1:] | 545 url += '&' + req.indexargs_href('', {})[1:] |
| 536 raise exceptions.Redirect, url | 546 raise exceptions.Redirect, url |
| 537 | 547 |
| 538 class NewItemAction(EditCommon, Action): | 548 class NewItemAction(EditCommon): |
| 539 def handle(self): | 549 def handle(self): |
| 540 ''' Add a new item to the database. | 550 ''' Add a new item to the database. |
| 541 | 551 |
| 542 This follows the same form as the EditItemAction, with the same | 552 This follows the same form as the EditItemAction, with the same |
| 543 special form values. | 553 special form values. |
| 671 if not self.client.standard_message([address], subject, body): | 681 if not self.client.standard_message([address], subject, body): |
| 672 return | 682 return |
| 673 | 683 |
| 674 self.client.ok_message.append(self._('Email sent to %s') % address) | 684 self.client.ok_message.append(self._('Email sent to %s') % address) |
| 675 | 685 |
| 676 class RegoCommon: | 686 class RegoCommon(Action): |
| 677 def finishRego(self): | 687 def finishRego(self): |
| 678 # log the new user in | 688 # log the new user in |
| 679 self.client.userid = self.userid | 689 self.client.userid = self.userid |
| 680 user = self.client.user = self.db.user.get(self.userid, 'username') | 690 user = self.client.user = self.db.user.get(self.userid, 'username') |
| 681 # re-open the database for real, using the user | 691 # re-open the database for real, using the user |
| 700 <body><p><a href="%s">%s</a></p> | 710 <body><p><a href="%s">%s</a></p> |
| 701 <script type="text/javascript"> | 711 <script type="text/javascript"> |
| 702 window.setTimeout('window.location = "%s"', 1000); | 712 window.setTimeout('window.location = "%s"', 1000); |
| 703 </script>'''%(message, url, message, url) | 713 </script>'''%(message, url, message, url) |
| 704 | 714 |
| 705 class ConfRegoAction(RegoCommon, Action): | 715 class ConfRegoAction(RegoCommon): |
| 706 def handle(self): | 716 def handle(self): |
| 707 """Grab the OTK, use it to load up the new user details.""" | 717 """Grab the OTK, use it to load up the new user details.""" |
| 708 try: | 718 try: |
| 709 # pull the rego information out of the otk database | 719 # pull the rego information out of the otk database |
| 710 self.userid = self.db.confirm_registration(self.form['otk'].value) | 720 self.userid = self.db.confirm_registration(self.form['otk'].value) |
| 711 except (ValueError, KeyError), message: | 721 except (ValueError, KeyError), message: |
| 712 self.client.error_message.append(str(message)) | 722 self.client.error_message.append(str(message)) |
| 713 return | 723 return |
| 714 self.finishRego() | 724 self.finishRego() |
| 715 | 725 |
| 716 class RegisterAction(RegoCommon, EditCommon, Action): | 726 class RegisterAction(RegoCommon, EditCommon): |
| 717 name = 'register' | 727 name = 'register' |
| 718 permissionType = 'Create' | 728 permissionType = 'Create' |
| 719 | 729 |
| 720 def handle(self): | 730 def handle(self): |
| 721 """Attempt to create a new user based on the contents of the form | 731 """Attempt to create a new user based on the contents of the form |
| 756 # commit now that all the tricky stuff is done | 766 # commit now that all the tricky stuff is done |
| 757 self.db.commit() | 767 self.db.commit() |
| 758 | 768 |
| 759 # finish off by logging the user in | 769 # finish off by logging the user in |
| 760 self.userid = self.nodeid | 770 self.userid = self.nodeid |
| 761 return self.finishRego() | 771 self.finishRego() |
| 772 return | |
| 762 | 773 |
| 763 # generate the one-time-key and store the props for later | 774 # generate the one-time-key and store the props for later |
| 764 for propname, proptype in self.db.user.getprops().items(): | 775 for propname, proptype in self.db.user.getprops().items(): |
| 765 value = user_props.get(propname, None) | 776 value = user_props.get(propname, None) |
| 766 if value is None: | 777 if value is None: |
| 867 if not self.hasPermission("Web Access"): | 878 if not self.hasPermission("Web Access"): |
| 868 raise exceptions.LoginError, self._( | 879 raise exceptions.LoginError, self._( |
| 869 "You do not have permission to login") | 880 "You do not have permission to login") |
| 870 | 881 |
| 871 def verifyPassword(self, userid, password): | 882 def verifyPassword(self, userid, password): |
| 872 ''' Verify the password that the user has supplied | 883 '''Verify the password that the user has supplied''' |
| 873 ''' | 884 stored = self.db.user.get(userid, 'password') |
| 874 stored = self.db.user.get(self.client.userid, 'password') | |
| 875 if password == stored: | 885 if password == stored: |
| 876 return 1 | 886 return 1 |
| 877 if not password and not stored: | 887 if not password and not stored: |
| 878 return 1 | 888 return 1 |
| 879 return 0 | 889 return 0 |
| 917 for itemid in klass.filter(matches, filterspec, sort, group): | 927 for itemid in klass.filter(matches, filterspec, sort, group): |
| 918 writer.writerow([str(klass.get(itemid, col)) for col in columns]) | 928 writer.writerow([str(klass.get(itemid, col)) for col in columns]) |
| 919 | 929 |
| 920 return '\n' | 930 return '\n' |
| 921 | 931 |
| 922 # vim: set filetype=python ts=4 sw=4 et si : | 932 # vim: set filetype=python sts=4 sw=4 et si : |
