def list_members(request, section_id=None):
    canvas_course_id = request.LTI.get('custom_canvas_course_id')

    if not canvas_course_id:
        return HttpResponseBadRequest('Unable to determine canvas course id')

    logger.info(
        'Rendering mailing_list section_list_details view for canvas course %s '
        'section %s', canvas_course_id, section_id)

    if section_id:
        mailing_list = get_object_or_404(MailingList,
                                         canvas_course_id=canvas_course_id,
                                         section_id=section_id)
    else:
        mailing_list = get_object_or_404(MailingList,
                                         canvas_course_id=canvas_course_id,
                                         section_id__isnull=True)

    enrollments = get_enrollments(canvas_course_id, section_id)
    canvas_api_helpers_enrollments.add_role_labels_to_enrollments(enrollments)
    enrollments.sort(key=lambda x: x['sortable_name'])
    section = get_section(canvas_course_id, section_id)

    if not section:
        course_code = get_course(canvas_course_id)['course_code']
        section = {
            'id': 0,
            'name': course_code,
        }

    return render(request, 'mailing_list/list_details.html', {
        'section': section,
        'enrollments': enrollments
    })
Exemplo n.º 2
0
def list_members(request, section_id=None):
    canvas_course_id = request.LTI.get('custom_canvas_course_id')

    if not canvas_course_id:
        return HttpResponseBadRequest('Unable to determine canvas course id')

    logger.info(
        u'Rendering mailing_list section_list_details view for canvas course %s '
        u'section %s', canvas_course_id, section_id)

    if section_id:
        mailing_list = get_object_or_404(MailingList, canvas_course_id=canvas_course_id, section_id=section_id)
    else:
        mailing_list = get_object_or_404(MailingList, canvas_course_id=canvas_course_id, section_id__isnull=True)

    enrollments = get_enrollments(canvas_course_id, section_id)

    enrollments.sort(key=lambda x: x['sortable_name'])
    section = get_section(canvas_course_id, section_id)

    if not section:
        course_code = get_course(canvas_course_id)['course_code']
        section = {
            'id': 0,
            'name': course_code,
        }

    return render(request, 'mailing_list/list_details.html',
                  {'section': section,
                   'enrollments': enrollments})
    def _get_enrolled_email_set(self):

        """
        When we add enrollment emails to the mailing list, check if this is a whole course list
        by checking if the section_id is 0. If it is we want to add all the enrollments that exist
        in the course. If not, we build the mailing with the enrollments for the specified section.
        """
        return {
            e['email'].lower() for e in canvas_api_client.get_enrollments(self.canvas_course_id, self.section_id)
            if e.get('email') is not None
        }
Exemplo n.º 4
0
 def _get_enrolled_email_set(self):
     """
     When we add enrollment emails to the mailing list, check if this is a whole course list
     by checking if the section_id is 0. If it is we want to add all the enrollments that exist
     in the course. If not, we build the mailing with the enrollments for the specified section.
     """
     return {
         e['email'].lower()
         for e in canvas_api_client.get_enrollments(self.canvas_course_id,
                                                    self.section_id)
         if e.get('email') is not None
     }