88
99__all__ = ['Action' , 'ShowAction' , 'RetireAction' , 'SearchAction' ,
1010 'EditCSVAction' , 'EditItemAction' , 'PassResetAction' ,
11- 'ConfRegoAction' , 'RegisterAction' , 'LoginAction' , 'LogoutAction' ]
11+ 'ConfRegoAction' , 'RegisterAction' , 'LoginAction' , 'LogoutAction' ,
12+ 'NewItemAction' ]
1213
1314# used by a couple of routines
1415chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
@@ -275,39 +276,7 @@ def permission(self):
275276 return self .db .security .hasPermission ('Edit' , self .client .userid ,
276277 self .client .classname )
277278
278- class EditItemAction (Action ):
279- def handle (self ):
280- """Perform an edit of an item in the database.
281-
282- See parsePropsFromForm and _editnodes for special variables.
283-
284- """
285- props , links = self .client .parsePropsFromForm ()
286-
287- # handle the props
288- try :
289- message = self ._editnodes (props , links )
290- except (ValueError , KeyError , IndexError ), message :
291- self .client .error_message .append (_ ('Apply Error: ' ) + str (message ))
292- return
293-
294- # commit now that all the tricky stuff is done
295- self .db .commit ()
296-
297- # redirect to the item's edit page
298- # redirect to finish off
299- url = self .base + self .classname
300- # note that this action might have been called by an index page, so
301- # we will want to include index-page args in this URL too
302- if self .nodeid is not None :
303- url += self .nodeid
304- url += '?@ok_message=%s&@template=%s' % (urllib .quote (message ),
305- urllib .quote (self .template ))
306- if self .nodeid is None :
307- req = templating .HTMLRequest (self )
308- url += '&' + req .indexargs_href ('' , {})[1 :]
309- raise Redirect , url
310-
279+ class _EditAction (Action ):
311280 def editItemPermission (self , props ):
312281 """Determine whether the user has permission to edit this item.
313282
@@ -333,37 +302,6 @@ def editItemPermission(self, props):
333302 return 1
334303 return 0
335304
336- def newItemAction (self ):
337- ''' Add a new item to the database.
338-
339- This follows the same form as the editItemAction, with the same
340- special form values.
341- '''
342- # parse the props from the form
343- try :
344- props , links = self .parsePropsFromForm (create = True )
345- except (ValueError , KeyError ), message :
346- self .error_message .append (_ ('Error: ' ) + str (message ))
347- return
348-
349- # handle the props - edit or create
350- try :
351- # when it hits the None element, it'll set self.nodeid
352- messages = self ._editnodes (props , links )
353-
354- except (ValueError , KeyError , IndexError ), message :
355- # these errors might just be indicative of user dumbness
356- self .error_message .append (_ ('Error: ' ) + str (message ))
357- return
358-
359- # commit now that all the tricky stuff is done
360- self .db .commit ()
361-
362- # redirect to the new item's page
363- raise Redirect , '%s%s%s?@ok_message=%s&@template=%s' % (self .base ,
364- self .classname , self .nodeid , urllib .quote (messages ),
365- urllib .quote (self .template ))
366-
367305 def newItemPermission (self , props ):
368306 """Determine whether the user has permission to create (edit) this item.
369307
@@ -446,7 +384,7 @@ def _editnodes(self, all_props, all_links, newids=None):
446384 # make a new node
447385 newid = self ._createnode (cn , props )
448386 if nodeid is None :
449- self .client . nodeid = newid
387+ self .nodeid = newid
450388 nodeid = newid
451389
452390 # and some nice feedback for the user
@@ -495,6 +433,71 @@ def _createnode(self, cn, props):
495433 # create the node and return its id
496434 cl = self .db .classes [cn ]
497435 return cl .create (** props )
436+
437+ class EditItemAction (_EditAction ):
438+ def handle (self ):
439+ """Perform an edit of an item in the database.
440+
441+ See parsePropsFromForm and _editnodes for special variables.
442+
443+ """
444+ props , links = self .client .parsePropsFromForm ()
445+
446+ # handle the props
447+ try :
448+ message = self ._editnodes (props , links )
449+ except (ValueError , KeyError , IndexError ), message :
450+ self .client .error_message .append (_ ('Apply Error: ' ) + str (message ))
451+ return
452+
453+ # commit now that all the tricky stuff is done
454+ self .db .commit ()
455+
456+ # redirect to the item's edit page
457+ # redirect to finish off
458+ url = self .base + self .classname
459+ # note that this action might have been called by an index page, so
460+ # we will want to include index-page args in this URL too
461+ if self .nodeid is not None :
462+ url += self .nodeid
463+ url += '?@ok_message=%s&@template=%s' % (urllib .quote (message ),
464+ urllib .quote (self .template ))
465+ if self .nodeid is None :
466+ req = templating .HTMLRequest (self )
467+ url += '&' + req .indexargs_href ('' , {})[1 :]
468+ raise Redirect , url
469+
470+ class NewItemAction (_EditAction ):
471+ def handle (self ):
472+ ''' Add a new item to the database.
473+
474+ This follows the same form as the EditItemAction, with the same
475+ special form values.
476+ '''
477+ # parse the props from the form
478+ try :
479+ props , links = self .client .parsePropsFromForm (create = True )
480+ except (ValueError , KeyError ), message :
481+ self .error_message .append (_ ('Error: ' ) + str (message ))
482+ return
483+
484+ # handle the props - edit or create
485+ try :
486+ # when it hits the None element, it'll set self.nodeid
487+ messages = self ._editnodes (props , links )
488+
489+ except (ValueError , KeyError , IndexError ), message :
490+ # these errors might just be indicative of user dumbness
491+ self .error_message .append (_ ('Error: ' ) + str (message ))
492+ return
493+
494+ # commit now that all the tricky stuff is done
495+ self .db .commit ()
496+
497+ # redirect to the new item's page
498+ raise Redirect , '%s%s%s?@ok_message=%s&@template=%s' % (self .base ,
499+ self .classname , self .nodeid , urllib .quote (messages ),
500+ urllib .quote (self .template ))
498501
499502class PassResetAction (Action ):
500503 def handle (self ):
0 commit comments