Esempio n. 1
0
    def obj_get(self, request=None, **kwargs):

        try:
            query = dict(_id=ObjectId(kwargs['pk']))
        except InvalidId:
            raise BadRequest('Invalid ObjectId provided')

        mongo_item = self._collection.find_one(query)

        if mongo_item is None:
            raise NotFound('Invalid resource lookup data provided')

        obj = MongoObj(initial=mongo_item)
        obj.uuid = kwargs['pk']
        return obj
Esempio n. 2
0
    def obj_create(self, bundle, request=None, **kwargs):

        bundle = self.full_hydrate(bundle)

        if "bundle" not in bundle.data and "reviews" not in bundle.data:
            kq = KnowledgeQuantum.objects.get(id=int(bundle.data["kq"]))

            if "unit" not in bundle.data:
                bundle.data["unit"] = kq.unit.id

            if "course" not in bundle.data:
                bundle.data["course"] = kq.unit.course.id

        if "created" not in bundle.data:
            bundle.data["created"] = datetime.utcnow()

        bundle.data["reviews"] = 0
        bundle.data["author_reviews"] = 0
        bundle.data["author"] = request.user.id

        _id = self._collection.insert(bundle.data, safe=True)

        bundle.obj = MongoObj(bundle.data)
        self.send_created_signal(request.user.id, bundle.obj)
        bundle.obj.uuid = str(_id)

        bundle.uuid = bundle.obj.uuid

        return bundle
Esempio n. 3
0
    def obj_create(self, bundle, request=None, **kwargs):

        bundle = self.full_hydrate(bundle)

        if "bundle" not in bundle.data and "reviews" not in bundle.data:
            kq = KnowledgeQuantum.objects.get(id=int(bundle.data["kq"]))

            if "unit" not in bundle.data:
                bundle.data["unit"] = kq.unit.id

            if "course" not in bundle.data:
                bundle.data["course"] = kq.unit.course.id

        if "created" not in bundle.data:
            bundle.data["created"] = datetime.utcnow()

        bundle.data["reviews"] = 0
        bundle.data["author_reviews"] = 0
        bundle.data["author"] = request.user.id
        from moocng.peerreview.utils import insert_p2p_if_does_not_exists_or_raise
        _id = insert_p2p_if_does_not_exists_or_raise(bundle.data,
                                                     self._collection)

        bundle.obj = MongoObj(bundle.data)
        self.send_created_signal(request.user.id, bundle.obj)
        bundle.obj.uuid = str(_id)

        bundle.uuid = bundle.obj.uuid

        return bundle
Esempio n. 4
0
    def obj_get_list(self, request=None, **kwargs):
        user = self._get_or_create_user(request, **kwargs)
        question_id = request.GET.get('question', None)

        results = []
        if question_id is None:
            for qid, question in user['questions'].items():
                if qid == question_id:
                    obj = MongoObj(initial=question)
                    obj.uuid = question_id
                    results.append(obj)
        else:
            question = user['questions'].get(question_id, None)
            if question is not None:
                obj = MongoObj(initial=question)
                obj.uuid = question_id
                results.append(obj)

        return results
Esempio n. 5
0
    def obj_get_list(self, request=None, **kwargs):
        mongo_query = {"author": request.GET.get("author", request.user.id)}

        for key in self._meta.filtering.keys():
            if key in request.GET:
                try:
                    mongo_query[key] = int(request.GET.get(key))
                except ValueError:
                    mongo_query[key] = request.GET.get(key)

        query_results = self._collection.find(mongo_query)

        results = []

        for query_item in query_results:
            obj = MongoObj(initial=query_item)
            obj.uuid = query_item["_id"]
            results.append(obj)

        return results
Esempio n. 6
0
    def obj_get_list(self, request=None, **kwargs):
        mongo_query = {"author": request.GET.get('author', request.user.id)}

        for key in self._meta.filtering.keys():
            if key in request.GET:
                try:
                    mongo_query[key] = int(request.GET.get(key))
                except ValueError:
                    mongo_query[key] = request.GET.get(key)

        query_results = self._collection.find(mongo_query)

        results = []

        for query_item in query_results:
            obj = MongoObj(initial=query_item)
            obj.uuid = query_item["_id"]
            results.append(obj)

        return results
Esempio n. 7
0
    def obj_get_list(self, request=None, **kwargs):
        user = self._get_or_create_user(request, **kwargs)
        question_id = request.GET.get('question', None)

        results = []
        if question_id is None:
            for qid, question in user['questions'].items():
                if qid == question_id:
                    obj = MongoObj(initial=question)
                    obj.uuid = question_id
                    results.append(obj)
        else:
            question = user['questions'].get(question_id, None)
            if question is not None:
                obj = MongoObj(initial=question)
                obj.uuid = question_id
                results.append(obj)

        return results