Ejemplo n.º 1
0
  def handle(self, *args, **options):

    # Roll the Dice = 223
    # Rolling the Dice = 224
    group = Group.objects.get(id=224)

    invitations = Invitation.objects.filter(group = group, is_accepted = False, is_declined=False)

    for invitation in invitations:

      invitation_url = reverse('invitations:view_invitation', args=[invitation.key])
      site_name = "https://www.loopla.com/"
      invitation_url = site_name + invitation_url

      subject = "Invitation from " + invitation.inviter.first_name + " to join " + group.name.title()

      n_posts = Post.objects.filter(group=group).count()
      n_comments = Comment.objects.filter(post__group=group).count()

      users = User.objects.filter(groups=group)
      n_short_list = ShortList.objects.filter(owner__in=users).count()

      context = {'user': invitation.invitee,
           'group': group,
           'n_members': str(Membership.objects.filter(group=group).count()),
           'n_posts_comments': str(n_posts + n_comments),
           'n_short_list': str(n_short_list),
           'url' : invitation_url}

      email = compose_email(subject, "groups/email_template_1.html", context)
      email.to.append(settings.NOTIFICATIONS_SERVICE_ADMIN_EMAIL_ADDRESS)
      safe_send_email(email)
      
Ejemplo n.º 2
0
 def send_email(self, summary_content):
     subject = "Your Weekly Update From Loopla"
     context = {
         'summary_content': summary_content,
         'user_id': summary_content['user'].id
     }
     email = compose_email(subject, "email_summary.html", context)
     email.to.append(summary_content['user'].email)
     safe_send_email(email)
Ejemplo n.º 3
0
def send_email_notification(message, recipient):
  context = {'message_context': message, 'user_id': message['recipient_id']}
  
  if(message['notification_type'] == 'post'):
    subject = message['poster_first_name'] + ' ' + message['poster_last_name'] + ' just posted in ' + message['group_name']
  else:
    subject = message['commenter_first_name'] + ' ' + message['commenter_last_name'] + ' commented on ' + message['post_summary']

  email = compose_email(subject, "email_notification.html", context)
  email.to.append(recipient)
  safe_send_email(email)
    def handle(self, *args, **options):

        # Roll the Dice = 223
        # Rolling the Dice = 224
        group = Group.objects.get(id=224)

        #users = User.objects.filter(groups=group)
        users = User.objects.filter(id=7)
        #users = User.objects.filter(last_name="Cuthbert")

        n_display = 5

        for user in users:

            subject = "Welcome to Loopla!"
            context = {'user': user, 'group': group}
            email = compose_email(subject, "groups/email_template_2.html",
                                  context)
            email.to.append(settings.NOTIFICATIONS_SERVICE_ADMIN_EMAIL_ADDRESS)
            safe_send_email(email)
  def handle(self, *args, **options):
    current_date = timezone.now().replace(hour=0, minute=0)
    reminder_number_max = settings.NOTIFICATIONS_NEW_INVITE_REMINDER_NUMBER_MAX
    reminder_days_required = settings.NOTIFICATIONS_NEW_INVITE_REMINDER_DAYS_REQUIRED
    date_threshold = current_date - timedelta(days = reminder_number_max * 
          reminder_days_required)
    filter_invitations = None
    for period in range(1, reminder_number_max + 1):
      date_threshold = current_date - timedelta(days = period * reminder_days_required)
      query = Q(is_accepted = False, sent_timestamp__gte=date_threshold, sent_timestamp__lte=date_threshold + timedelta(days=1))
      if filter_invitations == None:
        filter_invitations = query
      else:
        filter_invitations = filter_invitations | query
        
    invitations = Invitation.objects.filter(filter_invitations)

    for invitation in invitations:
      site_name = settings.BASE_URL
      invitation_url = '%s/invitation/%s/' %(site_name, invitation.key)
      group = invitation.group
      subject = "Invitation from " + invitation.inviter.first_name + " to Join " + group.circle.name.title()

      n_posts = Post.objects.filter(group=group).count()
      n_comments = Comment.objects.filter(post__group=group).count()

      users = User.objects.filter(groups=group)
      n_short_list = ShortList.objects.filter(owner__in=users).count()

      context = {'user': invitation.inviter,
          'group': group,
          'invitee_first_name': invitation.invitee.first_name,
          'n_members': str(Membership.objects.filter(group=group).count()),
          'n_posts_comments': str(n_posts + n_comments),
          'n_short_list': str(n_short_list),
          'url' : invitation_url}

      email = compose_email(subject, "email_invitation_member_reminder.html", context)
      email.to.append(invitation.invitee.email)
      safe_send_email(email)
Ejemplo n.º 6
0
    def handle(self, *args, **options):
        names = ['henry']  #, 'AnneLopez']
        ids = ['7', '3']

        #for name in names:
        #  user = User.objects.get (username=name)
        for i in ids:
            user = User.objects.get(id=i)
            actions = get_individual_actions(user)

            subject = user.first_name + "'s Loopla Summary"

            lines = []

            for key in actions:
                s = key + ": " + str(len(actions[key]))
                lines.append(s)

            body = '\n'.join(lines)

            email = compose_email(subject, body)
            email.to.append(user.email)
            safe_send_email(email)
