1- # $Id: client.py,v 1.54 2002-10-17 06:11:25 richard Exp $
1+ # $Id: client.py,v 1.55 2002-10-18 03:34:58 richard Exp $
22
33__doc__ = """
44WWW request handler (also used in the stand-alone server).
@@ -663,6 +663,11 @@ def editItemAction(self):
663663 :required=property,property,...
664664 The named properties are required to be filled in the form.
665665
666+ :remove:<propname>=id(s)
667+ The ids will be removed from the multilink property.
668+ :add:<propname>=id(s)
669+ The ids will be added to the multilink property.
670+
666671 '''
667672 cl = self .db .classes [self .classname ]
668673
@@ -1141,6 +1146,12 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
11411146
11421147 If a ":required" parameter is supplied, then the names property values
11431148 must be supplied or a ValueError will be raised.
1149+
1150+ Other special form values:
1151+ :remove:<propname>=id(s)
1152+ The ids will be removed from the multilink property.
1153+ :add:<propname>=id(s)
1154+ The ids will be added to the multilink property.
11441155 '''
11451156 required = []
11461157 if form .has_key (':required' ):
@@ -1154,19 +1165,37 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
11541165 keys = form .keys ()
11551166 properties = cl .getprops ()
11561167 for key in keys :
1157- if not properties .has_key (key ):
1168+ # see if we're performing a special multilink action
1169+ mlaction = 'set'
1170+ if key .startswith (':remove:' ):
1171+ propname = key [8 :]
1172+ mlaction = 'remove'
1173+ elif key .startswith (':add:' ):
1174+ propname = key [5 :]
1175+ mlaction = 'add'
1176+ else :
1177+ propname = key
1178+
1179+
1180+ # does the property exist?
1181+ if not properties .has_key (propname ):
1182+ if mlaction != 'set' :
1183+ raise ValueError , 'You have submitted a remove action for' \
1184+ ' the property "%s" which doesn\' t exist' % propname
11581185 continue
1159- proptype = properties [key ]
1186+ proptype = properties [propname ]
11601187
11611188 # Get the form value. This value may be a MiniFieldStorage or a list
11621189 # of MiniFieldStorages.
11631190 value = form [key ]
11641191
1192+ print (mlaction , propname , value )
1193+
11651194 # make sure non-multilinks only get one value
11661195 if not isinstance (proptype , hyperdb .Multilink ):
11671196 if isinstance (value , type ([])):
11681197 raise ValueError , 'You have submitted more than one value' \
1169- ' for the %s property' % key
1198+ ' for the %s property' % propname
11701199 # we've got a MiniFieldStorage, so pull out the value and strip
11711200 # surrounding whitespace
11721201 value = value .value .strip ()
@@ -1180,23 +1209,23 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
11801209 if not value :
11811210 # ignore empty password values
11821211 continue
1183- if not form .has_key ('%s:confirm' % key ):
1212+ if not form .has_key ('%s:confirm' % propname ):
11841213 raise ValueError , 'Password and confirmation text do not match'
1185- confirm = form ['%s:confirm' % key ]
1214+ confirm = form ['%s:confirm' % propname ]
11861215 if isinstance (confirm , type ([])):
11871216 raise ValueError , 'You have submitted more than one value' \
1188- ' for the %s property' % key
1217+ ' for the %s property' % propname
11891218 if value != confirm .value :
11901219 raise ValueError , 'Password and confirmation text do not match'
11911220 value = password .Password (value )
11921221 elif isinstance (proptype , hyperdb .Date ):
11931222 if value :
1194- value = date .Date (form [ key ] .value .strip ())
1223+ value = date .Date (value .value .strip ())
11951224 else :
11961225 continue
11971226 elif isinstance (proptype , hyperdb .Interval ):
11981227 if value :
1199- value = date .Interval (form [ key ] .value .strip ())
1228+ value = date .Interval (value .value .strip ())
12001229 else :
12011230 continue
12021231 elif isinstance (proptype , hyperdb .Link ):
@@ -1211,12 +1240,13 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
12111240 value = db .classes [link ].lookup (value )
12121241 except KeyError :
12131242 raise ValueError , _ ('property "%(propname)s": '
1214- '%(value)s not a %(classname)s' )% {'propname' :key ,
1215- 'value' : value , 'classname' : link }
1243+ '%(value)s not a %(classname)s' )% {
1244+ 'propname' : propname , 'value' : value ,
1245+ 'classname' : link }
12161246 except TypeError , message :
12171247 raise ValueError , _ ('you may only enter ID values '
12181248 'for property "%(propname)s": %(message)s' )% {
1219- 'propname' :key , 'message' : message }
1249+ 'propname' : propname , 'message' : message }
12201250 elif isinstance (proptype , hyperdb .Multilink ):
12211251 if isinstance (value , type ([])):
12221252 # it's a list of MiniFieldStorages
@@ -1235,37 +1265,66 @@ def parsePropsFromForm(db, cl, form, nodeid=0, num_re=re.compile('^\d+$')):
12351265 except KeyError :
12361266 raise ValueError , _ ('property "%(propname)s": '
12371267 '"%(value)s" not an entry of %(classname)s' )% {
1238- 'propname' :key , 'value' : entry , 'classname' : link }
1268+ 'propname' : propname , 'value' : entry ,
1269+ 'classname' : link }
12391270 except TypeError , message :
12401271 raise ValueError , _ ('you may only enter ID values '
12411272 'for property "%(propname)s": %(message)s' )% {
1242- 'propname' :key , 'message' : message }
1273+ 'propname' : propname , 'message' : message }
12431274 l .append (entry )
12441275 l .sort ()
1245- value = l
1276+
1277+ # now use that list of ids to modify the multilink
1278+ if mlaction == 'set' :
1279+ value = l
1280+ else :
1281+ # we're modifying the list - get the current list of ids
1282+ try :
1283+ existing = cl .get (nodeid , propname )
1284+ except KeyError :
1285+ existing = []
1286+ if mlaction == 'remove' :
1287+ # remove - handle situation where the id isn't in the list
1288+ for entry in l :
1289+ try :
1290+ existing .remove (entry )
1291+ except ValueError :
1292+ raise ValueError , _ ('property "%(propname)s": '
1293+ '"%(value)s" not currently in list' )% {
1294+ 'propname' : propname , 'value' : entry }
1295+ else :
1296+ # add - easy, just don't dupe
1297+ for entry in l :
1298+ if entry not in existing :
1299+ existing .append (entry )
1300+ value = existing
1301+ value .sort ()
1302+
12461303 elif isinstance (proptype , hyperdb .Boolean ):
1247- props [key ] = value = value .lower () in ('yes' , 'true' , 'on' , '1' )
1304+ value = value .lower () in ('yes' , 'true' , 'on' , '1' )
1305+ props [propname ] = value
12481306 elif isinstance (proptype , hyperdb .Number ):
1249- props [key ] = value = int (value )
1307+ props [propname ] = value = int (value )
12501308
12511309 # register this as received if required?
1252- if key in required and value is not None :
1253- required .remove (key )
1310+ if propname in required and value is not None :
1311+ required .remove (propname )
12541312
12551313 # get the old value
12561314 if nodeid :
12571315 try :
1258- existing = cl .get (nodeid , key )
1316+ existing = cl .get (nodeid , propname )
12591317 except KeyError :
12601318 # this might be a new property for which there is no existing
12611319 # value
1262- if not properties .has_key (key ): raise
1320+ if not properties .has_key (propname ):
1321+ raise
12631322
12641323 # if changed, set it
12651324 if value != existing :
1266- props [key ] = value
1325+ props [propname ] = value
12671326 else :
1268- props [key ] = value
1327+ props [propname ] = value
12691328
12701329 # see if all the required properties have been supplied
12711330 if required :
0 commit comments