Exemplo n.º 1
0
def task_course_notifications():
    log.info('Getting courses')
    courses = get_visible_courses()

    while courses:
        log.info('Pop first course')
        course = courses[-1]

        # we're interested only in dates
        log.info('Getting course start date')
        course_start_date = course.start.date()
        log.info('Today date')
        date_now = datetime.now(utc).date()

        log.info('Setting up email context')
        context = {
            'course_name': course.display_name,
            'course_url': get_course_link(course_id=course.id)
        }

        # send email when 7 days left to course start
        if course_start_date - timedelta(days=7) == date_now:
            send_course_notification_email(course=course,
                                           template_name=MandrillClient.COURSE_EARLY_WELCOME_TEMPLATE,
                                           context=context)
        # send email when 2 days left to course start
        elif course_start_date - timedelta(days=2) == date_now:
            send_course_notification_email(course=course,
                                           template_name=MandrillClient.COURSE_START_REMINDER_TEMPLATE,
                                           context=context)
        # send email the day the course starts
        elif course_start_date == date_now:
            send_course_notification_email(course=course,
                                           template_name=MandrillClient.COURSE_WELCOME_TEMPLATE,
                                           context={'course_name': course.display_name,
                                                    'course_url': get_course_first_chapter_link(course)
                                                    }
                                           )

        log.info('CELERY-TASK: date_now: %s, course_start_date: %s',
            date_now,
            course_start_date,
            )

        if course.end:
            log.info('CELERY-TASK: course_end_date: %s', course.end.date())

        log.info("Finishing celery task")

        courses.pop()
Exemplo n.º 2
0
def get_courses(user, org=None, filter_=None):
    """
    Return a LazySequence of courses available, optionally filtered by org code (case-insensitive).
    """
    courses = branding.get_visible_courses(
        org=org,
        filter_=filter_,
    ).prefetch_related('modes', ).select_related('image_set')

    permission_name = configuration_helpers.get_value(
        'COURSE_CATALOG_VISIBILITY_PERMISSION',
        settings.COURSE_CATALOG_VISIBILITY_PERMISSION)

    return LazySequence(
        (c for c in courses if has_access(user, permission_name, c)),
        est_len=courses.count())
Exemplo n.º 3
0
def get_courses(user, org=None, filter_=None, permissions=None):
    """
    Return a LazySequence of courses available, optionally filtered by org code
    (case-insensitive) or a set of permissions to be satisfied for the specified
    user.
    """

    courses = branding.get_visible_courses(
        org=org,
        filter_=filter_,
    ).prefetch_related('modes', ).select_related('image_set')

    permissions = set(permissions or '')
    permission_name = configuration_helpers.get_value(
        'COURSE_CATALOG_VISIBILITY_PERMISSION',
        settings.COURSE_CATALOG_VISIBILITY_PERMISSION)
    permissions.add(permission_name)

    return LazySequence(
        (c
         for c in courses if all(has_access(user, p, c) for p in permissions)),
        est_len=courses.count())