Ejemplo n.º 1
0
def on_attachment_created(sender, **kwargs):
    """
    Handle Creation of attachments
    """
    if not isinstance(sender, LogEntry):
        is_new = kwargs.get('created', False)
        attachment = kwargs.get('instance')

        if attachment and is_new:
            crocdoc_service = CrocdocAttachmentService(attachment=attachment)
            crocdoc_service.process()

            todo = attachment.todo
            todostatus_service = ToDoStatusService(todo_item=todo)
            todostatus_service.process()

            # increment the attachment count
            todo.num_attachments_plus()

            verb = u'{name} uploaded an attachment: "{filename}" on the checklist item {todo} for {project}'.format(name=attachment.uploaded_by.get_full_name(), filename=attachment.filename, todo=attachment.todo, project=attachment.project).encode('utf-8')
            action.send(attachment.uploaded_by,
                        verb=verb,
                        action_object=attachment,
                        target=attachment.todo,
                        content=verb,
                        attachment=attachment.filename,
                        todo=attachment.todo.name,
                        status=attachment.todo.display_status,
                        event='todo.attachment.created')
Ejemplo n.º 2
0
def on_comment_created(sender, **kwargs):
    """
    Handle Creation of attachments
    @TODO: This needs to be abstracted!
    @CODESMELL
    """
    if not isinstance(sender, LogEntry):
        send = False
        is_new = kwargs.get('created', False)
        comment = kwargs.get('instance')
        extra = {}

        if comment and is_new:
            content_object_type = type(comment.content_object)
            logger.debug('New Comment on object type: {content_object_type}'.format(content_object_type=content_object_type))

            # If its a comment on a ToDo Object
            if content_object_type == ToDo:
                send = True
                target = todo = comment.content_object
                event = 'todo.comment.created'
                verb = u'{name} commented on checklist item {todo} for {project}'.format(name=comment.user.get_full_name(), project=todo.project, todo=todo.name).encode('utf-8')

                # update the ToDo Status as its been interacted with
                todostatus_service = ToDoStatusService(todo_item=todo)
                todostatus_service.process()

            elif content_object_type == Project:
                send = True
                target = project = comment.content_object
                event = 'project.comment.created'
                verb = u'{name} commented on the {project} project'.format(name=comment.user.get_full_name(), project=project).encode('utf-8')
                extra.update({
                    'url': comment.absolute_deeplink_url()  # append url to the comment deeplink
                })

            elif content_object_type == ProjectLawyer:
                send = True
                target = comment_target = comment.content_object
                event = 'project.lawyer_engage.comment.created'
                verb = u'{name} commented on the Lawyer Engagement conversation for {project}'.format(name=comment.user.get_full_name(), project=comment_target.project).encode('utf-8')

                # notify the lawyer (used for discussion counts)
                if comment.user.profile.is_customer:
                    recipient = comment.content_object.lawyer.user
                else:
                    recipient = comment.content_object.project.customer.user
                # send notification
                notify.send(comment.user, recipient=recipient, verb=u'added to discussion', action_object=comment_target.project,
                    description=comment.comment, target=comment_target.project, project_action='added_discussion_item', project_pk=comment_target.project.pk, creating_user_pk=comment.user.pk)

        if send is True:
            logger.debug(u'send action: {event} {verb} content: {content}'.format(event=event, verb=verb, content=comment.comment).encode('utf-8'))
            action.send(comment.user,
                        verb=verb,
                        action_object=comment,
                        target=target,
                        content=comment.comment,
                        event=event,
                        **extra)