from pingcap_sso.models import OperationRedDotHistory, OrganizationUserAction DOT_NAMES = ['org-enroll', 'company-info'] def reddot_list(user): history = OperationRedDotHistory.objects.filter( user=user).values_list('name', flat=True) data = [{ 'name': dot, 'visible': dot not in history } for dot in DOT_NAMES] data.append({ 'name': 'join-org', 'visible': not OrganizationUserAction.objects.filter( action_type=OrganizationUserAction.ACTION_JOIN_ORG, user=user).exists() }) return data def mark_reddot_as_read(user, dot_name): OperationRedDotHistory.objects.create( user=user, name=dot_name )