def ticket_created(sender, instance, created, **kwargs):
    """
    Creates activities and notifications when ticket is saved.

    :param sender: the ticket class.
    :param instance: the ticket instance.
    :param created: boolean flag if instance is new.
    """
    if created:
        admins = set([
            admin
            for admin
            in instance.admins
            if admin != instance.submitted_by
        ])

        # Notify queue admins that a new ticket has been created.
        notify.send(
            sender          = sender,
            recipient       = admins,
            actor           = instance.submitted_by,
            verb            = 'created the ticket',
            action_object   = instance,
            preposition     = 'in ticket queue',
            target          = instance.queue
        )

        # Log ticket creation activity.
        Activity.objects.create(
            ticket  = instance,
            actor   = instance.submitted_by,
            verb    = 'created the ticket'
        )
def ticket_action(sender, ticket, actor, verb):
    """
    Creates activities and notifications for specified ticket action.

    :param sender: the Ticket class.
    :param ticket: the Ticket instance.
    """
    # Get associated users, minus the user performing the action.
    recipients = set([
        recipient
        for recipient
        in ticket.associated_staff
        if recipient != actor
    ])

    # Notify associated users.
    notify.send(
        sender          = sender,
        recipient       = recipients,
        actor           = actor,
        verb            = verb,
        action_object   = ticket,
        preposition     = 'in ticket queue',
        target          = ticket.queue
    )

    # Log the activity.
    Activity.objects.create(ticket=ticket, actor=actor, verb=verb)
示例#3
0
    def post_save(cls, sender, instance, created, **kwargs):
        if created:
            # TODO 添加通知
            from apps.account.models import Focus
            instance.tag.update_date = now()
            instance.tag.save()

            for focus in Focus.get_focus_by_content_object(instance.tag).exclude(user=instance.question.user):
                notify.send(get_model(settings.AUTH_USER_MODEL).objects.get(id=settings.NOTIFICATION_USER),
                            recipient=focus.user,
                            verb=u'你关注的标签[{tag}]有新的问题'.format(tag=instance.tag.title),
                            action_object=instance,
                            description=instance.question.get_markdown()
                )
示例#4
0
    def post_save(cls, sender, instance, created, **kwargs):
        if created:
            # TODO 添加通知
            from apps.account.models import Focus
            instance.tag.update_date = now()
            instance.tag.save()

            for focus in Focus.get_focus_by_content_object(
                    instance.tag).exclude(user=instance.question.user):
                notify.send(
                    get_model(settings.AUTH_USER_MODEL).objects.get(
                        id=settings.NOTIFICATION_USER),
                    recipient=focus.user,
                    verb=u'你关注的标签[{tag}]有新的问题'.format(tag=instance.tag.title),
                    action_object=instance,
                    description=instance.question.get_markdown())
示例#5
0
 def post_save(cls, sender, instance, created, **kwargs):
     if created:
         instance.article.update_date = now()
         instance.article.save()
         #TODO 添加通知
         sender = get_model(settings.AUTH_USER_MODEL).objects.get(id=settings.NOTIFICATION_USER)
         notify.send(sender,
                     recipient=instance.article.user,
                     verb=u'你发起的文章[{article}]有新的回复'.format(article=instance.article.title),
                     action_object=instance,
                     description=instance.get_markdown()
         )
         from apps.account.models import Focus
         for focus in Focus.get_focus_by_content_object(instance.article).exclude(user__in=[instance.user, instance.article.user]):
             print focus.user
             notify.send(sender,
                         recipient=focus.user,
                         verb=u'你关注的文章[{article}]有新的回复'.format(article=instance.article.title),
                         action_object=instance,
                         description=instance.get_markdown()
             )
示例#6
0
    def post_save(cls, sender, instance, created, **kwargs):
        if created:
            instance.question.update_status()
            # TODO 添加通知
            from apps.account.models import Focus
            sender = get_model(settings.AUTH_USER_MODEL).objects.get(id=settings.NOTIFICATION_USER)

            notify.send(sender,
                        recipient=instance.question.user,
                        verb=u'你发起的问题[{question}]有新的回答'.format(question=instance.question.title),
                        action_object=instance,
                        description=instance.get_markdown()
            )

            for focus in Focus.get_focus_by_content_object(instance.question).exclude(
                    user__in=[instance.user.id, instance.question.user.id]):
                notify.send(sender,
                            recipient=focus.user,
                            verb=u'你关注的问题[{question}]有新的回答'.format(question=instance.question.title),
                            action_object=instance,
                            description=instance.get_markdown()
                )
