Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     label_id = int(self.request.matchdict['id'])
     label = DBSession.query(models.Label).get(label_id)
     if not label:
         raise HTTPNotFound
     body = self.request.json_body
     if 'name' in body:
         label.name = body['name']
     if 'notes' in body:
         note_ids = [n['id'] for n in body['notes']]
         note_query = DBSession.query(models.Note).filter(models.Note.id.in_(note_ids))
         label.notes = note_query.all()
Exemple #6
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     identity_id = int(self.request.matchdict['id'])
     identity = DBSession.query(models.Identity).get(identity_id)
     if not identity:
         raise HTTPNotFound
     body = self.request.json_body
     if 'identifier' in body:
         identity.identifier = body['identifier']
     if 'user_id' in body:
         user = DBSession.query(models.User).get(body['user_id'])
         if user:
             identity.user = user
         else:
             raise HTTPBadRequest('Request body contains an invalid user id')
Exemple #7
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     identity_id = int(self.request.matchdict['id'])
     identity = DBSession.query(models.Identity).get(identity_id)
     if not identity:
         raise HTTPNotFound
     body = self.request.json_body
     if 'identifier' in body:
         identity.identifier = body['identifier']
     if 'user_id' in body:
         user = DBSession.query(models.User).get(body['user_id'])
         if user:
             identity.user = user
         else:
             raise HTTPBadRequest('Request body contains an invalid user id')
Exemple #8
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     note_id = int(self.request.matchdict['id'])
     note = DBSession.query(models.Note).get(note_id)
     if not note:
         raise HTTPNotFound
     body = self.request.json_body
     if 'title' in body:
         note.title = body['title']
     if 'content' in body:
         note.content = body['content']
     # We ignore created_on, created_by, creator_id as they are 'immutable'
     if 'labels' in body:
         lids = [l['id'] for l in body['labels']]
         label_query = DBSession.query(models.Label).filter(models.Label.id.in_(lids))
         note.labels = label_query.all()
Exemple #9
0
 def get(self):
     note_id = int(self.request.matchdict['id'])
     note = DBSession.query(models.Note).get(note_id)
     if note:
         return dict(note)
     else:
         raise HTTPNotFound
Exemple #10
0
 def get(self):
     identity_id = int(self.request.matchdict['id'])
     identity = DBSession.query(models.Identity).get(identity_id)
     if identity:
         return dict(identity)
     else:
         raise HTTPNotFound
Exemple #11
0
 def get(self):
     note_id = int(self.request.matchdict['id'])
     note = DBSession.query(models.Note).get(note_id)
     if note:
         return dict(note)
     else:
         raise HTTPNotFound
Exemple #12
0
 def get(self):
     user_id = int(self.request.matchdict['id'])
     user = DBSession.query(models.User).get(user_id)
     if user:
         return dict(user)
     else:
         raise HTTPNotFound
Exemple #13
0
 def get(self):
     label_id = int(self.request.matchdict['id'])
     label = DBSession.query(models.Label).get(label_id)
     if label:
         return dict(label)
     else:
         raise HTTPNotFound
Exemple #14
0
 def get(self):
     user_id = int(self.request.matchdict['id'])
     user = DBSession.query(models.User).get(user_id)
     if user:
         return dict(user)
     else:
         raise HTTPNotFound
Exemple #15
0
 def get(self):
     label_id = int(self.request.matchdict['id'])
     label = DBSession.query(models.Label).get(label_id)
     if label:
         return dict(label)
     else:
         raise HTTPNotFound
Exemple #16
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     label_id = int(self.request.matchdict['id'])
     label = DBSession.query(models.Label).get(label_id)
     if not label:
         raise HTTPNotFound
     body = self.request.json_body
     if 'name' in body:
         label.name = body['name']
     if 'notes' in body:
         label.notes = []
         for note_dict in body['notes']:
             note = DBSession.query(models.Note).get(note_dict['id'])
             if not note:
                 raise HTTPBadRequest('Request body contains an invalid note id')
             label.notes.append(note)
Exemple #17
0
 def get(self):
     identity_id = int(self.request.matchdict['id'])
     identity = DBSession.query(models.Identity).get(identity_id)
     if identity:
         return dict(identity)
     else:
         raise HTTPNotFound
Exemple #18
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     user_id = int(self.request.matchdict['id'])
     user = DBSession.query(models.User).get(user_id)
     if not user:
         raise HTTPNotFound
     body = self.request.json_body
     if 'name' in body:
         user.name = body['name']
     if 'notes' in body:
         note_ids = [n['id'] for n in body['notes']]
         note_query = DBSession.query(models.Note).filter(models.Note.id.in_(note_ids))
         user.notes = note_query.all()
     if 'identities' in body:
         id_query = DBSession.query(models.Identity)
         id_query.filter(models.Identity.id.in_(body['identities']))
         user.identities = id_query.all()
