Пример #1
0
    def run(self, *args, **kwargs):
        try:
            answer = Answer.objects.get(pk=kwargs.get('answer_pk'))
        except Answer.DoesNotExist:
            return
        action = kwargs.get('action')
        post = answer.post
        context = {}

        if post.qa_session:
            qa_team = post.qa_sessions.first()
            following = qa_team.get_available_users(search='')
            context['project'] = post.project
            serializer = AnswerPostSwarmSerializer(answer, context=context)
        else:
            if post.is_project:
                context['project'] = post.project
            following = followers(post)
            serializer = AnswerPostSerializer(answer, context=context)

        for follower in following:
            if follower != answer.created_by:
                class UserReq:
                    user = follower
                context['request'] = UserReq
                notifications.send_notifications(
                    get_topic_by_object(answer),
                    action,
                    answer.__class__.__name__.lower(),
                    follower.uuid,
                    serializer.data)
Пример #2
0
    def _send_notification(self, user, opportunity):
        request = Request()
        request.user = user
        serializer = OpportunityListSerializer(opportunity,
                                               context={'request': request})
        data = serializer.data
        action = settings.OPPORTUNITIES_ACTION_NEW_OPPORTUNITY

        send_notifications(action, user.uuid, data)
Пример #3
0
 def send_notification(self, user, applicant):
     request = Request()
     request.user = user
     serializer = OpportunityApplicantSerializer(
         applicant,
         context={'request': request})
     data = serializer.data
     data['opportunity'] = applicant.opportunity.pk
     action = settings.OPPORTUNITIES_ACTION_NEW_APPLICANT
     send_notifications(action, user.uuid, data)
Пример #4
0
def new_message_handler(sender, instance, *args, **kwargs):

    for conversation_user in instance.conversation.users.all():
        user = conversation_user.user
        request = Request()
        request.user = user

        serializer = MessageSerializer(instance, context={'request': request})
        data = serializer.data
        data['conversation'] = instance.conversation.pk
        data['Type'] = instance.conversation._type
        action = settings.CONVERSATIONS_ACTION_NEW_MESSAGE
        send_notifications(action, user.uuid, data)
Пример #5
0
def see_message_handler(sender, instance, *args, **kwargs):

    for conversation_user in instance.conversation.users.all():
        user = conversation_user.user
        request = Request()
        request.user = user

        data = {
            'id': instance.id,
            'conversation': instance.conversation.pk,
            'Type': instance.conversation._type,
        }
        action = settings.CONVERSATIONS_ACTION_SEE_MESSAGE
        send_notifications(action, user.uuid, data)
Пример #6
0
def new_conversation_group_handler(sender, instance, created, *args, **kwargs):
    if not created:
        return
    for conversation_user in instance.users.all():
        user = conversation_user.user
        request = Request()
        request.user = user

        serializer = ConversationSerializer(instance,
                                            context={'request': request})
        data = serializer.data
        data['Type'] = instance._type
        action = settings.CONVERSATIONS_ACTION_NEW_CONVERSATION
        send_notifications(action, user.uuid, data)
Пример #7
0
def microlearning_handler(sender, user_microlearning, *args, **kwargs):
    instance = MicroLearningAverage(
        step_stream=user_microlearning.microlearning.step_stream,
        user=user_microlearning.user,
        team=user_microlearning.team)

    payload = {
        'step_pk': instance.get_step().pk,
        'object': PersonalQuizSerializer(user_microlearning).data
    }
    notifications.send_notifications(
        settings.PROJECT_TOPIC_NAME,
        'update',
        instance.__class__.__name__.lower(),
        instance.user.uuid,
        payload)
Пример #8
0
def post_save_typeform_feedback_handler(sender, instance, created, *args,
                                        **kwargs):
    action = 'create' if created else 'update'
    related_to_object = instance.feedback.related_to.first()
    if hasattr(related_to_object, 'project'):
        project = related_to_object.project
        user_projects = project.get_granted_users(
            [settings.PROJECT_PERMS_VIEW_PROJECT])
        for user in user_projects:
            data = {
                'status': instance.status,
                'user_id': instance.user.id,
                'typeform_url': instance.url,
            }
            notifications.send_notifications(
                settings.PROJECT_TOPIC_NAME, action,
                instance.__class__.__name__.lower(), user.uuid, data)
Пример #9
0
def new_user_connected(uuids_in_topic, new_user_uuid):
    for uuid in uuids_in_topic:
        notifications.send_notifications(settings.EXO_AUTH_TOPIC_CONNECTED,
                                         settings.EXO_AUTH_USER_CONNECTED,
                                         {'uuid': uuid.__str__()},
                                         {'user_uuid': new_user_uuid})
Пример #10
0
def user_disconnected(uuids_in_topic, removed_user_uuid):
    for uuid in uuids_in_topic:
        notifications.send_notifications(settings.EXO_AUTH_TOPIC_CONNECTED,
                                         settings.EXO_AUTH_USER_DISCONNECTED,
                                         {'uuid': uuid.__str__()},
                                         {'user_uuid': removed_user_uuid})
Пример #11
0
 def send_notification(self, user, opportunity):
     data = {'opportunity': opportunity.pk}
     action = settings.OPPORTUNITIES_ACTION_REMOVED_OPPORTUNITY
     send_notifications(action, user.uuid, data)
Пример #12
0
def send_user(instance):
    serializer = UserSerializer(instance)
    notifications.send_notifications(settings.CUSTOM_AUTH_USER_TOPIC, 'update',
                                     instance.__class__.__name__.lower(),
                                     instance.uuid, serializer.data)