示例#7
0
    def post_save(cls, sender, instance, created, **kwargs):
        if created:
            instance.question.update_status()
            # TODO 添加通知
            from apps.account.models import Focus
            sender = get_model(settings.AUTH_USER_MODEL).objects.get(
                id=settings.NOTIFICATION_USER)

            notify.send(sender,
                        recipient=instance.question.user,
                        verb=u'你发起的问题[{question}]有新的回答'.format(
                            question=instance.question.title),
                        action_object=instance,
                        description=instance.get_markdown())

            for focus in Focus.get_focus_by_content_object(
                    instance.question
            ).exclude(user__in=[instance.user.id, instance.question.user.id]):
                notify.send(sender,
                            recipient=focus.user,
                            verb=u'你关注的问题[{question}]有新的回答'.format(
                                question=instance.question.title),
                            action_object=instance,
                            description=instance.get_markdown())
def ticket_changed(sender, ticket, actor, **kwargs):
    """
    Creates activities and notifications when ticket is changed.

    :param sender: the ticket class.
    :param instance: the ticket instance.
    """
    # Ticket contains updated attribute values, so get a cached version from DB.
    cached      = Ticket.objects.get(pk=ticket.pk)
    recipients  = set([
        recipient
        for recipient
        in ticket.associated_staff
        if recipient != actor
    ])

    if ticket.queue != cached.queue:
        # Changed queue.
        notify.send(
            sender          = sender,
            recipient       = recipients,
            actor           = actor,
            verb            = 'transferred the ticket',
            action_object   = ticket,
            preposition     = 'to ticket queue',
            target          = ticket.queue
        )

        Activity.objects.create(
            ticket          = ticket,
            actor           = actor,
            verb            = 'transferred the ticket to queue',
            action_object   = ticket.queue
        )

        # Reset the assignee.
        ticket.assigned_to = None

    if ticket.assigned_to and ticket.assigned_to != cached.assigned_to:
        # Assigned to staff.
        if ticket.assigned_to == actor:
            # Self-assigned.
            notify.send(
                sender          = sender,
                recipient       = recipients,
                actor           = actor,
                verb            = 'self-assigned the ticket',
                action_object   = ticket
            )

            Activity.objects.create(
                ticket  = ticket,
                actor   = actor,
                verb    = 'self-assigned the ticket',
            )
        else:
            notify.send(
                sender          = sender,
                recipient       = recipients,
                actor           = actor,
                verb            = 'assigned the ticket',
                action_object   = ticket,
                preposition     = 'to',
                target          = ticket.assigned_to
            )

            Activity.objects.create(
                ticket          = ticket,
                actor           = actor,
                verb            = 'assigned the ticket to',
                action_object   = ticket.assigned_to
            )

    if ticket.due_date != cached.due_date:
        # Changed due date.
        notify.send(
            sender          = sender,
            recipient       = recipients,
            actor           = actor,
            verb            = 'changed the due date for the ticket',
            action_object   = ticket,
            preposition     = 'in ticket queue',
            target          = ticket.queue
        )

        Activity.objects.create(
            ticket  = ticket,
            actor   = actor,
            verb    = 'changed the due date for the ticket',
        )

    if ticket.priority != cached.priority:
        # Changed priority.
        notify.send(
            sender          = sender,
            recipient       = recipients,
            actor           = actor,
            verb            = 'changed the priority for the ticket',
            action_object   = ticket,
            preposition     = 'in ticket queue',
            target          = ticket.queue
        )

        Activity.objects.create(
            ticket  = ticket,
            actor   = actor,
            verb    = 'changed the priority for the ticket',
        )

    if ticket.summary != cached.summary:
        # Changed summary.
        notify.send(
            sender          = sender,
            recipient       = recipients,
            actor           = actor,
            verb            = 'changed the summary of the ticket',
            action_object   = ticket,
            preposition     = 'in ticket queue',
            target          = ticket.queue
        )

        Activity.objects.create(
            ticket  = ticket,
            actor   = actor,
            verb    = 'changed the summary of the ticket',
        )

    if ticket.description != cached.description:
        # Changed description.
        notify.send(
            sender          = sender,
            recipient       = recipients,
            actor           = actor,
            verb            = 'changed the description of the ticket',
            action_object   = ticket,
            preposition     = 'in ticket queue',
            target          = ticket.queue
        )

        Activity.objects.create(
            ticket  = instance,
            actor   = instance.recipients,
            verb    = 'changed the description of the ticket',
        )