Ejemplo n.º 1
0
 def handle(self, *args, **options):
     tomorrow = arrow.utcnow().replace(hour=6, days=1).datetime
     next_day = arrow.utcnow().replace(hour=6, days=2).datetime
     class_times = ClassTime.objects.filter(start__gte=tomorrow,
                                            start__lte=next_day,
                                            emailed__isnull=True)
     class_times = class_times.exclude(
         session__course__active=False).exclude(
             session__active=False).distinct()
     if not class_times:
         return
     print "showing classes from %s to %s" % (tomorrow, next_day)
     print "reminding %s class times" % len(class_times)
     instructor_count = 0
     student_count = 0
     sent = []
     for class_time in class_times:
         instructor_count += 1
         instructor = class_time.session.user
         _dict = {
             'user': instructor,
             'la_key': LimitedAccessKey.new(instructor),
             'SITE_URL': settings.SITE_URL,
             'session': class_time.session,
             'class_time': class_time,
         }
         send_template_email("email/teaching_reminder",
                             instructor.email,
                             context=_dict,
                             experimental=False)
         for enrollment in class_time.session.enrollment_set.all():
             student_count += 1
             user = enrollment.user
             _dict = {
                 'user': user,
                 'la_key': LimitedAccessKey.new(user),
                 'SITE_URL': settings.SITE_URL,
                 'session': class_time.session,
                 'class_time': class_time,
             }
             if user.email in sent:
                 continue
             sent.append(user.email)
             send_template_email("email/course_reminder",
                                 user.email,
                                 context=_dict,
                                 experimental=False)
         class_time.emailed = arrow.utcnow().datetime
         class_time.save()
     print "\n\n\nemailed %s instructors and %s students" % (
         instructor_count, student_count)
Ejemplo n.º 2
0
 def handle(self, *args, **options):
   yesterday = datetime.datetime.now()-datetime.timedelta(7)
   pe = Enrollment.objects.pending_evaluation()
   pe = pe.filter(evaluation_date__gte=yesterday)
   if pe.count() and options.get("verbosity") > 0:
     print "sending %s evaluation emails"%pe.count()
   for enrollment in pe:
     if not enrollment.user.email:
       continue
     _dict = {
       'evaluation': enrollment,
       'la_key': LimitedAccessKey.new(enrollment.user),
       'domain': settings.SITE_URL,
       'settings': settings
     }
     subject = "Please evaluate the class you took from %s"%settings.SITE_NAME
     if enrollment.session.course.get_private_files():
       subject = "Course files and pending evaluation for %s"%enrollment.session.course
     send_mail(
       subject,
       render_to_string("email/pending_evaluation.html",_dict),
       settings.DEFAULT_FROM_EMAIL,
       [enrollment.user.email]
     )
     enrollment.emailed=True
     enrollment.save()
Ejemplo n.º 3
0
 def handle(self, *args, **options):
   send_mail(
     'Sending evaluations reminders!',
     'this is to inform you that they have been sent. Hopefully they did not go twice',
     settings.DEFAULT_FROM_EMAIL,
     ['*****@*****.**'],
     )
   yesterday = datetime.datetime.now()-datetime.timedelta(1)
   pe = Enrollment.objects.pending_evaluation()
   pe = pe.filter(evaluation_date__gte=yesterday)
   print "sending %s evaluation emails"%pe.count()
   for evaluation in pe:
     if not evaluation.user.email:
       continue
     _dict = {
       'evaluation': evaluation,
       'la_key': LimitedAccessKey.new(evaluation.user),
       'domain': settings.SITE_URL
       }
     send_mail(
       "Please evaluate the class you took from TX/RX",
       render_to_string("email/pending_evaluation.html",_dict),
       settings.DEFAULT_FROM_EMAIL,
       [evaluation.user.email]
       )
