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
    })
Exemple #2
0
    def get_or_create_or_delete_mailing_list_by_address(self, address):

        (canvas_course_id, section_id) = self._parse_address(address)
        if section_id:
            # if there is a section id, make sure that a section exists in canvas.
            canvas_section = canvas_api_client.get_section(
                canvas_course_id, section_id)
            if canvas_section:
                logger.debug(
                    'getting the mailing list for a section: {}'.format(
                        section_id))
                try:
                    mailing_list = MailingList.objects.get(
                        canvas_course_id=canvas_course_id,
                        section_id=section_id)
                except MailingList.DoesNotExist:
                    mailing_list = MailingList(
                        canvas_course_id=canvas_course_id,
                        section_id=section_id)
                    mailing_list.save()
            else:
                # Section with section_id no longer exists, so delete the associated mailing list
                MailingList.objects.get(canvas_course_id=canvas_course_id,
                                        section_id=section_id).delete()
                raise MailingList.DoesNotExist
        else:
            # if there is not a section_id, this is a class list, try to get it otherwise it will throw DoesNotExist
            # This address is created in the calling method.
            mailing_list = MailingList.objects.get(
                canvas_course_id=canvas_course_id, section_id__isnull=True)
        logger.debug('got mailing_list: {}'.format(mailing_list))
        return mailing_list
Exemple #3
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})
Exemple #4
0
    def get_or_create_or_delete_mailing_list_by_address(self, address):

        (canvas_course_id, section_id) = self._parse_address(address)
        if section_id:
            # if there is a section id, make sure that a section exists in canvas.
            canvas_section = canvas_api_client.get_section(canvas_course_id, section_id)
            if canvas_section:
                try:
                    mailing_list = MailingList.objects.get(canvas_course_id=canvas_course_id, section_id=section_id)
                except MailingList.DoesNotExist:
                    mailing_list = MailingList(canvas_course_id=canvas_course_id, section_id=section_id)
                    mailing_list.save()
            else:
                # Section with section_id no longer exists, so delete the associated mailing list
                MailingList.objects.get(canvas_course_id=canvas_course_id, section_id=section_id).delete()
                raise MailingList.DoesNotExist
        else:
            # if there is not a section_id, this is a class list, try to get it otherwise it will throw DoesNotExist
            # This address is created in the calling method.
            mailing_list = MailingList.objects.get(canvas_course_id=canvas_course_id, section_id__isnull=True)
            
        return mailing_list