def application_saved(sender, instance, **kwargs): application = instance for user, subscriptions in groupby(sorted(list( ChannelSubscription.objects.recent().filter(user__in=application.group.members.all())), key=lambda x: x.user.id), key=lambda x: x.user): groups = defaultdict(dict) for group_id, count in pending_applications(user): groups[group_id]['pending_application_count'] = count for subscription in subscriptions: send_in_channel(subscription.reply_channel, topic='status', payload={'groups': groups})
def get(request, **kwargs): conversations = unread_conversations(request.user) applications = pending_applications(request.user) feedback_possible = get_feedback_possible(request.user) groups = defaultdict(dict) for group_id, conversation_data in conversations['groups'].items(): groups[group_id] = { **conversation_data, } for group_id, application_count in applications: groups[group_id]['pending_application_count'] = application_count for group_id, feedback_possible_count in feedback_possible: groups[group_id][ 'feedback_possible_count'] = feedback_possible_count places = {} for place_id, conversation_data in conversations['places'].items(): places[place_id] = { **conversation_data, } data = { 'unseen_conversation_count': conversations['unseen_conversation_count'], 'unseen_thread_count': conversations['unseen_thread_count'], 'has_unread_conversations_or_threads': conversations['has_unread_conversations_or_threads'], 'unseen_notification_count': unseen_notification_count(request.user), 'groups': groups, 'places': places, } return Response(data=data, status=status.HTTP_200_OK)