tfb-groupme-bridge/tfbbridge/bridge/utils.py

30 lines
811 B
Python
Raw Permalink Normal View History

2024-12-20 22:05:41 -06:00
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]
2025-01-02 17:49:01 -06:00
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)