import pickle from .models import Organization def to_pickle(data): return pickle.dumps(data).hex() def from_pickle(data): return pickle.loads(bytes.fromhex(data)) # remove duplicate users # https://stackoverflow.com/questions/9427163/remove-duplicate-dict-in-list-in-python def remove_dup_dict_in_list(l): return [i for n, i in enumerate(l) if i not in l[n + 1:]] def get_org_by_id(org_id): return Organization.objects.filter(id__exact=org_id)[0] def get_user_from_user_id(user_id, users): for user in users: if user.userid == user_id: return user def get_group_from_group_id(group_id, groups): for group in groups: if group.groupid == group_id: return group def org_filter(org, **kwargs): return Organization.objects.filter(**kwargs)