comparison roundup/cgi/form_parser.py @ 5381:0942fe89e82e

Python 3 preparation: change "x.has_key(y)" to "y in x". (Also likewise "not in" where appropriate.) Tool-generated patch.
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 22:08:17 +0000
parents 198b6e810c67
children 23b8e6067f7c
comparison
equal deleted inserted replaced
5380:64c4e43fbb84 5381:0942fe89e82e
269 if not create and nodeid is None: 269 if not create and nodeid is None:
270 continue 270 continue
271 271
272 # get more info about the class, and the current set of 272 # get more info about the class, and the current set of
273 # form props for it 273 # form props for it
274 if not all_propdef.has_key(cn): 274 if cn not in all_propdef:
275 all_propdef[cn] = cl.getprops() 275 all_propdef[cn] = cl.getprops()
276 propdef = all_propdef[cn] 276 propdef = all_propdef[cn]
277 if not all_props.has_key(this): 277 if this not in all_props:
278 all_props[this] = {} 278 all_props[this] = {}
279 props = all_props[this] 279 props = all_props[this]
280 if not got_props.has_key(this): 280 if this not in got_props:
281 got_props[this] = {} 281 got_props[this] = {}
282 282
283 # is this a link command? 283 # is this a link command?
284 if d['link']: 284 if d['link']:
285 value = [] 285 value = []
292 292
293 # get details of linked class 293 # get details of linked class
294 lcn = m.group(1) 294 lcn = m.group(1)
295 lcl = self.db.classes[lcn] 295 lcl = self.db.classes[lcn]
296 lnodeid = m.group(2) 296 lnodeid = m.group(2)
297 if not all_propdef.has_key(lcn): 297 if lcn not in all_propdef:
298 all_propdef[lcn] = lcl.getprops() 298 all_propdef[lcn] = lcl.getprops()
299 if not all_props.has_key((lcn, lnodeid)): 299 if (lcn, lnodeid) not in all_props:
300 all_props[(lcn, lnodeid)] = {} 300 all_props[(lcn, lnodeid)] = {}
301 if not got_props.has_key((lcn, lnodeid)): 301 if (lcn, lnodeid) not in got_props:
302 got_props[(lcn, lnodeid)] = {} 302 got_props[(lcn, lnodeid)] = {}
303 303
304 # make sure the link property is valid 304 # make sure the link property is valid
305 if (not isinstance(propdef[propname], hyperdb.Multilink) and 305 if (not isinstance(propdef[propname], hyperdb.Multilink) and
306 not isinstance(propdef[propname], hyperdb.Link)): 306 not isinstance(propdef[propname], hyperdb.Link)):
321 'which doesn\'t exist') % { 321 'which doesn\'t exist') % {
322 'property':propname}) 322 'property':propname})
323 if m.group('classname'): 323 if m.group('classname'):
324 this = (m.group('classname'), m.group('id')) 324 this = (m.group('classname'), m.group('id'))
325 entry = m.group('propname') 325 entry = m.group('propname')
326 if not all_required.has_key(this): 326 if this not in all_required:
327 all_required[this] = [] 327 all_required[this] = []
328 all_required[this].append(entry) 328 all_required[this].append(entry)
329 continue 329 continue
330 330
331 # see if we're performing a special multilink action 331 # see if we're performing a special multilink action
334 mlaction = 'remove' 334 mlaction = 'remove'
335 elif d['add']: 335 elif d['add']:
336 mlaction = 'add' 336 mlaction = 'add'
337 337
338 # does the property exist? 338 # does the property exist?
339 if not propdef.has_key(propname): 339 if propname not in propdef:
340 if mlaction != 'set': 340 if mlaction != 'set':
341 raise FormError (self._('You have submitted a %(action)s ' 341 raise FormError (self._('You have submitted a %(action)s '
342 'action for the property "%(property)s" ' 342 'action for the property "%(property)s" '
343 'which doesn\'t exist') % { 343 'which doesn\'t exist') % {
344 'action': mlaction, 'property':propname}) 344 'action': mlaction, 'property':propname})
404 elif d['file']: 404 elif d['file']:
405 # This needs to be a Multilink and is checked above 405 # This needs to be a Multilink and is checked above
406 fcn = 'file' 406 fcn = 'file'
407 fcl = self.db.classes[fcn] 407 fcl = self.db.classes[fcn]
408 fpropname = 'content' 408 fpropname = 'content'
409 if not all_propdef.has_key(fcn): 409 if fcn not in all_propdef:
410 all_propdef[fcn] = fcl.getprops() 410 all_propdef[fcn] = fcl.getprops()
411 fpropdef = all_propdef[fcn] 411 fpropdef = all_propdef[fcn]
412 have_file = [] 412 have_file = []
413 for n, v in enumerate(value): 413 for n, v in enumerate(value):
414 if not hasattr(v, 'filename'): 414 if not hasattr(v, 'filename'):
438 # now use that list of ids to modify the multilink 438 # now use that list of ids to modify the multilink
439 if mlaction == 'set': 439 if mlaction == 'set':
440 value = l 440 value = l
441 else: 441 else:
442 # we're modifying the list - get the current list of ids 442 # we're modifying the list - get the current list of ids
443 if props.has_key(propname): 443 if propname in props:
444 existing = props[propname] 444 existing = props[propname]
445 elif nodeid and not nodeid.startswith('-'): 445 elif nodeid and not nodeid.startswith('-'):
446 existing = cl.get(nodeid, propname, []) 446 existing = cl.get(nodeid, propname, [])
447 else: 447 else:
448 existing = [] 448 existing = []
498 try: 498 try:
499 existing = cl.get(nodeid, propname) 499 existing = cl.get(nodeid, propname)
500 except KeyError: 500 except KeyError:
501 # this might be a new property for which there is 501 # this might be a new property for which there is
502 # no existing value 502 # no existing value
503 if not propdef.has_key(propname): 503 if propname not in propdef:
504 raise 504 raise
505 except IndexError as message: 505 except IndexError as message:
506 raise FormError(str(message)) 506 raise FormError(str(message))
507 507
508 # make sure the existing multilink is sorted. We must 508 # make sure the existing multilink is sorted. We must
551 s = [] 551 s = []
552 for thing, required in all_required.items(): 552 for thing, required in all_required.items():
553 # register the values we got 553 # register the values we got
554 got = got_props.get(thing, {}) 554 got = got_props.get(thing, {})
555 for entry in required[:]: 555 for entry in required[:]:
556 if got.has_key(entry): 556 if entry in got:
557 required.remove(entry) 557 required.remove(entry)
558 558
559 # If a user doesn't have edit permission for a given property, 559 # If a user doesn't have edit permission for a given property,
560 # but the property is already set in the database, we don't 560 # but the property is already set in the database, we don't
561 # require a value. 561 # require a value.
602 # if content is not defined remove all fields that 602 # if content is not defined remove all fields that
603 # reference that file. 603 # reference that file.
604 # if content is defined, let it pass through even if 604 # if content is defined, let it pass through even if
605 # content is empty. Yes people can upload/create 605 # content is empty. Yes people can upload/create
606 # empty files. 606 # empty files.
607 if props.has_key('content'): 607 if 'content' in props:
608 if id is not None and \ 608 if id is not None and \
609 not id.startswith('-') and \ 609 not id.startswith('-') and \
610 not props['content']: 610 not props['content']:
611 # This is an existing file with emtpy content 611 # This is an existing file with emtpy content
612 # value in the form. 612 # value in the form.
620 return all_props, all_links 620 return all_props, all_links
621 621
622 def parse_file(self, fpropdef, fprops, v): 622 def parse_file(self, fpropdef, fprops, v):
623 # try to determine the file content-type 623 # try to determine the file content-type
624 fn = v.filename.split('\\')[-1] 624 fn = v.filename.split('\\')[-1]
625 if fpropdef.has_key('name'): 625 if 'name' in fpropdef:
626 fprops['name'] = fn 626 fprops['name'] = fn
627 # use this info as the type/filename properties 627 # use this info as the type/filename properties
628 if fpropdef.has_key('type'): 628 if 'type' in fpropdef:
629 if hasattr(v, 'type') and v.type: 629 if hasattr(v, 'type') and v.type:
630 fprops['type'] = v.type 630 fprops['type'] = v.type
631 elif mimetypes.guess_type(fn)[0]: 631 elif mimetypes.guess_type(fn)[0]:
632 fprops['type'] = mimetypes.guess_type(fn)[0] 632 fprops['type'] = mimetypes.guess_type(fn)[0]
633 else: 633 else:

Roundup Issue Tracker: http://roundup-tracker.org/