Exemple #19
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     note_id = int(self.request.matchdict['id'])
     note = DBSession.query(models.Note).get(note_id)
     if not note:
         raise HTTPNotFound
     body = self.request.json_body
     if 'title' in body:
         note.title = body['title']
     if 'content' in body:
         note.content = body['content']
     # We ignore created_on, created_by, creator_id as they are 'immutable'
     if 'labels' in body:
         user.labels = []
         for label_dict in body['labels']:
             label = DBSession.query(models.Label).get(label_dict['id'])
             if not label:
                 raise HTTPBadRequest('Request body contains an invalid note id')
             user.labels.append(label)
Exemple #20
0
 def put(self):
     # Note: needs sending with 'Content-Type: application/json'
     user_id = int(self.request.matchdict['id'])
     user = DBSession.query(models.User).get(user_id)
     if not user:
         raise HTTPNotFound
     body = self.request.json_body
     if 'name' in body:
         user.name = body['name']
     if 'notes' in body:
         user.notes = []
         for note_dict in body['notes']:
             note = DBSession.query(models.Note).get(note_dict['id'])
             if not note:
                 raise HTTPBadRequest('Request body contains an invalid note id')
             user.notes.append(note)
     if 'identities' in body:
         user.identities = []
         for ident_id in body['identities']:
             identity = DBSession.query(models.Identity).get(ident_id)
             if not identity:
                 raise HTTPBadRequest('Request body contains an invalid identity id')
             user.identities.append(identity)
Exemple #21
0
 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)
Exemple #22
0
 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)
Exemple #23
0
 def delete(self):
     note_id = int(self.request.matchdict['id'])
     DBSession.query(models.Note).filter(models.Note.id==note_id).delete()
Exemple #24
0
 def collection_get(self):
     labels = DBSession.query(models.Label).all()
     label_list = [{'id': l.id, 'name': l.name, 'note_count': len(l.notes)} for l in labels]
     return {'labels': label_list}
Exemple #25
0
 def collection_get(self):
     notes = DBSession.query(models.Note).all()
     note_list = [{'id': n.id, 'title': n.title} for n in notes]
     return {'notes': note_list}
Exemple #26
0
 def delete(self):
     user_id = int(self.request.matchdict['id'])
     DBSession.query(models.User).filter(models.User.id==user_id).delete()
Exemple #27
0
 def collection_get(self):
     users = DBSession.query(models.User).all()
     user_list = [{'id': u.id, 'name': u.name} for u in users]
     return {'users': user_list}
Exemple #28
0
 def collection_get(self):
     identities = DBSession.query(models.Identity).all()
     identity_list = [{'id': i.id, 'identifier': i.identifier, 'user_id': i.user_id} for i in identities]
     return {'identities': identity_list}
Exemple #29
0
 def delete(self):
     label_id = int(self.request.matchdict['id'])
     DBSession.query(models.Label).filter(models.Label.id==label_id).delete()
Exemple #30
0
 def delete(self):
     label_id = int(self.request.matchdict['id'])
     DBSession.query(models.Label).filter(models.Label.id==label_id).delete()
Exemple #31
0
 def collection_get(self):
     labels = DBSession.query(models.Label).all()
     label_list = [{'id': l.id, 'name': l.name, 'note_count': len(l.notes)} for l in labels]
     return {'labels': label_list}
Exemple #32
0
 def delete(self):
     user_id = int(self.request.matchdict['id'])
     DBSession.query(models.User).filter(models.User.id==user_id).delete()
Exemple #33
0
 def collection_get(self):
     notes = DBSession.query(models.Note).all()
     note_list = [{'id': n.id, 'title': n.title} for n in notes]
     return {'notes': note_list}
Exemple #34
0
 def collection_get(self):
     identities = DBSession.query(models.Identity).all()
     identity_list = [{'id': i.id, 'identifier': i.identifier, 'user_id': i.user_id} for i in identities]
     return {'identities': identity_list}
Exemple #35
0
 def collection_get(self):
     users = DBSession.query(models.User).all()
     user_list = [{'id': u.id, 'name': u.name} for u in users]
     return {'users': user_list}
Exemple #36
0
 def delete(self):
     note_id = int(self.request.matchdict['id'])
     DBSession.query(models.Note).filter(models.Note.id==note_id).delete()