Exemple #1
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 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 #3
0
def admin_index(request):
    logged_in_user_id = request.LTI['lis_person_sourcedid']
    canvas_course_id = request.LTI.get('custom_canvas_course_id')

    course_code = get_course(canvas_course_id)['course_code']

    logger.info(u"Rendering mailing_list admin_index view for user %s",
                logged_in_user_id)
    return render(request, 'mailing_list/admin_index.html', {'course_code': course_code})
def admin_index(request):
    logged_in_user_id = request.LTI['lis_person_sourcedid']
    canvas_course_id = request.LTI.get('custom_canvas_course_id')
    build_info = settings.BUILD_INFO

    course = get_course(canvas_course_id)

    if course['name']:
        course_name = course['name']
    elif course['course_code']:
        course_name = course['course_code']
    else:
        course_name = canvas_course_id

    logger.info("Rendering mailing_list admin_index view for user %s",
                logged_in_user_id)
    return render(request, 'mailing_list/admin_index.html', {
        'course_name': course_name,
        'build_info': build_info
    })
Exemple #5
0
    def get_or_create_or_delete_mailing_lists_for_canvas_course_id(
            self, canvas_course_id, **kwargs):
        """
        Gets the mailing list data for all sections related to the given canvas_course_id.
        Creates MailingList models and corresponding listserv mailing lists if a given section's
        mailing list does not yet exist. This will also sync the mailing list membership with the
        course enrollments when creating new mailing lists.

        :param canvas_course_id:
        :param kwargs:
        :return: List of mailing list dictionaries for the given canvas_course_id
        """
        sis_course_id = canvas_api_client.get_course(
            canvas_course_id)['sis_course_id']
        canvas_sections = canvas_api_client.get_sections(canvas_course_id)
        mailing_lists_by_section_id = self._get_mailing_lists_by_section_id(
            canvas_course_id)

        overrides = kwargs.get('defaults', {})
        result = []

        try:
            # Check if there is a  Course list(Meta mailing list)
            course_list = mailing_lists_by_section_id.pop(None)
        except KeyError:
            course_list = None

        if not course_list:
            create_kwargs = {
                'canvas_course_id': canvas_course_id,
                'section_id': None
            }
            create_kwargs.update(overrides)
            course_list = MailingList(**create_kwargs)
            course_list.save()

        # if there is a course_list, add it to the result list so
        # it can be used by the template.
        if course_list:
            result.append({
                'id': course_list.id,
                'canvas_course_id': course_list.canvas_course_id,
                'sis_section_id': None,
                'section_id': course_list.section_id,
                'name': 'Course Mailing List',
                'address': course_list.address,
                'access_level': course_list.access_level,
                'members_count': len(course_list.members),
                'is_course_list': True,
                'cs_class_type': None,
                'is_primary': False,
            })

        for s in canvas_sections:
            section_id = s['id']
            try:
                mailing_list = mailing_lists_by_section_id.pop(section_id)
            except KeyError:
                mailing_list = None

            if not mailing_list:
                create_kwargs = {
                    'canvas_course_id': canvas_course_id,
                    'section_id': section_id
                }
                create_kwargs.update(overrides)
                mailing_list = MailingList(**create_kwargs)
                mailing_list.save()

            # cs_class_type is used to determine if the section
            # is an enrollment section or a non-enrollment section.
            # if it's null for a section with a real sis section id, we
            # should consider it an enrollment section.
            cs_class_type = None
            if s['sis_section_id'] and s['sis_section_id'].isdigit():
                logger.debug('Looking up section id %s' % s['sis_section_id'])
                cs_class_type = get_section_sis_enrollment_status(
                    s['sis_section_id'])

            result.append({
                'id': mailing_list.id,
                'canvas_course_id': mailing_list.canvas_course_id,
                'sis_section_id': s['sis_section_id'] or None,
                'section_id': mailing_list.section_id,
                'name': s['name'],
                'address': mailing_list.address,
                'access_level': mailing_list.access_level,
                'members_count': len(mailing_list.members),
                'is_course_list': False,
                'cs_class_type': cs_class_type,
                'is_primary': s['sis_section_id'] == sis_course_id,
            })

        # Delete existing mailing lists who's section no longer exists
        for section_id, mailing_list in mailing_lists_by_section_id.items():
            mailing_list.delete()

        return result
    def get_or_create_or_delete_mailing_lists_for_canvas_course_id(self, canvas_course_id, **kwargs):
        """
        Gets the mailing list data for all sections related to the given canvas_course_id.
        Creates MailingList models and corresponding listserv mailing lists if a given section's
        mailing list does not yet exist. This will also sync the mailing list membership with the
        course enrollments when creating new mailing lists.

        :param canvas_course_id:
        :param kwargs:
        :return: List of mailing list dictionaries for the given canvas_course_id
        """
        sis_course_id = canvas_api_client.get_course(canvas_course_id)['sis_course_id']
        canvas_sections = canvas_api_client.get_sections(canvas_course_id)
        mailing_lists_by_section_id = self._get_mailing_lists_by_section_id(canvas_course_id)

        overrides = kwargs.get('defaults', {})
        result = []

        try:
            # Check if there is a  Course list(Meta mailing list)
            course_list = mailing_lists_by_section_id.pop(None)
        except KeyError:
            course_list = None

        if not course_list:
            create_kwargs = {
                'canvas_course_id': canvas_course_id,
                'section_id': None
            }
            create_kwargs.update(overrides)
            course_list = MailingList(**create_kwargs)
            course_list.save()

        # if there is a course_list, add it to the result list so
        # it can be used by the template.
        if course_list:
            result.append({
                'id': course_list.id,
                'canvas_course_id': course_list.canvas_course_id,
                'sis_section_id': None,
                'section_id': course_list.section_id,
                'name': 'Course Mailing List',
                'address': course_list.address,
                'access_level': course_list.access_level,
                'members_count': len(course_list.members),
                'is_course_list': True,
                'cs_class_type': None,
                'is_primary': False,
            })

        for s in canvas_sections:
            section_id = s['id']
            try:
                mailing_list = mailing_lists_by_section_id.pop(section_id)
            except KeyError:
                mailing_list = None

            if not mailing_list:
                create_kwargs = {
                    'canvas_course_id': canvas_course_id,
                    'section_id': section_id
                }
                create_kwargs.update(overrides)
                mailing_list = MailingList(**create_kwargs)
                mailing_list.save()

            # cs_class_type is used to determine if the section
            # is an enrollment section or a non-enrollment section.
            # if it's null for a section with a real sis section id, we
            # should consider it an enrollment section.
            cs_class_type = None
            if s['sis_section_id'] and s['sis_section_id'].isdigit():
                logger.debug('Looking up section id %s' % s['sis_section_id'])
                cs_class_type = get_section_sis_enrollment_status(s['sis_section_id'])

            result.append({
                'id': mailing_list.id,
                'canvas_course_id': mailing_list.canvas_course_id,
                'sis_section_id': s['sis_section_id'] or None,
                'section_id': mailing_list.section_id,
                'name': s['name'],
                'address': mailing_list.address,
                'access_level': mailing_list.access_level,
                'members_count': len(mailing_list.members),
                'is_course_list': False,
                'cs_class_type': cs_class_type,
                'is_primary': s['sis_section_id'] == sis_course_id,
            })

        # Delete existing mailing lists who's section no longer exists
        for section_id, mailing_list in mailing_lists_by_section_id.iteritems():
            mailing_list.delete()

        return result
