Exemplo n.º 1
0
def get_user_update_msg(user):

    user_update = Users_update()
    user_Gset = GSet()
    user_Gset.add(user.to_json())
    user_update.users = json_util.dumps(user_Gset.toDict())

    msg = {"type": 'Users_update', "data": {'users': user_update.users}}
    return json_util.dumps(msg)
Exemplo n.º 2
0
class TwoPSet:
    def __init__(self):
        self.A = GSet()
        self.R = GSet()

    def add(self, elem):
        self.A.add(elem)

    def remove(self, elem):
        self.R.add(elem)

    def query(self, elem):
        return self.A.query(elem) and not self.R.query(elem)

    def compare(self, tps2):
        return self.A.compare(tps2.A) and self.R.compare(tps2.R)

    def merge(self, tps2):
        self.A.merge(tps2.A)
        self.R.merge(tps2.R)
        # self.display()

    def display(self):
        print("A: ", end="")
        self.A.display()
        print("R: ", end="")
        self.R.display()

    def addedValues(self):
        addedValues = []
        for elem in self.A.payload:
            if self.A.payload.count(elem) > self.R.payload.count(elem):
                if elem not in addedValues:
                    addedValues.append(elem)
        return addedValues

    def removedValues(self):
        removedValues = []
        for elem in self.R.payload:
            if self.R.payload.count(elem) > self.A.payload.count(elem):
                if elem not in removedValues:
                    removedValues.append(elem)
        return removedValues

    def toDict(self):
        self.A = self.A.toDict()
        self.R = self.R.toDict()
        # print(self.__dict__)
        return self.__dict__

    def loadFromDict(self, dict_input):
        A = GSet()
        R = GSet()
        self.A = A.loadFromDict(dict_input['A'])
        self.R = R.loadFromDict(dict_input['R'])
        return self
Exemplo n.º 3
0
def update_user(user, **kwargs):
    """
    Function to add user update (i.e. addition of user to middleware database) 
    """
    check_users()  # checks whether any user exists in that collection
    user_updates = Users_update.objects().first()

    user_updates_GSet_dict = json_util.loads(user_updates.users)
    user_updates_GSet = GSet()
    user_updates_GSet.__dict__ = user_updates_GSet_dict

    user_updates_GSet.add(user.to_json())

    user_updates.users = json_util.dumps(user_updates_GSet.__dict__)
    user_updates.save()