def section_save(section_key_us=None): form = SectionFormAdmin() # form validation if not form.validate_on_submit(): return "VALIDATION_ERROR", 400 # get and validate parent section if form.parent_section.data == '/': parent_section_key = None else: parent_section = ndb.Key( urlsafe=form.parent_section.data).get() or abort(404) parent_section_key = parent_section.key # section instance if section_key_us: # edit # print 'admin section save EDIT' section = ndb.Key(urlsafe=section_key_us).get() or abort(404) else: # new # print 'admin section save NEW' section = Section() # update data g.cache.clear() section.parent_section = parent_section_key section.set_name(form.name.data, g.language) section.put() return 'ok'