Ejemplo n.º 4
0
 def handle(self, *args, **options):
     new_sessions = Session.objects.filter(
         active=True, notified__isnull=True).exclude(private=True)
     count = new_sessions.count()
     if not new_sessions:
         mail_admins("No classes",
                     "No new classes to notify anyone about :(")
         return
     courses = list(set([s.course for s in new_sessions]))
     users = get_user_model().objects.filter(
         notifycourse__course__in=courses).distinct()
     for user in users:
         sessions = [
             s for s in new_sessions
             if user.notifycourse_set.filter(course=s.course)
         ]
         _dict = {
             'user': user,
             'la_key': LimitedAccessKey.new(user),
             'SITE_URL': settings.SITE_URL,
             'new_sessions': sessions,
         }
         send_mail(
             "New classes at the hackerspace",
             render_to_string("notify/notify_course.html", _dict),
             settings.DEFAULT_FROM_EMAIL,
             [user.email],
         )
     new_sessions.update(notified=datetime.datetime.now())
     print "Notified %s users of %s classes" % (len(users), count)
Ejemplo n.º 5
0
 def handle(self, *args, **options):
     user = get_user_model()
     dt = datetime.datetime.now() + datetime.timedelta(-16)
     new_sessions = Session.objects.filter(
         created__gte=dt, first_date__gte=datetime.datetime.now())
     new_sessions = new_sessions.exclude(private=True)
     if not new_sessions:
         print "No classes", "No new classes to email anyone about :("
         return
     kwargs = dict(usermembership__notify_sessions=True,
                   usermembership__notify_global=True)
     users = User.objects.filter(**kwargs)
     for user in users:
         _dict = {
             'user': user,
             'la_key': LimitedAccessKey.new(user),
             'SITE_URL': settings.SITE_URL,
             'new_sessions': new_sessions,
         }
         send_mail(
             "New classes at the hackerspace",
             render_to_string("email/new_classes.html", _dict),
             settings.DEFAULT_FROM_EMAIL,
             [user.email],
         )
     print "Emailed %s users:\n\n\n%s" % (
         len(users), render_to_string("email/new_classes.html", _dict))
Ejemplo n.º 6
0
 def handle(self, *args, **options):
   tomorrow = arrow.utcnow().replace(hour=6,days=1).datetime
   next_day = arrow.utcnow().replace(hour=6,days=2).datetime
   class_times = ClassTime.objects.filter(start__gte=tomorrow,start__lte=next_day,emailed__isnull=True)
   class_times = class_times.exclude(session__course__active=False).exclude(session__active=False).distinct()
   if not class_times:
     return
   print "showing classes from %s to %s"%(tomorrow,next_day)
   print "reminding %s class times"%len(class_times)
   instructor_count = 0
   student_count = 0
   sent = []
   for class_time in class_times:
     instructor_count += 1
     instructor = class_time.session.user
     _dict = {
       'user': instructor,
       'la_key': LimitedAccessKey.new(instructor),
       'SITE_URL': settings.SITE_URL,
       'session': class_time.session,
       'class_time': class_time,
     }
     send_template_email("email/teaching_reminder",instructor.email,context=_dict)
     for enrollment in class_time.session.enrollment_set.all():
       student_count += 1
       user = enrollment.user
       _dict = {
         'user': user,
         'la_key': LimitedAccessKey.new(user),
         'SITE_URL': settings.SITE_URL,
         'session': class_time.session,
         'class_time': class_time,
       }
       if user.email in sent:
         continue
       sent.append(user.email)
       send_template_email("email/course_reminder",user.email,context=_dict)
     class_time.emailed = arrow.utcnow().datetime
     class_time.save()
   print "\n\n\nemailed %s instructors and %s students"%(instructor_count,student_count)
