def __init__(self, data={}):
        serializer = IncomingDataSerializer(data=data)

        if serializer.is_valid():
            client = DBHandler.get_database_client()
            db = client.test
            education = db.education
            user_id = data.get("user_info")

            #searched_user_id = education.find_one({"_id":ObjectId(user_id)})
            searched_user_id = education.find_one(
                {"_id": ObjectId("5e08ce2ffebc801b83cd2579")})

            invitation_list = searched_user_id.get("invitations")

            for stored_invitation in invitation_list:
                #print(str(stored_invitation["_id"]))
                #print(stored_invitation["_id"])
                if (str(stored_invitation["_id"]) ==
                        serializer.validated_data.get("invitation_id")):
                    self.response = json.loads(
                        json.dumps(stored_invitation, default=str))
                    return
                else:
                    self.response = json.loads(
                        json.dumps({"message": "something went wrong."},
                                   default=str))
        else:
            self.response = serializer.errors
Example #2
0
    def __init__(self, data={}):
        serializer = InvitePeopleSerializer(data=data)
        if serializer.is_valid():
            users_incoming_phone_no = serializer.validated_data.get("phone_no")

            # query database for dashboard info
            #str(users.find_one({"$and":[{"email": "*****@*****.**"},{"password": "******"}]}))
            client = DBHandler.get_database_client()
            db = client.test
            education = db.education
            user_id = data.get("user_info")
            users = db.users

            serched_phone_number = users.find_one(
                {"phone_no": users_incoming_phone_no})

            if (serched_phone_number is None):
                # todo store user phon
                new_user_id = users.insert_one({
                    "phone_no":
                    users_incoming_phone_no
                }).inserted_id
            else:
                new_user_id = serched_phone_number.get("_id")

            invitation_document_object = {
                "_id": ObjectId(),
                "phone_no": serializer.validated_data.get("phone_no"),
                "expired_date": datetime.now() + timedelta(hours=48),
                "invitation_from": user_id,
                "institute_id": serializer.validated_data.get("institute_id"),
                "designations": serializer.validated_data.get("designations"),
                "verification_code": randint(1000, 9999)
            }
            #print(new_user_id)
            res = education.update_one(
                {"_id": ObjectId(new_user_id)},
                {"$push": {
                    "invitations": invitation_document_object
                }},
                upsert=True)

            invitation_id = education.find_one({"_id": ObjectId(new_user_id)})
            pprint(invitation_id)
            pprint(res.modified_count)

            #sms queue collection
            sms_queue = db.sms_queue
            sms_id = sms_queue.insert_one({
                "_id": ObjectId(),
                "invitation_id": invitation_id,
                "send_status": "pending"
            }).inserted_id

            if res.matched_count > 0:
                self.response = {"s": "success"}
            else:
                self.response = {"message": "something went wrong"}
        else:
            self.response = serializer.errors
Example #3
0
    def __init__(self, data={}):
        #data["associated"] = "5ddd62ffd8639286d599dcd6"
        #data["designation"] = "5ddd62ffd8639286d599dcd7"
        #data["tag"] = "5ddd62ffd8639286d599dcd8"
        serializer = TasksSerializer(data=data)
        if serializer.is_valid():
            #query database for dashboard info
            client = DBHandler.get_database_client()
            db = client.test
            education = db.education
            user_id = data.get("user_info")

            query_result = education.find_one({"_id": ObjectId(user_id)})

            print("showing results")
            pprint(query_result)

            for associate in query_result["associated"]:
                if serializer.validated_data.get("associated") == str(
                        associate.get("_id")):
                    for designation in associate["designations"]:
                        if serializer.validated_data.get("designation") == str(
                                designation.get("_id")):
                            for tag in designation["tags"]:
                                if serializer.validated_data.get("tag") == str(
                                        tag.get("_id")):
                                    self.response = json.loads(
                                        json.dumps(tag, default=str))
                                    return

            self.response = json.loads(
                json.dumps({"error": "retriving_tast_list"}, default=str))
        else:
            self.response = serializer.errors
