Beispiel #1
0
def notify_round_started():
  if not in_competition():
    return
    
  today = datetime.datetime.today()
  prev_date = None
  current_round = "Overall Round"
  previous_round = 'Overall Round'
  
  for key, value in settings.COMPETITION_ROUNDS.items():
    # We're looking for a round that ends today and another that starts today (or overall)
    start = datetime.datetime.strptime(value["start"], "%Y-%m-%d")
    end = datetime.datetime.strptime(value["end"], "%Y-%m-%d")
    # Check yesterday's round and check for the current round.
    if start < (today - datetime.timedelta(days=1)) < end:
      previous_round = key
        
    if start < today < end:
      current_round = key
    
  print 'Previous Round: %s' % previous_round
  print 'Current Round: %s' % current_round
    
  if current_round and previous_round and current_round != previous_round:
    print 'Sending out round transition notices.'
    template = NoticeTemplate.objects.get(notice_type="round-transition")
    message = template.render({"PREVIOUS_ROUND": previous_round, "CURRENT_ROUND": current_round,})
    for user in User.objects.all():
      UserNotification.create_info_notification(user, message, display_alert=True,)
Beispiel #2
0
def notify_commitment_end():
    members = CommitmentMember.objects.filter(
        completion_date=datetime.date.today(), award_date__isnull=True)

    # try and load the notification template.
    template = None
    try:
        template = NoticeTemplate.objects.get(notice_type="commitment-ready")
    except NoticeTemplate.DoesNotExist:
        pass

    for member in members:
        message = None
        if template:
            message = template.render({"COMMITMENT": member.commitment})
        else:
            message = "Your commitment <a href='%s'>%s</a> has end." % (
                reverse("activity_task",
                        args=(
                            member.commitment.type,
                            member.commitment.slug,
                        )), member.commitment.title)

            message += "You can click on the link to claim your points."

        UserNotification.create_info_notification(member.user,
                                                  message,
                                                  display_alert=True,
                                                  content_object=member)
        print "created commitment end notification for %s : %s" % (
            member.user, member.commitment.slug)
Beispiel #3
0
  def __create_notifications(self, user):
    try:
      template = NoticeTemplate.objects.get(notice_type='canopy-elevation')
      contents = template.render()
      UserNotification.create_info_notification(user, contents, True)
      
    except NoticeTemplate.DoesNotExist:
      # Use default message.
      message = "Congratulations! You have been added to the canopy!" 
      UserNotification.create_info_notification(user, message, True)

    if user.email and len(user.email) > 0:
      subject = "[%s] Congratulations! You have been added to the canopy!" % (settings.COMPETITION_NAME,) 
      current_site = Site.objects.get(id=settings.SITE_ID)
      message = render_to_string("email/added_to_canopy.txt", {
          "user": user,
          "competition_name": settings.COMPETITION_NAME,
          "domain": current_site.domain,
      })
      html_message = render_to_string("email/added_to_canopy.html", {
          "user": user,
          "competition_name": settings.COMPETITION_NAME,
          "domain": current_site.domain,
      })
      self.stdout.write('Sending email to %s\n' % user.email)
      UserNotification.create_email_notification(user.email, subject, message, html_message)
      
    else:
      self.stdout.write("'%s' does not have a valid email address.  Skipping\n" % user.username)
Beispiel #4
0
 def __pick_winners(self, prizes):
   for prize in prizes:
     if not prize.winner:
       # Randomly order the tickets and then pick a random ticket.
       while True:
         tickets = prize.raffleticket_set.order_by("?").all()
         if tickets.count() == 0:
           self.stdout.write('No tickets for %s. Skipping.\n' % prize)
         ticket = random.randint(0, tickets.count() - 1)
         user = tickets[ticket].user
         self.stdout.write(str(prize) + ": " + user.username + '\n')
         value = raw_input('Is this OK? [y/n] ')
         if value.lower() == 'y':
           prize.winner = user
           prize.save()
           
           self.stdout.write("Notifying %s\n" % user.username)
           # Notify winner using the template.
           try:
             template = NoticeTemplate.objects.get(notice_type='raffle-winner')
             message = template.render({'PRIZE': prize})
             UserNotification.create_info_notification(user, message, True, prize)
           except NoticeTemplate.DoesNotExist:
             self.stdout.write("Could not find the raffle-winner template.  User was not notified.\n")
             
           break