Ejemplo n.º 7
0
def new_comment_connection(sender, instance=None, created=False, **kwargs):
    if not created:
        return
    _dict = {
        'content':
        instance.comment,
        'admin_url':
        _u(
            reverse('admin:unrest_comments_unrestcomment_change',
                    args=[instance.id])),
        'object_name':
        instance.content_object,
        'admin_email':
        settings.ADMINS[0][1],
    }

    try:
        _dict['object_url'] = _u(
            instance.content_object.get_absolute_url()) + "#c%s" % instance.id
    except AttributeError:
        _dict['object_url'] = _u(instance.get_absolute_url())
    users = []

    if instance.parent:
        # email whoever wrote the parent comment
        user = instance.parent.user
        if user.usermembership.notify_comments and user.usermembership.notify_global:
            # this conditional is incase they opt out
            key = LimitedAccessKey.new(user).key
            _dict['unsubscribe_url'] = _u(
                reverse("unsubscribe", args=['comments', user.id]) +
                "?LA_KEY=" + key)
            subject = 'Someone responded to your comment'
            send_mail(subject, comment_response_email % _dict,
                      settings.DEFAULT_FROM_EMAIL, [user.email])
    else:
        # email the course instructor or whoever is in the "users" list
        users = getattr(settings, 'COMMENT_ADMINS', [])
        try:
            users += [
                user.email for user in instance.content_object.list_users
            ]
        except AttributeError:
            pass
        subject = 'New comment on %s' % instance.content_object
        send_mail(subject, admin_comment_email % _dict,
                  settings.DEFAULT_FROM_EMAIL, list(set(users)))
Ejemplo n.º 8
0
 def handle(self, *args, **options):
   dt = datetime.datetime.now() + datetime.timedelta(-16)
   new_sessions = Session.objects.filter(created__gte=dt,first_date__gte=datetime.datetime.now())
   if not new_sessions:
     mail_admins("No classes","No new classes to email anyone about :(")
     return
   kwargs = dict(usermembership__notify_sessions=True,usermembership__notify_global=True)
   users = User.objects.filter(**kwargs)
   for user in users:
     _dict = {
       'user': user,
       'la_key': LimitedAccessKey.new(user),
       'SITE_URL': settings.SITE_URL,
       'new_sessions': new_sessions,
       }
     send_mail(
       "[TX/RX] New classes at the hackerspace",
       render_to_string("email/new_classes.html",_dict),
       settings.DEFAULT_FROM_EMAIL,
       [user.email],
       )
Ejemplo n.º 9
0
def new_comment_connection(sender, instance=None, created=False,**kwargs):
  if not created:
    return
  _dict = {
    'content': instance.comment,
    'admin_url': _u(reverse('admin:mptt_comments_mpttcomment_change',args=[instance.id])),
    'object_name': instance.content_object,
    'admin_email': settings.ADMINS[0][1],
    }

  try:
    _dict['object_url'] = _u(instance.content_object.get_absolute_url()) + "#c%s"%instance.id
  except AttributeError:
    _dict['object_url'] = _u(instance.get_absolute_url())
  users = []

  if instance.parent:
    # email whoever wrote the parent comment
    user = instance.parent.user
    if user.usermembership.notify_comments and user.usermembership.notify_global:
      print user
      # this conditional is incase they opt out
      key = LimitedAccessKey.new(user).key
      _dict['unsubscribe_url'] = _u(reverse("unsubscribe",args=['comments',user.id])+"?LA_KEY="+key)
      subject = 'Someone responded to your comment'
      send_mail(
        subject,
        comment_response_email%_dict,
        settings.DEFAULT_FROM_EMAIL,
        [user.email])
  else:
    # email the course instructor or whoever is in the "users" list
    try:
      users = [user.email for user in instance.content_object.list_users]
    except AttributeError:
      pass

  mail_admins('New Comment',admin_comment_email%_dict,users)
Ejemplo n.º 10
0
  def handle(self, *args, **options):
    dt = datetime.datetime.now()-datetime.timedelta(2)
    new_sessions = Session.objects.filter(created__gte=dt,first_date__gte=datetime.datetime.now())

    if not new_sessions:
      mail_admins("No classes","No new classes to email anyone about :(")
      return
    courses = list(set([s.section.course for s in new_sessions]))
    users = User.objects.filter(notifycourse__course__in=courses).distinct()
    for user in users:
      sessions = [s for s in new_sessions if user.notifycourse_set.filter(course=s.section.course)]
      _dict = {
        'user': user,
        'la_key': LimitedAccessKey.new(user),
        'SITE_URL': settings.SITE_URL,
        'new_sessions': sessions,
        }
      send_mail(
        "[TX/RX] New classes at the hackerspace",
        render_to_string("notify/notify_course.html",_dict),
        settings.DEFAULT_FROM_EMAIL,
        [user.email],
        )
