Beispiel #1
0
def on_lawyer_assigned(sender, **kwargs):
    instance = kwargs.get('instance')

    if instance.pk is not None:
        # we have an existing item
        prev_instance = ProjectLawyer.objects.get(pk=instance.pk)

        if prev_instance.status != instance.status:

            if instance.status == instance._LAWYER_STATUS.assigned:
                logger.info('Sending ProjectLawyer.assigned email')

                # send email of congratulations to lawyer in question
                recipients = (instance.lawyer.user,)
                from_name = instance.project.customer.user.get_full_name()
                from_email = instance.project.customer.user.email

                url = instance.project.get_absolute_url()

                logger.info('Sending ProjectLawyer.assigned url:{url}'.format(url=url))

                email = NewActionEmailService(
                    from_name=from_name,
                    from_email=from_email,
                    recipients=recipients,
                    event='project.lawyer_assigned'
                )
                email.send(url=url)

                # copy the comments from the ProjectLawyer object to The Project object to
                # continue the flow
                comments_service = EngageLawyerCommentsMoveService(project_lawyer_join=instance)
                comments_service.process()

                # set all other projectLawyer objects for this project to .rejected
                logger.info('Updating other lawyers assigned as potential ProjectLawyer.assigned email')
                ProjectLawyer.objects.exclude(
                    pk=instance.pk
                ).filter(
                    project=instance.project,
                    status=instance._LAWYER_STATUS.potential
                ).update(
                    status=instance._LAWYER_STATUS.rejected
                )
Beispiel #2
0
def on_action_created(sender, **kwargs):
    """
    Handle Creation of attachments
    """
    if not isinstance(sender, LogEntry):
        from glynt.apps.services.email import NewActionEmailService
        from glynt.apps.services.pusher import PusherPublisherService

        is_new = kwargs.get('created', False)
        action = kwargs.get('instance')
        target = action.target

        if action and is_new:

            event = action.data.get('event', 'action.created')

            user_name = action.actor.get_full_name()
            user_email = action.actor.email

            info_object = Bunch(name=user_name,
                                verb=action.verb,
                                target_name=unicode(action),
                                timestamp='',
                                **action.data)

            # if the target has a project attached to it
            if hasattr(target, 'pusher_id'):
                if hasattr(target, 'project'):
                    # send the same event to the project channel
                    # so that the other project channel subscribers
                    # can hear it
                    channels = [target.project.pusher_id, target.pusher_id]
                    pusher_service = PusherPublisherService(channel=channels, event=event)
                else:
                    pusher_service = PusherPublisherService(channel=target.pusher_id, event=event)

                pusher_service.process(label=action.verb, comment=action.verb, **info_object)

            recipients = None
            url = None

            target_type = type(target)

            if target_type == Project:
                logger.debug('action.target is a Project object')
                project = target
                recipients = project.notification_recipients()
                url = action.data.get('url', project.get_absolute_url())

            elif target_type == ProjectLawyer:
                logger.debug('action.target is a ProjectLawyer object')
                project = target.project
                recipients = target.notification_recipients()
                url = action.data.get('url', project.get_absolute_url()) # @TODO need to change this to be the actual engagement element link and write a js trigger to show the modal

            elif target_type == ToDo:
                logger.debug('action.target is a ToDo object')
                project = action.target.project
                recipients = project.notification_recipients()
                url = action.data.get('url', target.get_absolute_url())  # get the todos absolute url

            if recipients:
                logger.debug('recipients: {recipients}'.format(recipients=recipients))

                email = NewActionEmailService(
                    verb=event,
                    from_name=user_name,
                    from_email=user_email,
                    recipients=recipients,
                    actor=action.actor,
                    target=target,
                    project=project,
                    **action.data  # append kwargs sent in via: https://django-activity-stream.readthedocs.org/en/latest/data.html
                )
                email.send(url=url, message=action.verb)