コード例 #1
0
ファイル: frames.py プロジェクト: bmwasaru/Openframe-Server
 def get(self, frame_id=None):
     if frame_id:
         print('get frame: ' + frame_id)
         frame_resp = Frames.get_by_id(frame_id)
     else:
         frame_resp = Frames.get_all()
     _unify_ids(frame_resp)
     self.write(dumps(frame_resp))
コード例 #2
0
ファイル: frames.py プロジェクト: bmwasaru/Openframe-Server
 def post(self):
     print('create frame item')
     doc = json_decode(self.request.body.decode('utf-8'))
     result = Frames.insert(doc)
     if not result:
         print('Problem inserting new frame')
     _unify_ids(doc)
     self.write(dumps(doc))
コード例 #3
0
 def get_by_id(frame_id):
     """
     Get a frame by id
     """
     fid = frame_id if not ObjectId.is_valid(frame_id) else ObjectId(frame_id)
     resp = Frames.collection.find_one({"_id": fid})
     _unify_ids(resp)
     return resp
コード例 #4
0
ファイル: frames.py プロジェクト: bmwasaru/Openframe-Server
 def put(self, frame_id):
     print('update frame: ' + frame_id)
     doc = json_decode(self.request.body.decode('utf-8'))
     result = Frames.update_by_id(frame_id, doc)
     if not result:
         print('Problem updating frame')
     _unify_ids(result)
     self.write(dumps(result))
コード例 #5
0
 def put(self, content_id):
     print('update content: ' + content_id)
     doc = json_decode(self.request.body.decode('utf-8'))
     result = Content.update_by_id(content_id, doc)
     if not result:
         print('Problem updating content')
     _unify_ids(result)
     self.write(dumps(result))
コード例 #6
0
 def post(self):
     print('create content item')
     doc = json_decode(self.request.body.decode('utf-8'))
     content_id = Content.insert(doc)
     if not content_id:
         print('problem inserting new content')
     _unify_ids(doc)
     self.write(dumps(doc))
コード例 #7
0
ファイル: frames.py プロジェクト: bmwasaru/Openframe-Server
 def get(self, username):
     connected = self.get_argument('connected', None)
     if username:
         resp = Frames.get_by_username(username, connected)
     else:
         print('username missing')
         resp = {'error': 'username required'}
     _unify_ids(resp)
     self.write(dumps(resp))
コード例 #8
0
    def get(self, content_id=None):
        if content_id:
            print('get content: ' + content_id)
            content_resp = Content.get_by_id(content_id)

        else:
            content_resp = Content.get_all()
        _unify_ids(content_resp)
        self.write(dumps(content_resp))
コード例 #9
0
 def get_by_owner(username, connected=None):
     """
     Get a list of frames which user owns
     """
     query = {"owner": username}
     if connected is not None:
         query["connected"] = connected
     resp = list(Frames.collection.find(query))
     _unify_ids(resp)
     return resp
コード例 #10
0
 def get_by_username(username, connected=None):
     """
     Get a list of frames which user has access to
     """
     query = {"users": username}
     if connected is not None:
         query["connected"] = connected
     resp = list(Frames.collection.find(query))
     _unify_ids(resp)
     return resp
コード例 #11
0
    def update_by_id(frame_id, doc):
        """
        Update a frame by id, returning the updated doc
        """
        fid = frame_id if not ObjectId.is_valid(frame_id) else ObjectId(frame_id)
        # do not update the _id, ever.
        if "_id" in doc:
            del doc["_id"]

        resp = Frames.collection.find_one_and_update({"_id": fid}, {"$set": doc}, return_document=ReturnDocument.AFTER)
        _unify_ids(resp)
        return resp
コード例 #12
0
 def get_public(connected=None, username=None):
     """
     Get a list of frames which are publicly visible (for mirroring)
     """
     # Only return frames that are not mirroring another frame.
     query = {"settings.visible": True, "$or": [{"mirroring": {"$exists": False}}, {"mirroring": None}]}
     if username is not None:
         # don't include public frames for the supplied username
         query["users"] = {"$ne": username}
     if connected is not None:
         # only select connected frames
         query["connected"] = connected
     resp = list(Frames.collection.find(query))
     _unify_ids(resp)
     return resp
コード例 #13
0
 def delete_by_id(frame_id):
     """
     Update a frame by id, returning the updated doc
     """
     fid = frame_id if not ObjectId.is_valid(frame_id) else ObjectId(frame_id)
     resp = Frames.collection.delete_one({"_id": fid})
     return _unify_ids(resp)
コード例 #14
0
 def get_mirroring(frame_id):
     """
     Get a list of all the frames that are mirroring frame_id
     """
     query = {"mirroring": frame_id}
     resp = list(Frames.collection.find(query))
     return _unify_ids(resp)
コード例 #15
0
 def get_by_username(username):
     """
     Get a list of content which user has access to
     """
     query = {'users': username}
     resp = list(Content.collection.find(query))
     return _unify_ids(resp)
コード例 #16
0
 def get_by_id(content_id):
     """
     Get content by id
     """
     cid = content_id
     # if content_id is valid ObjectId, assume it is one
     # and find using an ObjectId
     if ObjectId.is_valid(content_id):
         cid = ObjectId(content_id)
     resp = Content.collection.find_one({'_id': cid})
     return _unify_ids(resp)
コード例 #17
0
    def update_mirroring(frame_id, mirroring_id):
        """
        Set a frame to mirror another by id
        """
        fid = frame_id if not ObjectId.is_valid(frame_id) else ObjectId(frame_id)
        mid = frame_id if not ObjectId.is_valid(mirroring_id) else ObjectId(mirroring_id)

        doc = {"mirroring": mid}

        resp = Frames.collection.find_one_and_update({"_id": fid}, {"$set": doc}, return_document=ReturnDocument.AFTER)

        return _unify_ids(resp)
コード例 #18
0
 def update_by_id(content_id, doc):
     """
     Update content by id, returning the updated doc
     """
     cid = content_id
     # if content_id is valid ObjectId, assume it is one
     # and find using an ObjectId
     if ObjectId.is_valid(content_id):
         cid = ObjectId(content_id)
     resp = Content.collection.find_one_and_update(
         {"_id": cid}, {"$set": doc}, return_document=ReturnDocument.AFTER)
     return _unify_ids(resp)
コード例 #19
0
ファイル: frames.py プロジェクト: bmwasaru/Openframe-Server
 def get(self, frame_id=None):
     # frames = Frames.get_public(username=self.current_user)
     frames = Frames.get_public()
     _unify_ids(frames)
     self.write(dumps(frames))
コード例 #20
0
ファイル: frames.py プロジェクト: bmwasaru/Openframe-Server
 def get(self, owner):
     connected = self.get_argument('connected', None)
     resp = Frames.get_by_owner(owner, connected)
     _unify_ids(resp)
     self.write(dumps(resp))
コード例 #21
0
 def insert(doc):
     """
     Insert a doc into the content collection
     """
     resp = Content.collection.insert_one(doc)
     return _unify_ids(resp)