Ejemplo n.º 11
0
 def handle(self, *args, **options):
   today = datetime.datetime.now()
   tomorrow = datetime.datetime.now()+datetime.timedelta(1)
   class_times = ClassTime.objects.filter(start__gte=today,start__lte=tomorrow)
   for class_time in class_times:
     sent = []
     for enrollment in class_time.session.enrollment_set.all():
       user = enrollment.user
       _dict = {
         'user': user,
         'la_key': LimitedAccessKey.new(user),
         'SITE_URL': settings.SITE_URL,
         'session': class_time.session,
         'class_time': class_time,
         }
       if user.email in sent:
         continue
       sent.append(user.email)
       send_mail(
         "[TX/RX] Class today!",
         render_to_string("email/course_reminder.html",_dict),
         settings.DEFAULT_FROM_EMAIL,
         [user.email],
         )
Ejemplo n.º 12
0
def new_comment_connection(sender, instance=None, created=False,**kwargs):
  if not created:
    return
  _dict = {
    'content': instance.comment,
    'admin_url': _u(reverse('admin:unrest_comments_unrestcomment_change',args=[instance.id])),
    'object_name': instance.content_object,
    'admin_email': settings.ADMINS[0][1],
  }

  try:
    _dict['object_url'] = _u(instance.content_object.get_absolute_url()) + "#c%s"%instance.id
  except AttributeError:
    _dict['object_url'] = _u(instance.get_absolute_url())
  users = []

  try:
    url = instance.content_object.get_absolute_url()
  except AttributeError:
    url = None
  _kwargs = {
    'target_type': 'unrest_comments.unrestcomment',
    'target_id': instance.id,
    'url': url,
    'emailed': timezone.now(),
  }
  if instance.parent:
    # email whoever wrote the parent comment
    user = instance.parent.user
    Notification.objects.create(
      message='Comment Reply on "%s" from %s'%(instance.content_object,instance.user),
      user=user,
      relationship='comment_reply',
      **_kwargs
    )
    key = LimitedAccessKey.new(user).key
    _dict['unsubscribe_url'] = _u(reverse("unsubscribe",args=['comments',user.id])+"?LA_KEY="+key)
    if user.notifysettings.new_comments == "sms":
      user.send_sms("%s has replied to your comment. Visit new.txrxlabs.org for more info."%(instance.user or "Anon"))
    elif user.notifysettings.new_comments == "email":
      subject = 'Someone responded to your comment'
      send_mail(
        subject,
        comment_response_email%_dict,
        settings.DEFAULT_FROM_EMAIL,
        [user.email]
      )
  else:
    # email the course instructor or whoever is in the "users" list
    users = list(get_user_model().objects.filter(id__in=getattr(settings,'COMMENT_ADMIN_IDS',[])))
    try:
      users += instance.content_object.list_users
    except AttributeError:
      pass
    users = set(users)
    for user in users:
      Notification.objects.create(
        message='New comment on %s from %s'%(instance.content_object,instance.user),
        user=user,
        relationship='new_comment',
        **_kwargs
      )
      if user.notifysettings.new_comments == "sms":
        user.send_sms("There is a new comment by %s. Visit new.txrxlabs.org for more info."%(instance.user or "Anon"))
      elif user.notifysettings.new_comments == "email":
        subject = 'New comment on %s'%instance.content_object
        send_mail(subject,admin_comment_email%_dict,settings.DEFAULT_FROM_EMAIL,[user.email])
