def deserialize_project(datum, projectSchema, nbhd): # type: (dict, NewProjectSchema, Neighborhood) -> object p = projectSchema.deserialize(datum) p = Object(p) # convert from dict to something with attr-access # generate a shortname, and try to make it unique if not p.shortname: max_shortname_len = 15 # maybe more depending on NeighborhoodProjectShortNameValidator impl, but this is safe shortname = orig_shortname = make_shortname(p.name, max_shortname_len) for i in range(1, 10): try: ProjectRegistrationProvider.get( ).shortname_validator.to_python(shortname, neighborhood=nbhd) except formencode.api.Invalid: if len(orig_shortname) == max_shortname_len - 1: shortname = orig_shortname + str(i) else: shortname = orig_shortname[:max_shortname_len - 1] + str(i) else: # we're good! break p.shortname = shortname return p