From: jlgijsbers Date: Sat, 14 Feb 2004 01:17:38 +0000 (+0000) Subject: Fix last commit to make editing/creating items work again. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=46e8f3985f24ebb148a0ff4e5b08b6ea23a365ca;p=roundup.git Fix last commit to make editing/creating items work again. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@2080 57a73879-2fb5-44c3-a270-3262357dd7e2 --- diff --git a/roundup/cgi/actions.py b/roundup/cgi/actions.py index afc6a10..de4143d 100755 --- a/roundup/cgi/actions.py +++ b/roundup/cgi/actions.py @@ -8,7 +8,8 @@ from roundup.mailgw import uidFromAddress __all__ = ['Action', 'ShowAction', 'RetireAction', 'SearchAction', 'EditCSVAction', 'EditItemAction', 'PassResetAction', - 'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction'] + 'ConfRegoAction', 'RegisterAction', 'LoginAction', 'LogoutAction', + 'NewItemAction'] # used by a couple of routines chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' @@ -275,39 +276,7 @@ class EditCSVAction(Action): return self.db.security.hasPermission('Edit', self.client.userid, self.client.classname) -class EditItemAction(Action): - def handle(self): - """Perform an edit of an item in the database. - - See parsePropsFromForm and _editnodes for special variables. - - """ - props, links = self.client.parsePropsFromForm() - - # handle the props - try: - message = self._editnodes(props, links) - except (ValueError, KeyError, IndexError), message: - self.client.error_message.append(_('Apply Error: ') + str(message)) - return - - # commit now that all the tricky stuff is done - self.db.commit() - - # redirect to the item's edit page - # redirect to finish off - url = self.base + self.classname - # note that this action might have been called by an index page, so - # we will want to include index-page args in this URL too - if self.nodeid is not None: - url += self.nodeid - url += '?@ok_message=%s&@template=%s'%(urllib.quote(message), - urllib.quote(self.template)) - if self.nodeid is None: - req = templating.HTMLRequest(self) - url += '&' + req.indexargs_href('', {})[1:] - raise Redirect, url - +class _EditAction(Action): def editItemPermission(self, props): """Determine whether the user has permission to edit this item. @@ -333,37 +302,6 @@ class EditItemAction(Action): return 1 return 0 - def newItemAction(self): - ''' Add a new item to the database. - - This follows the same form as the editItemAction, with the same - special form values. - ''' - # parse the props from the form - try: - props, links = self.parsePropsFromForm(create=True) - except (ValueError, KeyError), message: - self.error_message.append(_('Error: ') + str(message)) - return - - # handle the props - edit or create - try: - # when it hits the None element, it'll set self.nodeid - messages = self._editnodes(props, links) - - except (ValueError, KeyError, IndexError), message: - # these errors might just be indicative of user dumbness - self.error_message.append(_('Error: ') + str(message)) - return - - # commit now that all the tricky stuff is done - self.db.commit() - - # redirect to the new item's page - raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base, - self.classname, self.nodeid, urllib.quote(messages), - urllib.quote(self.template)) - def newItemPermission(self, props): """Determine whether the user has permission to create (edit) this item. @@ -446,7 +384,7 @@ class EditItemAction(Action): # make a new node newid = self._createnode(cn, props) if nodeid is None: - self.client.nodeid = newid + self.nodeid = newid nodeid = newid # and some nice feedback for the user @@ -495,6 +433,71 @@ class EditItemAction(Action): # create the node and return its id cl = self.db.classes[cn] return cl.create(**props) + +class EditItemAction(_EditAction): + def handle(self): + """Perform an edit of an item in the database. + + See parsePropsFromForm and _editnodes for special variables. + + """ + props, links = self.client.parsePropsFromForm() + + # handle the props + try: + message = self._editnodes(props, links) + except (ValueError, KeyError, IndexError), message: + self.client.error_message.append(_('Apply Error: ') + str(message)) + return + + # commit now that all the tricky stuff is done + self.db.commit() + + # redirect to the item's edit page + # redirect to finish off + url = self.base + self.classname + # note that this action might have been called by an index page, so + # we will want to include index-page args in this URL too + if self.nodeid is not None: + url += self.nodeid + url += '?@ok_message=%s&@template=%s'%(urllib.quote(message), + urllib.quote(self.template)) + if self.nodeid is None: + req = templating.HTMLRequest(self) + url += '&' + req.indexargs_href('', {})[1:] + raise Redirect, url + +class NewItemAction(_EditAction): + def handle(self): + ''' Add a new item to the database. + + This follows the same form as the EditItemAction, with the same + special form values. + ''' + # parse the props from the form + try: + props, links = self.client.parsePropsFromForm(create=True) + except (ValueError, KeyError), message: + self.error_message.append(_('Error: ') + str(message)) + return + + # handle the props - edit or create + try: + # when it hits the None element, it'll set self.nodeid + messages = self._editnodes(props, links) + + except (ValueError, KeyError, IndexError), message: + # these errors might just be indicative of user dumbness + self.error_message.append(_('Error: ') + str(message)) + return + + # commit now that all the tricky stuff is done + self.db.commit() + + # redirect to the new item's page + raise Redirect, '%s%s%s?@ok_message=%s&@template=%s'%(self.base, + self.classname, self.nodeid, urllib.quote(messages), + urllib.quote(self.template)) class PassResetAction(Action): def handle(self): diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index c15b3f1..7722865 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.157 2004-02-13 01:32:37 richard Exp $ +# $Id: client.py,v 1.158 2004-02-14 01:17:38 jlgijsbers Exp $ """WWW request handler (also used in the stand-alone server). """ @@ -522,7 +522,7 @@ class Client: actions = ( ('edit', EditItemAction), ('editcsv', EditCSVAction), - ('new', EditItemAction), + ('new', NewItemAction), ('register', RegisterAction), ('confrego', ConfRegoAction), ('passrst', PassResetAction),