Ejemplo n.º 13
0
def new_comment_connection(sender, instance=None, created=False, **kwargs):
    if not created:
        return
    _dict = {
        'content':
        instance.comment,
        'admin_url':
        _u(
            reverse('admin:unrest_comments_unrestcomment_change',
                    args=[instance.id])),
        'object_name':
        instance.content_object,
        'admin_email':
        settings.ADMINS[0][1],
    }

    try:
        _dict['object_url'] = _u(
            instance.content_object.get_absolute_url()) + "#c%s" % instance.id
    except AttributeError:
        _dict['object_url'] = _u(instance.get_absolute_url())
    users = []

    try:
        url = instance.content_object.get_absolute_url()
    except AttributeError:
        url = None
    _kwargs = {
        'target_type': 'unrest_comments.unrestcomment',
        'target_id': instance.id,
        'url': url,
        'emailed': timezone.now(),
    }
    if instance.parent:
        # email whoever wrote the parent comment
        user = instance.parent.user
        Notification.objects.create(message='Comment Reply on "%s" from %s' %
                                    (instance.content_object, instance.user),
                                    user=user,
                                    relationship='comment_reply',
                                    **_kwargs)
        key = LimitedAccessKey.new(user).key
        _dict['unsubscribe_url'] = _u(
            reverse("unsubscribe", args=['comments', user.id]) + "?LA_KEY=" +
            key)
        if user.notifysettings.new_comments == "sms":
            user.send_sms(
                "%s has replied to your comment. Visit new.txrxlabs.org for more info."
                % (instance.user or "Anon"))
        elif user.notifysettings.new_comments == "email":
            subject = 'Someone responded to your comment'
            send_mail(subject, comment_response_email % _dict,
                      settings.DEFAULT_FROM_EMAIL, [user.email])
    else:
        # email the course instructor or whoever is in the "users" list
        users = list(get_user_model().objects.filter(
            id__in=getattr(settings, 'COMMENT_ADMIN_IDS', [])))
        try:
            users += instance.content_object.list_users
        except AttributeError:
            pass
        users = set(users)
        for user in users:
            Notification.objects.create(
                message='New comment on %s from %s' %
                (instance.content_object, instance.user),
                user=user,
                relationship='new_comment',
                **_kwargs)
            if user.notifysettings.new_comments == "sms":
                user.send_sms(
                    "There is a new comment by %s. Visit new.txrxlabs.org for more info."
                    % (instance.user or "Anon"))
            elif user.notifysettings.new_comments == "email":
                subject = 'New comment on %s' % instance.content_object
                send_mail(subject, admin_comment_email % _dict,
                          settings.DEFAULT_FROM_EMAIL, [user.email])
Ejemplo n.º 14
0
    def handle(self, *args, **options):
        # First people who are following classes
        notifications = Notification.objects.filter(
            emailed__isnull=True, target_type='course.session')
        students = get_user_model().objects.filter(
            id__in=set(notifications.values_list("user", flat=True)))
        count = 0
        users_count = len(students)
        if not users_count and not settings.TESTING:
            mail_admins("No classes",
                        "No new classes to notify anyone about :(")
        for user in students:
            notifications = user.notification_set.filter(
                emailed__isnull=True, target_type="course.session")
            count += notifications.count()
            sessions = [n.target for n in notifications]
            _dict = {
                'user': user,
                'la_key': LimitedAccessKey.new(user),
                'new_sessions': sessions,
                'notifications': notifications,
            }
            if user.notifysettings.new_sessions == "email":
                send_template_email("notify/email/course", [user.email],
                                    context=_dict)
            elif user.notifysettings.new_sessions == "sms":
                c = sessions[0].course.get_short_name()
                p = ""
                if len(sessions) > 1:
                    p = " and %s other classes you are interested in" % (
                        len(sessions) - 1)
                m = "There a new session of %s%s at %s. Visit %s to find out more"

                user.send_sms(m %
                              (c, p, settings.SITE_NAME, settings.NOTIFY_URL))
            notifications.update(emailed=datetime.datetime.now())
        # Now hit up enrollments that are happening tomorrow
        for relationship in ["teaching_reminder", "course_reminder"]:
            _notifications = Notification.objects.filter(
                emailed__isnull=True, target_type="course.classtime")
            _notifications = _notifications.filter(relationship=relationship)
            followers = get_user_model().objects.filter(
                id__in=set(_notifications.values_list("user", flat=True)))
            users_count = len(followers)
            for user in followers:
                notifications = user.notification_set.filter(
                    emailed__isnull=True,
                    target_type="course.classtime",
                    relationship=relationship,
                )
                count += notifications.count()
                classtimes = sorted([n.target for n in notifications],
                                    key=lambda ct: ct.start)
                if user.notifysettings.my_classes == "email":
                    _dict = {
                        'user': user,
                        'la_key': LimitedAccessKey.new(user),
                        'SITE_URL': settings.SITE_URL,
                        'notifications': notifications,
                        'first_classtime': classtimes[0],
                        'classtimes': classtimes
                    }
                    send_template_email("email/%s" % relationship,
                                        [user.email, '*****@*****.**'],
                                        context=_dict)
                elif user.notifysettings.my_classes == "sms":
                    course_name = classtimes[0].session.course.get_short_name()
                    time_s = date(classtimes[0].start, "P")
                    if len(classtimes) == 1:
                        body = "You have class tomorrow at %s: %s @ %s" % (
                            settings.SITE_NAME, course_name, time_s)
                    else:
                        body = "You have %s classes tomorrow at %s. The first is: %s @ %s" % (
                            len(classtimes), settings.SITE_NAME, course_name,
                            time_s)
                    user.send_sms(body)

                notifications.update(emailed=datetime.datetime.now())
            if options.get("verbosity") > 0:
                print "%s: Notified %s users of %s notifications" % (
                    relationship, users_count, count)
