Mercurial > p > roundup > code
comparison roundup/cgi/actions.py @ 4083:bbab97f8ffb2
XMLRPC improvements:
* Add support for actions to XMLRPC interface.
* Provide bridge so user actions may be executed
either via CGI or XMLRPC.
* Adjust XMLRPC tests to recent work.
* Cleanup.
| author | Stefan Seefeld <stefan@seefeld.name> |
|---|---|
| date | Fri, 27 Feb 2009 17:46:47 +0000 |
| parents | 0b89c94a2387 |
| children | 34434785f308 |
comparison
equal
deleted
inserted
replaced
| 4082:5eb5f7e66c37 | 4083:bbab97f8ffb2 |
|---|---|
| 1 #$Id: actions.py,v 1.73 2008-08-18 05:04:01 richard Exp $ | |
| 2 | |
| 3 import re, cgi, StringIO, urllib, time, random, csv, codecs | 1 import re, cgi, StringIO, urllib, time, random, csv, codecs |
| 4 | 2 |
| 5 from roundup import hyperdb, token, date, password | 3 from roundup import hyperdb, token, date, password |
| 4 from roundup.actions import Action as BaseAction | |
| 6 from roundup.i18n import _ | 5 from roundup.i18n import _ |
| 7 import roundup.exceptions | 6 import roundup.exceptions |
| 8 from roundup.cgi import exceptions, templating | 7 from roundup.cgi import exceptions, templating |
| 9 from roundup.mailgw import uidFromAddress | 8 from roundup.mailgw import uidFromAddress |
| 10 | 9 |
| 989 for itemid in klass.filter(matches, filterspec, sort, group): | 988 for itemid in klass.filter(matches, filterspec, sort, group): |
| 990 self.client._socket_op(writer.writerow, [str(klass.get(itemid, col)) for col in columns]) | 989 self.client._socket_op(writer.writerow, [str(klass.get(itemid, col)) for col in columns]) |
| 991 | 990 |
| 992 return '\n' | 991 return '\n' |
| 993 | 992 |
| 993 | |
| 994 class Bridge(BaseAction): | |
| 995 """Make roundup.actions.Action executable via CGI request. | |
| 996 | |
| 997 Using this allows users to write actions executable from multiple frontends. | |
| 998 CGI Form content is translated into a dictionary, which then is passed as | |
| 999 argument to 'handle()'. XMLRPC requests have to pass this dictionary | |
| 1000 directly. | |
| 1001 """ | |
| 1002 | |
| 1003 def __init__(self, *args): | |
| 1004 | |
| 1005 # As this constructor is callable from multiple frontends, each with | |
| 1006 # different Action interfaces, we have to look at the arguments to | |
| 1007 # figure out how to complete construction. | |
| 1008 if (len(args) == 1 and | |
| 1009 hasattr(args[0], '__class__') and | |
| 1010 args[0].__class__.__name__ == 'Client'): | |
| 1011 self.cgi = True | |
| 1012 self.execute = self.execute_cgi | |
| 1013 self.client = args[0] | |
| 1014 self.form = self.client.form | |
| 1015 else: | |
| 1016 self.cgi = False | |
| 1017 | |
| 1018 def execute_cgi(self): | |
| 1019 args = {} | |
| 1020 for key in self.form.keys(): | |
| 1021 args[key] = self.form.getvalue(key) | |
| 1022 self.permission(args) | |
| 1023 return self.handle(args) | |
| 1024 | |
| 1025 def permission(self, args): | |
| 1026 """Raise Unauthorised if the current user is not allowed to execute | |
| 1027 this action. Users may override this method.""" | |
| 1028 | |
| 1029 pass | |
| 1030 | |
| 1031 def handle(self, args): | |
| 1032 | |
| 1033 raise NotImplementedError | |
| 1034 | |
| 994 # vim: set filetype=python sts=4 sw=4 et si : | 1035 # vim: set filetype=python sts=4 sw=4 et si : |
