def _set_password(self, core_id, password): session = r.Session() result = r.search_single('user', "_core_id = ?", values = [core_id], session = session) save_set = SaveItem(result.results[0], session) save_set.set_value('password', password) errors = save_set.save()
def save_row(self, node_token, session = None): """Saves an individual database row. Subforms are saved last and the subforms call this method in their own form instance. relation_attr is the attribute on the newly created object that should have the parent_obj as its value. This is to allow sqlalchemy to determine the ids for new objects. Both form and subform manipulate the same data which is stored agianst the node.""" data = node_token[self.name] id = data.get('id') root = data.get('__root') if id: # existing record try: result = r.search_single(self.table, dict(id = id), session = session) save_set = SaveItem(result.results[0], session) save_set.new = False except custom_exceptions.SingleResultError: form.errors[root] = 'record not found' raise version = data.get("_version") save_set.set_value("_version", version) else: # new record (create blank one) _core_id = data.get('__id') save_set = SaveNew(r, self.table, session) if _core_id: save_set.set_value('_core_id', _core_id) session = save_set.session save_set.new = True ## prepare save data for normal fields # TD we loop through the form items and try to save them for form_item in self.form_items: form_item.save_page_item(node_token, save_set, data, session) errors = save_set.save() # FIXME get errors working again :) #### errors = {} #### try: #### session.save_or_update(obj) #### except formencode.Invalid, e: #### print "failed to save\n%s" % e.msg #### for key, value in e.error_dict.items(): #### errors[key] = value.msg #### errors[root] = errors return (save_set, errors)