def event_unlocked(self, eventcheckin): """Send an email to the user who has just unlocked a badge at an event""" from event.templatetags.eventtags import event_friends if not eventcheckin: return True user_profile = eventcheckin.user_profile if not user_profile: return True event = eventcheckin.event if not event.has_unlock and not settings.FOURSQUARE_UNLOCK_BETA: return True user = user_profile.user if user: d = get_event_email_data(event, 'event-unlocked') num_fr = event_friends(event, user_profile).lower().replace('|', '') if num_fr.endswith("friend"): num_fr = num_fr + " is in for this event" elif num_fr.endswith("friends"): num_fr = num_fr + " are in for this event" d['num_friends'] = num_fr subject = event.unlock_subject or settings.FOURSQUARE_UNLOCK_SUBJECT body = event.unlock_body email_template(subject, 'event/email/event_unlocked.html', { 'event': event, 'user': user, 'user_profile': user_profile, 'data': d, 'subject': subject, 'body': body }, to_list=[user.email]) return True
def event_unlocked(self, eventcheckin): """Send an email to the user who has just unlocked a badge at an event""" from event.templatetags.eventtags import event_friends if not eventcheckin: return True user_profile = eventcheckin.user_profile if not user_profile: return True event = eventcheckin.event if not event.has_unlock and not settings.FOURSQUARE_UNLOCK_BETA: return True user = user_profile.user if user: d = get_event_email_data(event, 'event-unlocked') num_fr = event_friends(event, user_profile).lower().replace('|', '') if num_fr.endswith("friend"): num_fr = num_fr + " is in for this event" elif num_fr.endswith("friends"): num_fr = num_fr + " are in for this event" d['num_friends'] = num_fr subject = event.unlock_subject or settings.FOURSQUARE_UNLOCK_SUBJECT body = event.unlock_body email_template(subject, 'event/email/event_unlocked.html', {'event':event, 'user':user, 'user_profile':user_profile, 'data':d, 'subject':subject, 'body':body}, to_list=[user.email]) return True
def event_faved(self, attendee): """Email users when a friend favorites an event they've favorited. The email will basically say "%Username% is on board with you for %Event%!". """ from event.templatetags.eventtags import event_friends from registration.models import Friendship if not attendee: return True event = attendee.event if not event.is_active: return True venue = event.venue user_profile = attendee.attendee_profile if not user_profile.user.is_active: return True friends = Friendship.objects.get_friendships(user_profile).values_list( 'user_profile2_id', flat=True) friends = set(list(friends)) attendees = event.attendee_set.select_related( 'attendee_profile__user').filter( pk__lt=attendee. pk, # people that faved this event before this user attendee_profile__send_favorites=True, attendee_profile__user__is_active=True) e, v = event, venue d = get_event_email_data(event, 'event-faved') for f in attendees: friend_profile = f.attendee_profile if friend_profile.pk in friends: num_fr = event_friends(event, friend_profile).lower().replace( '|', '') if num_fr.endswith("friend"): num_fr = num_fr + " is in for this event" elif num_fr.endswith("friends"): num_fr = num_fr + " are in for this event" d['num_friends'] = num_fr subject = u'%s is on board with you for %s' % ( user_profile.username.title(), event.title) email_template(subject, 'event/email/friend_is_on_board.html', { 'event': event, 'user_profile': friend_profile, 'friend_profile': user_profile, 'data': d }, to_list=[friend_profile.user.email]) return True
def send_favorites(hours=25, queue=None, limit_to_username=None): from event.models import RecommendedEvent, Event from event.templatetags.eventtags import event_friends from registration.models import UserProfile now = date.today() add_date_threshold = date.today() - timedelta(hours=hours) profiles = UserProfile.objects.active().filter(send_favorites=True).order_by('pk') if limit_to_username: profiles = profiles.filter(user__username=limit_to_username) n = 0 q = queue or EventsQ(bind_queue=False) for p in profiles: a = p.user d = dict( email_type='favorites', attendee__username=a.username, attendee__email=a.email, attendee__first_name=a.first_name, attendee__last_name=a.last_name, attendee_profile_id=p.pk ) picks = Event.objects.active().select_related('artist').filter( recommendedevent__user_profile=p, recommendedevent__added_on__gte=add_date_threshold, ).distinct().order_by('event_date', 'event_start_time') if picks: ripe_picks = [] d['ripe_picks'] = ripe_picks for rp in picks: ripe = dict( event__event_url=rp.get_absolute_url(force_hostname=True), event__title=rp.title, event__event_date=date_filter(rp.event_date, "l, N j, Y"), event__event_start_time=time_filter(rp.event_start_time), event__event_timezone=rp.event_timezone, ) ripe_picks.append(ripe) num_fr = event_friends(rp, p).lower().replace('| ', '') if num_fr.endswith("friend"): num_fr = "<b>" + num_fr + "</b> is interested in" elif num_fr.endswith("friends"): num_fr = "<b>" + num_fr + "</b> are interested in" ripe['num_friends'] = num_fr send_event_reminder(d, queue=q, email_type='favorites') n += 1 _log.debug("%s event favorite emails sent", n)
def send_favorites(hours=25, queue=None, limit_to_username=None): from event.models import RecommendedEvent, Event from event.templatetags.eventtags import event_friends from registration.models import UserProfile now = date.today() add_date_threshold = date.today() - timedelta(hours=hours) profiles = UserProfile.objects.active().filter( send_favorites=True).order_by('pk') if limit_to_username: profiles = profiles.filter(user__username=limit_to_username) n = 0 q = queue or EventsQ(bind_queue=False) for p in profiles: a = p.user d = dict(email_type='favorites', attendee__username=a.username, attendee__email=a.email, attendee__first_name=a.first_name, attendee__last_name=a.last_name, attendee_profile_id=p.pk) picks = Event.objects.active().select_related('artist').filter( recommendedevent__user_profile=p, recommendedevent__added_on__gte=add_date_threshold, ).distinct().order_by('event_date', 'event_start_time') if picks: ripe_picks = [] d['ripe_picks'] = ripe_picks for rp in picks: ripe = dict( event__event_url=rp.get_absolute_url(force_hostname=True), event__title=rp.title, event__event_date=date_filter(rp.event_date, "l, N j, Y"), event__event_start_time=time_filter(rp.event_start_time), event__event_timezone=rp.event_timezone, ) ripe_picks.append(ripe) num_fr = event_friends(rp, p).lower().replace('| ', '') if num_fr.endswith("friend"): num_fr = "<b>" + num_fr + "</b> is interested in" elif num_fr.endswith("friends"): num_fr = "<b>" + num_fr + "</b> are interested in" ripe['num_friends'] = num_fr send_event_reminder(d, queue=q, email_type='favorites') n += 1 _log.debug("%s event favorite emails sent", n)
def event_faved(self, attendee): """Email users when a friend favorites an event they've favorited. The email will basically say "%Username% is on board with you for %Event%!". """ from event.templatetags.eventtags import event_friends from registration.models import Friendship if not attendee: return True event = attendee.event if not event.is_active: return True venue = event.venue user_profile = attendee.attendee_profile if not user_profile.user.is_active: return True friends = Friendship.objects.get_friendships( user_profile ).values_list('user_profile2_id', flat=True) friends = set(list(friends)) attendees = event.attendee_set.select_related('attendee_profile__user').filter( pk__lt=attendee.pk, # people that faved this event before this user attendee_profile__send_favorites=True, attendee_profile__user__is_active=True ) e, v = event, venue d = get_event_email_data(event, 'event-faved') for f in attendees: friend_profile = f.attendee_profile if friend_profile.pk in friends: num_fr = event_friends(event, friend_profile).lower().replace('|', '') if num_fr.endswith("friend"): num_fr = num_fr + " is in for this event" elif num_fr.endswith("friends"): num_fr = num_fr + " are in for this event" d['num_friends'] = num_fr subject = u'%s is on board with you for %s' % (user_profile.username.title(), event.title) email_template(subject, 'event/email/friend_is_on_board.html', {'event':event, 'user_profile':friend_profile, 'friend_profile':user_profile, 'data':d}, to_list=[friend_profile.user.email]) return True
def send_reminders(hours=32, queue=None, limit_to_username=None, location_list=None, current_time=None): from event.models import Attendee, Event from event.templatetags.eventtags import event_friends aq = Attendee.objects.select_related('event__artist', 'event__venue', 'attendee', 'attendee_profile__user') if hours < 24: now = current_time or datetime.now() today = now.date() next_hour = now + timedelta(hours=hours + 1) next_hour2 = next_hour + timedelta(hours=1) if next_hour2.hour < next_hour.hour: return # don't send reminders around midnight for now min_time = timex(hour=next_hour.hour) max_time = timex(hour=next_hour2.hour) _log.debug("Hourly %s, %s", min_time, max_time) if location_list: _log.debug("Locations: %s", location_list) evlist = aq.filter(event__is_deleted=False, event__is_approved=True, event__event_date=today, event__event_start_time__gte=min_time, event__event_start_time__lt=max_time, event__location__in=location_list, attendee__is_active=True, attendee_profile__send_reminders=True) else: evlist = aq.filter(event__is_deleted=False, event__is_approved=True, event__event_date=today, event__event_start_time__gte=min_time, event__event_start_time__lt=max_time, attendee__is_active=True, attendee_profile__send_reminders=True) else: now = date.today() end_date = date.today() + timedelta(hours=hours) evlist = aq.filter(event__is_deleted=False, event__is_approved=True, event__event_date__gte=now, event__event_date__lte=end_date, attendee__is_active=True, attendee_profile__send_reminders=True) evlist = evlist.order_by('event__event_date') if limit_to_username: evlist = evlist.filter(attendee__username=limit_to_username) num = evlist.count() if not num: return _log.debug( "Reminding people about %s events coming up in the next %s hours", num, hours) q = queue or EventsQ(bind_queue=False) for o in evlist: e = o.event v = e.venue a = o.attendee p = o.attendee_profile d = dict( email_type='reminder', event_id=e.pk, event__title=e.title, event__event_url=e.get_absolute_url(force_hostname=True), event__tweet_count=e.tweet_count, event__short_url=e.get_short_url(), event__ticket_url=e.ticket_or_tm_url, event__event_date=e.event_date, event__event_start_time=e.event_start_time, event__event_timezone=e.event_timezone, event__venue__name=v.name, event__venue__address=v.address, event__venue__citystatezip=v.citystatezip, event__venue__map_url=v.map_url, attendee__username=a.username, attendee__email=a.email, attendee__first_name=a.first_name, attendee__last_name=a.last_name, attendee_profile_id=p.pk, ) if hours < 2 and e.show_checkins: d['fsq_checkins'] = v.fsq_checkins d['fsq_ratio'] = v.fsq_ratio_display num_fr = event_friends(e, p).lower().replace('|', '') if num_fr.endswith("friend"): num_fr = num_fr + " is in for this event" elif num_fr.endswith("friends"): num_fr = num_fr + " are in for this event" d['num_friends'] = num_fr d['event__event_date'] = date_filter(d['event__event_date'], "l, N j, Y") if d['event__event_start_time']: d['event__event_start_time'] = time_filter( d['event__event_start_time']) # add ripe picks: # TODO: cache ripe picks for a few minutes picks = Event.objects.active().select_related('artist').filter( recommendedevent__user_profile=p).distinct().order_by('event_date') if picks: ripe_picks = [] d['ripe_picks'] = ripe_picks for rp in picks: ripe = dict( event__event_url=rp.get_absolute_url(force_hostname=True), event__title=rp.title, event__event_date=date_filter(rp.event_date, "l, N j, Y"), event__event_start_time=time_filter(rp.event_start_time), event__event_timezone=rp.event_timezone, ) ripe_picks.append(ripe) num_fr = event_friends(rp, p).lower().replace('| ', '') if num_fr.endswith("friend"): num_fr = "<b>" + num_fr + "</b> is interested in" elif num_fr.endswith("friends"): num_fr = "<b>" + num_fr + "</b> are interested in" ripe['num_friends'] = num_fr send_event_reminder(d, queue=q)
def send_reminders(hours=32, queue=None, limit_to_username=None, location_list=None, current_time=None): from event.models import Attendee, Event from event.templatetags.eventtags import event_friends aq = Attendee.objects.select_related('event__artist', 'event__venue', 'attendee', 'attendee_profile__user') if hours < 24: now = current_time or datetime.now() today = now.date() next_hour = now + timedelta(hours=hours+1) next_hour2 = next_hour + timedelta(hours=1) if next_hour2.hour < next_hour.hour: return # don't send reminders around midnight for now min_time = timex(hour=next_hour.hour) max_time=timex(hour=next_hour2.hour) _log.debug("Hourly %s, %s", min_time, max_time) if location_list: _log.debug("Locations: %s", location_list) evlist = aq.filter( event__is_deleted=False, event__is_approved=True, event__event_date=today, event__event_start_time__gte=min_time, event__event_start_time__lt=max_time, event__location__in=location_list, attendee__is_active=True, attendee_profile__send_reminders=True ) else: evlist = aq.filter( event__is_deleted=False, event__is_approved=True, event__event_date=today, event__event_start_time__gte=min_time, event__event_start_time__lt=max_time, attendee__is_active=True, attendee_profile__send_reminders=True ) else : now = date.today() end_date = date.today() + timedelta(hours=hours) evlist = aq.filter( event__is_deleted=False, event__is_approved=True, event__event_date__gte=now, event__event_date__lte=end_date, attendee__is_active=True, attendee_profile__send_reminders=True ) evlist = evlist.order_by('event__event_date') if limit_to_username: evlist = evlist.filter(attendee__username=limit_to_username) num = evlist.count() if not num: return _log.debug("Reminding people about %s events coming up in the next %s hours", num, hours) q = queue or EventsQ(bind_queue=False) for o in evlist: e = o.event v = e.venue a = o.attendee p = o.attendee_profile d = dict( email_type='reminder', event_id=e.pk, event__title=e.title, event__event_url=e.get_absolute_url(force_hostname=True), event__tweet_count=e.tweet_count, event__short_url=e.get_short_url(), event__ticket_url=e.ticket_or_tm_url, event__event_date=e.event_date, event__event_start_time=e.event_start_time, event__event_timezone=e.event_timezone, event__venue__name=v.name, event__venue__address=v.address, event__venue__citystatezip=v.citystatezip, event__venue__map_url=v.map_url, attendee__username=a.username, attendee__email=a.email, attendee__first_name=a.first_name, attendee__last_name=a.last_name, attendee_profile_id=p.pk, ) if hours < 2 and e.show_checkins: d['fsq_checkins'] = v.fsq_checkins d['fsq_ratio'] = v.fsq_ratio_display num_fr = event_friends(e, p).lower().replace('|', '') if num_fr.endswith("friend"): num_fr = num_fr + " is in for this event" elif num_fr.endswith("friends"): num_fr = num_fr + " are in for this event" d['num_friends'] = num_fr d['event__event_date'] = date_filter(d['event__event_date'], "l, N j, Y") if d['event__event_start_time']: d['event__event_start_time'] = time_filter(d['event__event_start_time']) # add ripe picks: # TODO: cache ripe picks for a few minutes picks = Event.objects.active().select_related('artist').filter( recommendedevent__user_profile=p ).distinct().order_by('event_date') if picks: ripe_picks = [] d['ripe_picks'] = ripe_picks for rp in picks: ripe = dict( event__event_url=rp.get_absolute_url(force_hostname=True), event__title=rp.title, event__event_date=date_filter(rp.event_date, "l, N j, Y"), event__event_start_time=time_filter(rp.event_start_time), event__event_timezone=rp.event_timezone, ) ripe_picks.append(ripe) num_fr = event_friends(rp, p).lower().replace('| ', '') if num_fr.endswith("friend"): num_fr = "<b>" + num_fr + "</b> is interested in" elif num_fr.endswith("friends"): num_fr = "<b>" + num_fr + "</b> are interested in" ripe['num_friends'] = num_fr send_event_reminder(d, queue=q)