Пример #1
0
 def setUp(self):
     self.user = UserFactory()
     self.client = APIClient()
     self.client.force_authenticate(user=self.user)
     self.list_url = reverse('api:activity-list')
     # create a bunch of action objects of various types
     self.team = TeamFactory()
     self.team_member = TeamMemberFactory(user=self.user, team=self.team)
     self.video = VideoFactory()
     TeamVideoFactory(video=self.video, team=self.team)
     self.user2 = UserFactory()
     Action.create_video_handler(self.video, self.user)
     self.video.title = 'new-title'
     self.video.save()
     Action.change_title_handler(self.video, self.user)
     # creating comment will automatically create the action object
     Comment(content_object=self.video,
             user=self.user,
             content="Test Comment").save()
     v = pipeline.add_subtitles(self.video, 'en', None, author=self.user)
     Action.create_caption_handler(v, datetime.now())
     Action.create_approved_video_handler(v, self.user2)
     Action.create_rejected_video_handler(v, self.user2)
     Action.create_new_member_handler(self.team_member)
     Action.create_member_left_handler(self.team, self.user)
     self.action_qs = Action.objects.for_user(self.user)
Пример #2
0
def team_member_new(member_pk):
    if getattr(settings, "MESSAGES_DISABLED", False):
        return
    from messages.models import Message
    from teams.models import TeamMember
    member = TeamMember.objects.get(pk=member_pk)
    if not _team_sends_notification(member.team,
                                    'block_team_member_new_message'):
        return False
    from videos.models import Action
    from teams.models import TeamMember
    # the feed item should appear on the timeline for all team members
    # as a team might have thousands of members, this one item has
    # to show up on all of them
    Action.create_new_member_handler(member)
    # notify  admins and owners through messages
    notifiable = TeamMember.objects.filter(
        team=member.team,
        role__in=[TeamMember.ROLE_ADMIN,
                  TeamMember.ROLE_OWNER]).exclude(pk=member.pk)
    for m in notifiable:
        context = {
            "new_member": member.user,
            "team": member.team,
            "user": m.user,
            "role": member.role,
            "url_base": get_url_base(),
        }
        body = render_to_string("messages/team-new-member.txt", context)
        subject = ugettext("%s team has a new member" % (member.team))
        if m.user.notify_by_message:
            msg = Message()
            msg.subject = subject
            msg.content = body
            msg.user = m.user
            msg.object = m.team
            msg.save()
        template_name = "messages/email/team-new-member.html"
        Meter('templated-emails-sent-by-type.teams.new-member').inc()
        send_templated_email(m.user, subject, template_name, context)

    # now send welcome mail to the new member
    template_name = "messages/team-welcome.txt"
    context = {
        "team": member.team,
        "url_base": get_url_base(),
        "role": member.role,
        "user": member.user,
    }
    body = render_to_string(template_name, context)

    msg = Message()
    msg.subject = ugettext("You've joined the %s team!" % (member.team))
    msg.content = body
    msg.user = member.user
    msg.object = member.team
    msg.save()
    template_name = "messages/email/team-welcome.html"
    Meter('templated-emails-sent-by-type.teams.welcome').inc()
    send_templated_email(msg.user, msg.subject, template_name, context)
Пример #3
0
def team_member_new(member_pk):
    if getattr(settings, "MESSAGES_DISABLED", False):
        return
    from messages.models import Message
    from teams.models import TeamMember, Setting
    member = TeamMember.objects.get(pk=member_pk)
    if not team_sends_notification(member.team,'block_team_member_new_message'):
        return False
    from videos.models import Action
    from teams.models import TeamMember
    # the feed item should appear on the timeline for all team members
    # as a team might have thousands of members, this one item has
    # to show up on all of them
    Action.create_new_member_handler(member)
    # notify  admins and owners through messages
    notifiable = TeamMember.objects.filter(team=member.team, user__is_active=True,
       role__in=[TeamMember.ROLE_ADMIN, TeamMember.ROLE_OWNER]).exclude(pk=member.pk)
    for m in notifiable:
        context = {
            "new_member": member.user,
            "team":member.team,
            "user":m.user,
            "role":member.role,
            "url_base":get_url_base(),
        }
        body = render_to_string("messages/team-new-member.txt",context)
        subject = fmt(
            ugettext("%(team)s team has a new member"),
            team=member.team)
        if m.user.notify_by_message:
            msg = Message()
            msg.message_type = 'S'
            msg.subject = subject
            msg.content = body
            msg.user = m.user
            msg.object = m.team
            msg.save()
        template_name = "messages/email/team-new-member.html"
        send_templated_email(m.user, subject, template_name, context)

    # does this team have a custom message for this?
    team_default_message = None
    messages = Setting.objects.messages().filter(team=member.team)
    if messages.exists():
        for m in messages:
            if m.get_key_display() == 'messages_joins':
                team_default_message = m.data
                break
    for ul in UserLanguage.objects.filter(user=member.user).order_by("priority"):
        localized_message = Setting.objects.messages().filter(team=member.team, language_code=ul.language)
        if len(localized_message) == 1:
            if team_default_message:
                team_default_message += u'\n\n----------------\n\n' + localized_message[0].data
            else:
                team_default_message = localized_message[0].data
            break
    # now send welcome mail to the new member
    template_name = "messages/team-welcome.txt"
    context = {
       "team":member.team,
       "url_base":get_url_base(),
       "role":member.role,
       "user":member.user,
       "custom_message": team_default_message,
    }
    body = render_to_string(template_name,context)

    msg = Message()
    msg.message_type = 'S'
    msg.subject = fmt(
        ugettext("You've joined the %(team)s team!"),
        team=member.team)
    msg.content = body
    msg.user = member.user
    msg.object = member.team
    msg.save()
    template_name = "messages/email/team-welcome.html"
    send_templated_email(msg.user, msg.subject, template_name, context)