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)
def _handle_rejected(self): """ Creates a notification for rejected tasks. This also creates an email message if it is configured. """ # Construct the message to be sent. message = "Your response to <a href='%s'>%s</a> %s was not approved." % ( reverse("activity_task", args=(self.activity.type, self.activity.slug,)), self.activity.title, # The below is to tell the javascript to convert into a pretty date. # See the prettyDate function in media/js/makahiki.js "<span class='rejection-date' title='%s'></span>" % self.submission_date.isoformat(), ) message += " You can still get points by clicking on the link and trying again." UserNotification.create_error_notification(self.user, message, content_object=self) subject = "[%s] Your response to '%s' was not approved" % (settings.COMPETITION_NAME, self.activity.title) current_site = Site.objects.get(id=settings.SITE_ID) message = render_to_string("email/rejected_activity.txt", { "object": self, "COMPETITION_NAME": settings.COMPETITION_NAME, "domain": current_site.domain, }) html_message = render_to_string("email/rejected_activity.html", { "object": self, "COMPETITION_NAME": settings.COMPETITION_NAME, "domain": current_site.domain, }) UserNotification.create_email_notification(self.user.email, subject, message, html_message)
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)
def send(self): """ Sends a reminder text to the user via an email. """ number = self.text_number.replace("-", "") email = number + "@" + self.TEXT_EMAILS[self.text_carrier] if not self.sent: # subject = "[%s] Reminder for %s" % (settings.COMPETITION_NAME, self.activity.title) current_site = Site.objects.get(id=settings.SITE_ID) message = render_to_string("email/activity_text_reminder.txt", { "activity": self.activity, "user": self.user, }) UserNotification.create_email_notification(email, "", message) self.sent = True self.save()
def send(self): """ Sends a reminder email to the user. """ if not self.sent: subject = "[%s] Reminder for %s" % (settings.COMPETITION_NAME, self.activity.title) current_site = Site.objects.get(id=settings.SITE_ID) message = render_to_string("email/activity_reminder.txt", { "activity": self.activity, "user": self.user, "COMPETITION_NAME": settings.COMPETITION_NAME, "domain": current_site.domain, }) html_message = render_to_string("email/activity_reminder.html", { "activity": self.activity, "user": self.user, "COMPETITION_NAME": settings.COMPETITION_NAME, "domain": current_site.domain, }) UserNotification.create_email_notification(self.email_address, subject, message, html_message) self.sent = True self.save()
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)