def collection_post(self): # Note: needs sending with 'Content-Type: application/json' body = self.request.json_body user = models.User(body['name']) DBSession.add(user) # We flush the session to generate an id that we can add to the response DBSession.flush() return dict(user)
def collection_post(self): # Note: needs sending with 'Content-Type: application/json' body = self.request.json_body identity = models.Label(body['identifier'], body['user_id']) DBSession.add(identifier) # Check for valid user_id # We flush the session to generate an id that we can add to the response DBSession.flush() return dict(identifier)
def collection_post(self): # Note: needs sending with 'Content-Type: application/json' body = self.request.json_body note = models.Note(body['title']) if 'content' in body: note.content = body['content'] if 'creator_id' in body: # The id takes preference note.creator_id = body['creator_id'] elif 'created_by' in body: name = body['created_by'] user = DBSession.query(models.User).filter_by(name=name).first() if user: note.creator_id = user.id if 'labels' in body and len(body['labels']) > 0: lids = [x['id'] for x in body['labels']] label_query = DBSession.query(models.Label).filter(models.Label.id.in_(lids)) note.labels = label_query.all() DBSession.add(note) # We flush the session to generate an id that we can add to the response DBSession.flush() return dict(note)
def collection_post(self): # Note: needs sending with 'Content-Type: application/json' body = self.request.json_body note = models.Note(body['title']) if 'content' in body: note.content = body['content'] if 'creator_id' in body: # The id takes preference note.creator_id = body['creator_id'] elif 'created_by' in body: name = body['created_by'] user = DBSession.query(models.User).filter_by(name=name).first() if user: note.creator_id = user.id if 'labels' in body and len(body['labels']) > 0: lids = [x['id'] for x in body['labels']] labels = DBSession.query(models.Label).filter(models.Label.id.in_(lids)) note.labels = list(labels) DBSession.add(note) # We flush the session to generate an id that we can add to the response DBSession.flush() return dict(note)