Beispiel #1
0
    def save(self):
        """
        This method saves the visitor model to the database
        If the visitor id exists in the database updates the existing record
        Else the new visitor is saved
        """
        visitor_collection = MongoConnection().get_collection(self.COLLECTION)

        visitor_collection.replace_one({self.Meta.USER_ID_KEY: self.user_id}, self.to_json(), upsert=True)
Beispiel #2
0
    def save(self):
        """
        saves the given question in persistence
        :return:
        """
        Meta = self.Meta
        question_collection = MongoConnection().get_collection(self.COLLECTION)

        question_collection.replace_one(
            {Meta.VISITOR_ID_KEY: self.visitor_id, Meta.QUESTION_ID_KEY: self.question_id}, self.to_json(), upsert=True
        )
Beispiel #3
0
    def remove_all(self):
        """
        :return:
        """
        mongo_conn = MongoConnection()
        upper_case_regex = r"/([A-Z]+\_[A-Z]+)/"
        for collection in MongoConnection.Collections.__dict__.keys():

            if re.match(upper_case_regex, collection) is not None:
                coll = mongo_conn.get_collection(collection, create_if_not_found=False)
                if coll is not None:
                    coll.remove({self.Meta.ID_KEY: self.visitor_id})  # remove all the data for the visitor
Beispiel #4
0
    def save(self, is_completed):
        """
        Saves the Visitor Session Information to the database
        :param is_completed: indicates whether the session was completed or not, based upon which the collection is selected
        :return:
        """
        # Note: we are using the visitor information as the base for the storing the session info.
        # We will be adding other properties to it such as questions answered, final text provided
        object_to_persist = self.to_json()

        collection_to_persist = self.COLLECTION if is_completed else self.COLLECTION_UNFINISHED

        session_collection = MongoConnection().get_collection(collection_to_persist)

        session_collection.insert_one(object_to_persist)
Beispiel #5
0
# We aren't declaring django models here, we will declare simple classes that will