Example #4
0
 def __init__(self, data={}):
     #query database for dashboard info
     client = DBHandler.get_database_client()
     db = client.test
     education = db.education
     user_id = data.get("user_info")
     #pprint(user_id)
     query_result = education.find_one({"_id": ObjectId(user_id)}, {
         "_id": 0,
         "associated.designations.tags": 0
     })
     #print(json.dumps(query_result, cls=JSONEncoder))
     self.response = json.loads(json.dumps(query_result, default=str))
Example #5
0
    def __init__(self, data={}):
        client = DBHandler.get_database_client()
        db = client.test

        attendance_object = {
            "association_id": "",
            "year": "",
            "month": "",
            "day": "",
            "status": "",
        }

        self.response = {
            "res": db.attendance.insert_one(attendance_object).inserted_id
        }
Example #6
0
    def __init__(self, data={}):
        #serialize data
        serializer = listPeopleSerializer(data=data["data"])

        if serializer.is_valid():
            client = DBHandler.get_database_client()
            db = client.test
            result = db.education.find({
                "associated.institute_id" : ObjectId(serializer.validated_data.get("institute_id")),
                "associated.designations.meta_data.class" : serializer.validated_data.get("meta_data").get("class")
            },{
                "associated.designations.meta_data":1
            })
            pprint(result.count())
            self.response = {"result":json.loads(json.dumps(list(result), default=str))}
        else:
            self.response = {"error": serializer.errors}
    def __init__(self, data={}):

        client = DBHandler.get_database_client()
        db = client.test
        education = db.education
        user_id = data.get("user_info")

        query_result = education.find_one(
            {
                "id" : objectId(user_id)
            },
            {
                "invitations" : 1
            }
            )
        self.response=json.loads(json.dumps(query_result, default=str))
             
    def __init__(self, data={}):
        #query database for dashboard info
        #str(users.find_one({"$and":[{"email": "*****@*****.**"},{"password": "******"}]}))
        client = DBHandler.get_database_client()
        db = client.test
        education = db.education
        user_id = data.get("user_info")
        pprint(user_id)
        query_result = education.find_one(
              {"_id" : ObjectId(user_id), "associated": {"$elemMatch":{"_id": data.get(associated),"$elemMatch":{"designation":"parent"}},""},
              {"_id":1,
              "tags":1}
        )

        #this is to avoid ObjectId not serializer error
        query_result["_id"] = user_id
        # query_result = { 
        #     "_id":ObjectId(user_id),
        #     "associated": [
        #     {"id": 1, "short_name":"BRUR", "long_name":"Begum Rokeya University, Rangpur", "designation":"Parent",
        #     "status": "joined",
        #     "join_date": "July 1st 2019",
        #     "allowed_services": [
        #     { "id": 1, "designation": "Parent" },
        #     { "id": 2, "designation": "Teacher" } ]},
        #     {"id": 2, "short_name":"RGC", "long_name":"Rangpur Government College, Rangpur", "designation":"Parent",
        #     "status": "joined",
        #     "join_date": "July 1st 2019",
        #     "allowed_services": [
        #     { "id": 1, "designation": "Parent" },
        #     { "id": 2, "designation": "Teacher" } ]},
        #     ]
        # }

        #query database for associates
        #{"_id":ObjectId(user_id)}
        #post_id = education.insert_one(query_result).inserted_id
        



        self.response=query_result
Example #9
0
 def __init__(self, data={}):
     #data["associated"] = "5ddd62ffd8639286d599dcd6"
     #data["designation"] = "5ddd62ffd8639286d599dcd7"
     serializer = TagSerializer(data=data)
     if serializer.is_valid():
         #query database for dashboard info
         client = DBHandler.get_database_client()
         db = client.test
         education = db.education
         user_id = data.get("user_info")
         #pprint(user_id)
         query_result = education.find_one(
             {
                 "_id":
                 ObjectId(user_id),
                 "associated._id":
                 ObjectId(serializer.validated_data.get("associated")),
                 "associated.designations._id":
                 ObjectId(serializer.validated_data.get("designation"))
             }, {"associated.designations.tags.tasks": 0})
         #this is to avoid ObjectId not serializer error
         #query_result["_id"] = user_id
         print("showing results")
         pprint(query_result)
         for associate in query_result["associated"]:
             print(associate.get("_id"))
             if data["associated"] == str(associate.get("_id")):
                 for designation in associate["designations"]:
                     if data["designation"] == str(designation.get("_id")):
                         self.response = json.loads(
                             json.dumps(designation, default=str))
                         return
         self.response = json.loads(
             json.dumps({"error": "does not exist"}, default=str))
     else:
         self.response = serializer.errors
Example #10
0
    def __init__(self, data={}):

        serializer = AddPeopleSerializer(data=data["data"])

        if serializer.is_valid():
            #debug
            #self.response = serializer.validated_data
            #return
            '''
            1. query user by phone no
            2. if not found create an user in user collection
            3. create a document in education collection with user id
                attributes:
                
            4. Enque to sms/email send system
            '''
            client = DBHandler.get_database_client()
            db = client.test
            user_collection = db.users

            user_query_result = user_collection.find_one(
                {"phone_no": serializer.validated_data.get("phone_no")})
            print("querying user")
            if user_query_result is None:
                #insert user in user collection and get the id
                invited_user_id = user_collection.insert_one({
                    "name":
                    serializer.validated_data.get("name"),
                    "phone_no":
                    serializer.validated_data.get("phone_no")
                }).inserted_id
            else:
                invited_user_id = user_query_result["_id"]

            print("got user id")
            #inserting into education collection

            ppageid = db.public_pages.find_one({
                "_id":
                ObjectId(serializer.validated_data.get("institute_id"))
            })
            if (ppageid is None):
                self.response = {
                    "status_code": "page_not_found",
                    "default_description": "no such thing exits in the system"
                }
                return

            stored_designations = ppageid.get("designation")
            incoming_designations = serializer.validated_data.get(
                "designations")
            matched_designations = []

            for designations in incoming_designations:
                for designation in stored_designations:
                    #pprint(designation)
                    if (designations == designation["title"]):
                        matched_designations.append(designation)
                    else:
                        matched_designations.append({
                            "title": designations,
                            "meta_data": {
                                "roll": 1234,
                                "class": 10,
                                "session": "2011-12"
                            }
                        })

            associate_institute_document_object = {
                "_id": ObjectId(),
                "institute_id": ppageid.get("_id"),
                "long_name": ppageid.get("page_title"),
                "description": ppageid.get("description"),
                "designations": matched_designations,
                "invitor": data.get("user_info")
            }

            education_collection = db.education

            #pprint("user id "+ user_id)
            res = education_collection.update_one(
                {"_id": ObjectId(invited_user_id)},
                {"$push": {
                    "associated": associate_institute_document_object
                }},
                upsert=True)

            #pprint(res)
            if res.matched_count > 0:
                #add to send message database
                education_doc_id = associate_institute_document_object["_id"]
                invitation_message_object = {
                    "invitation_id": education_doc_id,
                    "status": "pending"
                }
                invitation_id = db.invitation_queue.insert_one(
                    invitation_message_object)
                if invitation_id is None:
                    self.response = {"error": "something went wrong"}
                else:
                    self.response = {"status": "success"}
            else:
                self.response = {"s": "fail"}
        else:
            self.response = {"error": serializer.errors}
Example #11
0
    def __init__(self, data={}):

        serializer = JoinInstituteSerializer(data=data)

        if serializer.is_valid():
            public_page_id = serializer.validated_data.get("institute_id")
            incoming_designations = serializer.validated_data.get(
                "designations")

            #query database for dashboard info
            #str(users.find_one({"$and":[{"email": "*****@*****.**"},{"password": "******"}]}))
            client = DBHandler.get_database_client()
            db = client.test
            education = db.education
            user_id = data.get("user_info")
            public_pages = db.public_pages

            # Inserting a dummy public_page object for testing
            if (0):
                temp_data = {
                    "_id":
                    ObjectId(),
                    "page_title":
                    "Begum Rokeya university",
                    "description":
                    "BRUR Description",
                    "designation": [{
                        "_id":
                        ObjectId(),
                        "title":
                        "parents",
                        "tags": [{
                            "_id":
                            ObjectId(),
                            "title":
                            "parents_Tag 1",
                            "tasks": [{
                                "_id": ObjectId(),
                                "title": "tasks11"
                            }, {
                                "_id": ObjectId(),
                                "title": "tasks12"
                            }]
                        }, {
                            "_id":
                            ObjectId(),
                            "title":
                            "parents_Tag 2",
                            "tasks": [{
                                "_id": ObjectId(),
                                "title": "tasks21"
                            }, {
                                "_id": ObjectId(),
                                "title": "tasks22"
                            }]
                        }]
                    }, {
                        "_id":
                        ObjectId(),
                        "title":
                        "teacher",
                        "tags": [{
                            "_id":
                            ObjectId(),
                            "title":
                            "teacher_Tag 1",
                            "tasks": [{
                                "_id": ObjectId(),
                                "title": "tasks11"
                            }, {
                                "_id": ObjectId(),
                                "title": "tasks12"
                            }]
                        }, {
                            "_id":
                            ObjectId(),
                            "title":
                            "teacher_Tag 2",
                            "tasks": [{
                                "_id": ObjectId(),
                                "title": "tasks21"
                            }, {
                                "_id": ObjectId(),
                                "title": "tasks22"
                            }]
                        }]
                    }]
                }
                page_id = public_pages.insert_one(temp_data).inserted_id
                print(page_id)

            #query if already exist
            ppageid = public_pages.find_one({"_id": ObjectId(public_page_id)})
            #pprint(ppageid)
            if (ppageid is None):
                self.response = {
                    "status_code": "page_not_found",
                    "default_description": "no such thing exits in the system"
                }
                return

            stored_designations = ppageid.get("designation")
            matched_designations = []
            for designations in incoming_designations:
                for designation in stored_designations:
                    #pprint(designation)
                    if (designations == designation["title"]):
                        matched_designations.append(designation)
            #this is to avoid ObjectId not serializer error
            #query_result["_id"] = user_id
            #pprint(stored_designations)
            pprint(matched_designations)
            #print(incoming_designations)
            associate_institute_document_object = {
                "_id": ObjectId(),
                "long_name": ppageid.get("page_title"),
                "description": ppageid.get("description"),
                "designations": matched_designations
            }

            #pprint("user id "+ user_id)
            res = education.update_one(
                {"_id": ObjectId(user_id)},
                {"$push": {
                    "associated": associate_institute_document_object
                }},
                upsert=True)

            #pprint(res)
            if res.matched_count > 0:
                self.response = {"s": "success"}
            else:
                self.response = {"s": "fail"}
        else:
            self.response = serializer.errors
    def __init__(self, data={}):

        serializer = PublicPageSerializer(data=data["data"])

        if serializer.is_valid():
            # query database
            client = DBHandler.get_database_client()
            db = client.test
            public_pages = db.public_pages
            # user_id = data.get("user_info")

            found_page = public_pages.find_one(
                {"page_title": serializer.validated_data.get("page_title")})
            if found_page is None:
                #assign it to "designation" key
                default_designations = [{
                    "_id":
                    ObjectId(),
                    "title":
                    "page_admin",
                    "tags": [{
                        "_id":
                        ObjectId(),
                        "title":
                        "approval_requests",
                        "tasks": [{
                            "_id": ObjectId(),
                            "title": "Approve Join Request",
                            "task_nice_id": "approve_join_request"
                        }],
                    }, {
                        "_id":
                        ObjectId(),
                        "title":
                        "manage_people",
                        "tasks": [{
                            "_id": ObjectId(),
                            "title": "Approve Join Request",
                            "task_nice_id": "add_people"
                        }, {
                            "_id": ObjectId(),
                            "title": "Modify Responsibility",
                            "task_nice_id": "modify_responsibility"
                        }, {
                            "_id": ObjectId(),
                            "title": "Suspend user association",
                            "task_nice_id": "suspend_association"
                        }],
                    }, {
                        "_id":
                        ObjectId(),
                        "title":
                        "manage_class",
                        "tasks": [{
                            "_id": ObjectId(),
                            "title": "Suspend user association",
                            "task_nice_id": "take_attendance"
                        }],
                    }, {
                        "_id":
                        ObjectId(),
                        "title":
                        "analysis",
                        "tasks": [{
                            "_id": ObjectId(),
                            "title": "Student attendance analysis",
                            "task_nice_id": "student_attendance_analysis"
                        }],
                    }],
                }, {
                    "_id":
                    ObjectId(),
                    "title":
                    "Teacher",
                    "tags": [{
                        "_id":
                        ObjectId(),
                        "title":
                        "manage_class",
                        "tasks": [{
                            "_id": ObjectId(),
                            "title": "Suspend user association",
                            "task_nice_id": "take_attendance"
                        }],
                    }],
                }, {
                    "_id":
                    ObjectId(),
                    "title":
                    "Guardian",
                    "tags": [{
                        "_id":
                        ObjectId(),
                        "title":
                        "manage_attendance",
                        "tasks": [{
                            "_id": ObjectId(),
                            "title": "Child Attendance Analysis",
                            "task_nice_id": "attendance_analysis"
                        }],
                    }],
                }]

                serializer.validated_data["designation"] = default_designations
                post_id = public_pages.insert_one(
                    serializer.validated_data).inserted_id
                self.response = {
                    "status_code": "page_creation_successfull",
                    "default_description": "successfully created page",
                    "id": str(post_id),
                }
            else:
                self.response = {
                    "status_code": "registration_failed",
                    "default_description": "already exist",
                    "id": str(found_page["_id"]),
                }
        else:
            self.response = {"error": serializer.errors}
    def __init__(self, data={}):
        serializer = IncomiingDataSerializer(data=data)
        if serializer.is_valid():
            client = DBHandler.get_database_client()
            db = client.test
            education = db.education
            user_id = data.get("user_info")
            public_pages = db.public_pages
            #searched_invitation = education.find_one({"_id":ObjectId(serializer.validated_data.get("invitation_id"))})
            #searched_user_id = education.find_one({"_id":ObjectId(user_id)})
            searched_user_id = education.find_one(
                {"_id": ObjectId("5e08ce2ffebc801b83cd2579")})
            #print(searched_user_id)
            invitation_list = searched_user_id.get("invitations")
            incoming_invitation_id = serializer.validated_data.get(
                "invitation_id")

            for stored_invitation in invitation_list:
                #print(stored_invitation)
                #print(incoming_invitation_id)
                #print(str(stored_invitation["_id"]))
                if (str(stored_invitation["_id"]) == incoming_invitation_id):
                    if (serializer.validated_data.get("verification_code") ==
                            stored_invitation.get("verification_code")):
                        #print(stored_invitation)
                        institute_id = stored_invitation.get("institute_id")
                        #institute_id = "5df85e5f8b98b8fc21f45162"
                        searched_institute_id = public_pages.find_one(
                            {"_id": ObjectId(institute_id)})
                        #print(searched_institute_id)
                        invited_designation = stored_invitation.get(
                            "designations")
                        ppage_designation = searched_institute_id.get(
                            "designation")
                        #print(ppage_designation)
                        matched_designations = []

                        for p_designation in ppage_designation:
                            #print(p_designation)
                            for i_designation in invited_designation:
                                #print(i_designation)
                                if (i_designation == p_designation.get("title")
                                    ):
                                    matched_designations.append(p_designation)

                        associate_institute_document_object = {
                            "institute_id": searched_institute_id,
                            "long_name":
                            searched_institute_id.get("page_title"),
                            "description":
                            searched_institute_id.get("description"),
                            "designations": matched_designations
                        }

                        res = education.update_one(
                            {"_id": ObjectId(user_id)}, {
                                "$push": {
                                    "associated":
                                    associate_institute_document_object
                                }
                            },
                            upsert=True)

                        #print(matched_designations)
                        tags = []
                        for designation in matched_designations:
                            tags.append(designation.get("tags"))

                        if res.matched_count > 0:
                            self.response = json.loads(
                                json.dumps(tags, default=str))
                            return
                        else:
                            self.response = {"message": "something went wrong"}
                    else:
                        self.response = {"message": "verification code error"}
                else:
                    self.response = {"message": "invitation not found"}
        else:
            self.response = serializer.errors