Beispiel #5
0
    def __pick_winners(self, prizes):
        for prize in prizes:
            if not prize.winner:
                # Randomly order the tickets and then pick a random ticket.
                while True:
                    tickets = prize.raffleticket_set.order_by("?").all()
                    if tickets.count() == 0:
                        self.stdout.write('No tickets for %s. Skipping.\n' %
                                          prize)
                    ticket = random.randint(0, tickets.count() - 1)
                    user = tickets[ticket].user
                    self.stdout.write(str(prize) + ": " + user.username + '\n')
                    value = raw_input('Is this OK? [y/n] ')
                    if value.lower() == 'y':
                        prize.winner = user
                        prize.save()

                        self.stdout.write("Notifying %s\n" % user.username)
                        # Notify winner using the template.
                        try:
                            template = NoticeTemplate.objects.get(
                                notice_type='raffle-winner')
                            message = template.render({'PRIZE': prize})
                            UserNotification.create_info_notification(
                                user, message, True, prize)
                        except NoticeTemplate.DoesNotExist:
                            self.stdout.write(
                                "Could not find the raffle-winner template.  User was not notified.\n"
                            )

                        break
Beispiel #6
0
def process_rsvp():
  members = ActivityMember.objects.filter(Q(activity__type="event")|Q(activity__type="excursion"),approval_status="pending")

  # try and load the notification template.
  template_noshow = None
  try:
    template_noshow = NoticeTemplate.objects.get(notice_type="event-noshow-penalty")
  except NoticeTemplate.DoesNotExist:
    pass

  template_reminder = None
  try:
    template_reminder = NoticeTemplate.objects.get(notice_type="event-post-reminder")
  except NoticeTemplate.DoesNotExist:
    pass

  for member in members:
      activity = member.activity
      user = member.user
      profile = user.get_profile()
      
      diff = datetime.date.today() - activity.event_date.date()
      if diff.days == 3:
          message = "%s: %s (No Show)" % (activity.type.capitalize(), activity.title)
          profile.remove_points(4, datetime.datetime.today() - datetime.timedelta(minutes=1), message, member)
          profile.save()
          print "removed 4 points from %s for '%s'" % (profile.name, message)
          
          if template_noshow:
            message = template_noshow.render({"ACTIVITY": activity})
          else:
            message = "4 points had been deducted from you, because you signed up but did not enter the confirmation code 2 days after the %s <a href='%s'>%s</a>, " % (
              activity.type.capitalize(), 
              reverse("activity_task", args=(activity.type, activity.slug,)),
              activity.title)
            message += " If you did attend, please click on the link to claim your points and reverse the deduction."
              
          UserNotification.create_info_notification(user, message, display_alert=True, content_object=member)
          print "created no-show penalty notification for %s for %s" % (profile.name, activity.title)
    
      if diff.days == 2:
          if template_reminder:
            message = template_reminder.render({"ACTIVITY": activity})
          else:
            message  = "Hi %s, <p/> We just wanted to remind you that the %s <a href='http://%s%s'>%s</a> had ended. Please click on the link to claim your points." % (            
              profile.name,
              activity.type.capitalize(), 
              Site.objects.get(id=settings.SITE_ID).domain,
              reverse("activity_task", args=(activity.type, activity.slug,)),
              activity.title)  
            message += "<p/>Because you signed up for the event/excursion, if you do not enter the confirmation code within 2 days after the event/excusion, a total of 4 points (2 point signup bonus plus 2 point no-show penalty) will be deducted from your total points. So please enter your confirmation code early to avoid the penalty."
            message += "<p/><p/>Kukui Cup Administrators"           
          subject = "[Kukui Cup] Reminder to enter your event/excursion confirmation code"
          UserNotification.create_email_notification(user.email, subject, message, message)    
          print "sent post event email reminder to %s for %s" % (profile.name, activity.title)
Beispiel #7
0
def notify_commitment_end():
  members = CommitmentMember.objects.filter(completion_date=datetime.date.today(), award_date__isnull=True)
  
  # try and load the notification template.
  template = None
  try:
    template = NoticeTemplate.objects.get(notice_type="commitment-ready")
  except NoticeTemplate.DoesNotExist:
    pass
    
  for member in members:
    message = None
    if template:
      message = template.render({"COMMITMENT": member.commitment})
    else:
      message = "Your commitment <a href='%s'>%s</a> has end." % (
          reverse("activity_task", args=(member.commitment.type, member.commitment.slug,)),
          member.commitment.title)

      message += "You can click on the link to claim your points."

    UserNotification.create_info_notification(member.user, message, display_alert=True, content_object=member)
    print "created commitment end notification for %s : %s" % (member.user, member.commitment.slug)