Exemple #7
0
    def get_or_create_or_delete_mailing_lists_for_canvas_course_id(self, canvas_course_id, **kwargs):
        """
        Gets the mailing list data for all sections related to the given canvas_course_id.
        Creates MailingList models and corresponding listserv mailing lists if a given section's
        mailing list does not yet exist. This will also sync the mailing list membership with the
        course enrollments when creating new mailing lists.

        :param canvas_course_id:
        :param kwargs:
        :return: List of mailing list dictionaries for the given canvas_course_id
        """
        canvas_sections = canvas_api_client.get_sections(canvas_course_id)
        mailing_lists_by_section_id = self._get_mailing_lists_by_section_id(canvas_course_id)

        # get a list of the primary sections
        primary_sections = [s['id'] for s in canvas_sections if s['sis_section_id'] is not None]

        overrides = kwargs.get('defaults', {})
        result = []

        # if there is more than one primary section
        # create a primary mailing list.
        course_list = None
        if len(primary_sections) > 1:
            try:
                course_list = mailing_lists_by_section_id.pop(None)
            except KeyError:
                course_list = None

            if not course_list:
                create_kwargs = {
                    'canvas_course_id': canvas_course_id,
                    'section_id': None
                }
                create_kwargs.update(overrides)
                course_list = MailingList(**create_kwargs)
                course_list.save()

        # if there is a course_list, append it to the result list so
        # it can be used by the template.
        if course_list:
            result.append({
                'id': course_list.id,
                'canvas_course_id': course_list.canvas_course_id,
                'section_id': course_list.section_id,
                'name': canvas_api_client.get_course(canvas_course_id)['course_code'],
                'address': course_list.address,
                'access_level': course_list.access_level,
                'members_count': len(course_list.members),
                'is_primary_section': True,
                'is_course_list': True,
            })

        for s in canvas_sections:
            section_id = s['id']
            try:
                mailing_list = mailing_lists_by_section_id.pop(section_id)
            except KeyError:
                mailing_list = None

            if not mailing_list:
                create_kwargs = {
                    'canvas_course_id': canvas_course_id,
                    'section_id': section_id
                }
                create_kwargs.update(overrides)
                mailing_list = MailingList(**create_kwargs)
                mailing_list.save()

            result.append({
                'id': mailing_list.id,
                'canvas_course_id': mailing_list.canvas_course_id,
                'section_id': mailing_list.section_id,
                'name': s['name'],
                'address': mailing_list.address,
                'access_level': mailing_list.access_level,
                'members_count': len(mailing_list.members),
                'is_primary_section': s['sis_section_id'] is not None
            })

        # Delete existing mailing lists who's section no longer exists
        for section_id, mailing_list in mailing_lists_by_section_id.iteritems():
            mailing_list.delete()

        return result