Ejemplo n.º 7
0
    def send(self, request):
        # Add name of recipient

        invitation_url = '/invitation/' + self.key + '/'
        invitation_url = request.build_absolute_uri(invitation_url)

        read_receipt_url = reverse('api_v1:invitation-read-receipt.png')
        read_receipt_url = request.build_absolute_uri(read_receipt_url)
        read_receipt_url = read_receipt_url + '?id=' + str(self.id)

        personal_message = self.invitation_message.message

        if self.invitation_type == Invitation.BECOME_GROUP_COORDINATOR:
            self.invitation_message.subject = get_admin_invitation_subject(
                user=request.user, group=self.group)

            message_body = get_admin_invitation_body(
                request,
                user=request.user,
                group=self.group,
                invitee_first_name=self.invitee.first_name,
                url=invitation_url,
                optional_message=personal_message,
                invitation_id=self.id,
                read_receipt_url=read_receipt_url)

        elif self.invitation_type == Invitation.BECOME_GROUP_MEMBER:
            self.invitation_message.subject = get_member_invitation_subject(
                user=request.user, group=self.group)

            message_body = get_member_invitation_body(
                request,
                user=request.user,
                group=self.group,
                invitee_first_name=self.invitee.first_name,
                url=invitation_url,
                optional_message=personal_message,
                is_disabled_button=False,
                invitation_id=self.id,
                read_receipt_url=read_receipt_url)

        elif self.invitation_type == START_GROUP_FROM_USER:
            self.invitation_message.subject = get_founder_invitation_subject(
                user=request.user, group=self.group)

            message_body = get_founder_invitation_body(
                request,
                user=request.user,
                group=self.group,
                invitee_first_name=self.invitee.first_name,
                url=invitation_url,
                optional_message=personal_message,
                invitation_id=self.id,
                read_receipt_url=read_receipt_url)

        self.invitation_message.message = message_body.replace(
            "\r\n", "<br />")

        email = compose_email(self.invitation_message.subject,
                              self.invitation_message.message)
        email.extra_headers.update({'Content-ID': '<Loopla_Logo.png>'})
        email.to.append(self.invitee.email)

        # If we want to attach an actual image, we uncomment the following
        # two lines
        #fd = default_storage.open ('logos/Loopla_logo_01_112x30.png', 'rb')
        #email.attach('Loopla_Logo.png', fd.read(), 'img/png')

        safe_send_email(email)

        self.sent_timestamp = timezone.now()

        self.invitation_message.save()
        self.save()
Ejemplo n.º 8
0
 def send_email(self, feedback):
     subject = "New Feedback"
     context = {'feedback': feedback}
     email = compose_email(subject, "email_feedback.html", context)
     email.to.append(settings.NOTIFICATIONS_SERVICE_ADMIN_EMAIL_ADDRESS)
     safe_send_email(email)
Ejemplo n.º 9
0
def change_status(request,
                  user,
                  status_change,
                  person,
                  group,
                  is_send_email,
                  is_initiated_by_user,
                  note=None):
    """Takes action to change the status of a given user"""

    change = status_change[1]
    membership = Membership.objects.get(user=person, group=group)
    now = datetime.utcnow()

    def remove_user_from_group():
        Post.objects.filter(owner=person).filter(group=group).update(
            is_deleted=True, date_deleted=now)
        Comment.objects.filter(owner=person).filter(post__group=group).update(
            is_deleted=True, date_deleted=now)
        person.groups.remove(group)
        membership.is_coordinator = False
        membership.is_active = False
        membership.is_removed = True
        membership.date_became_inactive = None
        membership.date_became_coordinator = None
        membership.date_became_removed = now
        membership.save()

    def make_user_inactive():
        membership.is_coordinator = False
        membership.is_active = False
        membership.is_removed = False
        membership.date_became_inactive = now
        membership.date_became_coordinator = None
        membership.date_became_removed = None
        membership.save()

    # Record the status change... unless becoming admin
    if change != 'member_to_admin' and change != 'inactive_to_admin':
        # Status change to admin requires that user accept invitation
        # Change will not be official until they do so.
        sc = StatusChange(user=person,
                          group=group,
                          status_change=status_change[0],
                          note=note,
                          is_initiated_by_user=is_initiated_by_user)
        sc.save()

    # Handle status changes
    if change == 'admin_to_member':
        membership.is_coordinator = False
        membership.date_became_coordinator = None
        membership.save()

    elif change == 'member_to_admin':

        subject = get_admin_invitation_subject(user, group)
        # The rest of the message is added when it is sent
        body = note
        message = InvitationMessage(subject=subject, message=body)
        message.save()

        nomination = Invitation.create(
            invitation_type=Invitation.BECOME_GROUP_COORDINATOR,
            group=group,
            inviter=user,
            invitee=person,
            invitation_message=message)
        nomination.send(request)

    elif change == 'inactive_to_member':
        membership.is_active = True
        membership.date_became_inactive = None
        membership.save()

    elif change == 'admin_to_inactive' or change == 'member_to_inactive':
        make_user_inactive()

    elif change == 'remove_admin' or change == 'remove_member' or change == 'remove_inactive':
        remove_user_from_group()

    # Send status change email
    # This email doesn't go to nominated administrators as they got sent
    # their own email above.
    if change != 'member_to_admin' and change != 'inactive_to_admin' and is_send_email:
        message_subject = get_status_change_subject(user=user, group=group)
        message_body = get_status_change_body(
            request=request,
            change=change,
            user=user,
            group=group,
            invitee_first_name=person.first_name,
            optional_message=note).replace("\r\n", "<br />")
        email = compose_email(message_subject, message_body)
        email.to.append(person.email)
        safe_send_email(email)