Beispiel #8
0
def notify_round_started():
    if not in_competition():
        return

    today = datetime.datetime.today()
    prev_date = None
    current_round = "Overall Round"
    previous_round = 'Overall Round'

    for key, value in settings.COMPETITION_ROUNDS.items():
        # We're looking for a round that ends today and another that starts today (or overall)
        start = datetime.datetime.strptime(value["start"], "%Y-%m-%d")
        end = datetime.datetime.strptime(value["end"], "%Y-%m-%d")
        # Check yesterday's round and check for the current round.
        if start < (today - datetime.timedelta(days=1)) < end:
            previous_round = key

        if start < today < end:
            current_round = key

    print 'Previous Round: %s' % previous_round
    print 'Current Round: %s' % current_round

    if current_round and previous_round and current_round != previous_round:
        print 'Sending out round transition notices.'
        template = NoticeTemplate.objects.get(notice_type="round-transition")
        message = template.render({
            "PREVIOUS_ROUND": previous_round,
            "CURRENT_ROUND": current_round,
        })
        for user in User.objects.all():
            UserNotification.create_info_notification(
                user,
                message,
                display_alert=True,
            )
Beispiel #9
0
def process_rsvp():
    members = ActivityMember.objects.filter(Q(activity__type="event")
                                            | Q(activity__type="excursion"),
                                            approval_status="pending")

    # try and load the notification template.
    template_noshow = None
    try:
        template_noshow = NoticeTemplate.objects.get(
            notice_type="event-noshow-penalty")
    except NoticeTemplate.DoesNotExist:
        pass

    template_reminder = None
    try:
        template_reminder = NoticeTemplate.objects.get(
            notice_type="event-post-reminder")
    except NoticeTemplate.DoesNotExist:
        pass

    for member in members:
        activity = member.activity
        user = member.user
        profile = user.get_profile()

        diff = datetime.date.today() - activity.event_date.date()
        if diff.days == 3:
            message = "%s: %s (No Show)" % (activity.type.capitalize(),
                                            activity.title)
            profile.remove_points(
                4,
                datetime.datetime.today() - datetime.timedelta(minutes=1),
                message, member)
            profile.save()
            print "removed 4 points from %s for '%s'" % (profile.name, message)

            if template_noshow:
                message = template_noshow.render({"ACTIVITY": activity})
            else:
                message = "4 points had been deducted from you, because you signed up but did not enter the confirmation code 2 days after the %s <a href='%s'>%s</a>, " % (
                    activity.type.capitalize(),
                    reverse("activity_task",
                            args=(
                                activity.type,
                                activity.slug,
                            )), activity.title)
                message += " If you did attend, please click on the link to claim your points and reverse the deduction."

            UserNotification.create_info_notification(user,
                                                      message,
                                                      display_alert=True,
                                                      content_object=member)
            print "created no-show penalty notification for %s for %s" % (
                profile.name, activity.title)

        if diff.days == 2:
            if template_reminder:
                message = template_reminder.render({"ACTIVITY": activity})
            else:
                message = "Hi %s, <p/> We just wanted to remind you that the %s <a href='http://%s%s'>%s</a> had ended. Please click on the link to claim your points." % (
                    profile.name, activity.type.capitalize(),
                    Site.objects.get(id=settings.SITE_ID).domain,
                    reverse("activity_task",
                            args=(
                                activity.type,
                                activity.slug,
                            )), activity.title)
                message += "<p/>Because you signed up for the event/excursion, if you do not enter the confirmation code within 2 days after the event/excusion, a total of 4 points (2 point signup bonus plus 2 point no-show penalty) will be deducted from your total points. So please enter your confirmation code early to avoid the penalty."
                message += "<p/><p/>Kukui Cup Administrators"
            subject = "[Kukui Cup] Reminder to enter your event/excursion confirmation code"
            UserNotification.create_email_notification(user.email, subject,
                                                       message, message)
            print "sent post event email reminder to %s for %s" % (
                profile.name, activity.title)