Exemple #1
0
def on_project_categories_sort_updated(sender, instance, user, categories, **kwargs):
    pusher_service = PusherPublisherService(channel=instance.pusher_id, event='project.project_categories_sort_updated')

    name = user.get_full_name() if hasattr(user, 'get_full_name') else 'An Anonymous user'
    comment = '{name} changed the order of the project categories for {project}'.format(name=name, project=instance.__unicode__())

    pusher_service.process(comment=comment)
Exemple #2
0
 def pusher_event(self):
         pusher = PusherPublisherService(channel=[self.todo_item.pusher_id,
                                                  self.todo_item.project.pusher_id], 
                                         event='todo.status_change')
         info_object = {
             'old_status': {'id': self.status, 'name': self.todo_item.TODO_STATUS_CHOICES.get_desc_by_value(self.status)},
             'new_status': {'id': self.new_status, 'name': self.todo_item.TODO_STATUS_CHOICES.get_desc_by_value(self.new_status)},
         }
         pusher.process(**info_object)
Exemple #3
0
def todo_item_crud(sender, **kwargs):
    from glynt.apps.services.pusher import PusherPublisherService

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

    if is_sort_order_update(**kwargs) is False and is_data_field_update(**kwargs) is False:

        info_object = get_todo_info_object(todo=instance)
        pusher_service = PusherPublisherService(channel=instance.project.pusher_id, event='todo.post_save')

        if is_new is True:
            pusher_service.event = 'todo.is_new'
            comment = label = 'Created new item "{name}"'.format(name=instance.name)

        elif instance.is_deleted is True:
            pusher_service.event = 'todo.is_deleted'
            comment = label = 'Deleted "{name}"'.format(name=instance.name)

        else:
            pusher_service.event = 'todo.is_updated'
            comment = label = 'Updated "{name}"'.format(name=instance.name)

        pusher_service.process(label=label, comment=comment, **info_object)
Exemple #4
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)