Ejemplo n.º 15
0
  def handle(self, *args, **options):
    # First people who are following classes
    notifications = Notification.objects.filter(emailed__isnull=True,target_type='course.session')
    students = get_user_model().objects.filter(id__in=set(notifications.values_list("user",flat=True)))
    count = 0
    users_count = len(students)
    if not users_count and not settings.TESTING:
      mail_admins("No classes","No new classes to notify anyone about :(")
    for user in students:
      notifications = user.notification_set.filter(emailed__isnull=True,target_type="course.session")
      count += notifications.count()
      sessions = [n.target for n in notifications]
      _dict = {
        'user': user,
        'la_key': LimitedAccessKey.new(user),
        'new_sessions': sessions,
        'notifications': notifications,
      }
      if user.notifysettings.new_sessions == "email":
        send_template_email("notify/email/course",[user.email],context=_dict)
      elif user.notifysettings.new_sessions == "sms":
        c = sessions[0].course.get_short_name()
        p = ""
        if len(sessions) > 1:
          p = " and %s other classes you are interested in"%(len(sessions) - 1)
        m = "There a new session of %s%s at %s. Visit %s to find out more"

        user.send_sms(m%(c,p,settings.SITE_NAME,settings.NOTIFY_URL))
      notifications.update(emailed=datetime.datetime.now())
    # Now hit up enrollments that are happening tomorrow
    for relationship in ["teaching_reminder","course_reminder"]:
      _notifications = Notification.objects.filter(emailed__isnull=True,target_type="course.classtime")
      _notifications = _notifications.filter(relationship=relationship)
      followers = get_user_model().objects.filter(id__in=set(_notifications.values_list("user",flat=True)))
      users_count = len(followers)
      for user in followers:
        notifications = user.notification_set.filter(
          emailed__isnull=True,
          target_type="course.classtime",
          relationship=relationship,
        )
        count += notifications.count()
        classtimes = sorted([n.target for n in notifications],key=lambda ct: ct.start)
        if user.notifysettings.my_classes == "email":
          _dict = {
            'user': user,
            'la_key': LimitedAccessKey.new(user),
            'SITE_URL': settings.SITE_URL,
            'notifications': notifications,
            'first_classtime': classtimes[0],
            'classtimes': classtimes
          }
          send_template_email("email/%s"%relationship,[user.email,'*****@*****.**'],context=_dict)
        elif user.notifysettings.my_classes == "sms":
          course_name = classtimes[0].session.course.get_short_name()
          time_s = date(classtimes[0].start,"P")
          if len(classtimes) == 1:
            body = "You have class tomorrow at %s: %s @ %s"%(settings.SITE_NAME,course_name,time_s)
          else:
            body = "You have %s classes tomorrow at %s. The first is: %s @ %s"%(len(classtimes),settings.SITE_NAME,course_name,time_s)
          user.send_sms(body)

        notifications.update(emailed=datetime.datetime.now())
      if options.get("verbosity") > 0:
        print "%s: Notified %s users of %s notifications"%(relationship,users_count,count)