Exemplo n.º 1
0
 def get_extra_context(self):
     parent = self.get_assignment(self.project)
     key = 'assignment_instructions_{}'.format(parent.id)
     return {
         'show_instructions': UserSetting.get_setting(
             self.request.user, key, True),
         'allow_public_compositions': allow_public_compositions(
             self.request.course)
     }
Exemplo n.º 2
0
 def get_extra_context(self):
     parent = self.get_assignment(self.project)
     key = 'assignment_instructions_{}'.format(parent.id)
     return {
         'show_instructions': UserSetting.get_setting(
             self.request.user, key, True),
         'allow_public_compositions': allow_public_compositions(
             self.request.course)
     }
Exemplo n.º 3
0
    def get(self, request, *args, **kwargs):
        project = get_object_or_404(Project, pk=kwargs.get('project_id', None))

        data = {
            'project': project,
            'can_edit': request.user == project.author,
            'allow_public_compositions': allow_public_compositions(
                self.request.course)
        }

        return self.render_to_response(data)
Exemplo n.º 4
0
    def get(self, request, *args, **kwargs):
        project = get_object_or_404(Project, pk=kwargs.get('project_id', None))

        data = {
            'project': project,
            'can_edit': request.user == project.author,
            'allow_public_compositions': allow_public_compositions(
                self.request.course)
        }

        return self.render_to_response(data)
Exemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     r = super(DashboardSettingsForm, self).__init__(*args, **kwargs)
     self.fields['publish_to_world'].initial = \
         allow_public_compositions(self.instance)
     self.fields['see_eachothers_items'].initial = \
         all_items_are_visible(self.instance)
     self.fields['see_eachothers_selections'].initial = \
         all_selections_are_visible(self.instance)
     self.fields['allow_item_download'].initial = \
         allow_item_download(self.instance)
     self.fields['allow_roster_changes'].initial = \
         allow_roster_changes(self.instance)
     return r
Exemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     r = super(DashboardSettingsForm, self).__init__(*args, **kwargs)
     self.fields['publish_to_world'].initial = \
         allow_public_compositions(self.instance)
     self.fields['homepage_title'].initial = \
         course_information_title(self.instance)
     self.fields['see_eachothers_items'].initial = \
         all_items_are_visible(self.instance)
     self.fields['see_eachothers_selections'].initial = \
         all_selections_are_visible(self.instance)
     self.fields['allow_item_download'].initial = \
         allow_item_download(self.instance)
     self.fields['allow_roster_changes'].initial = \
         allow_roster_changes(self.instance)
     return r
Exemplo n.º 7
0
    def test_post_disabled_selection_visibility(self):
        self.client.login(username=self.instructor_one.username,
                          password='******')
        data = {course_details.ITEM_VISIBILITY_KEY: 0}

        response = self.client.post('/dashboard/settings/', data)
        self.assertEquals(response.status_code, 302)

        # unchanged from defaults
        self.assertEquals(course_information_title(self.sample_course),
                          'From Your Instructor')
        self.assertFalse(allow_public_compositions(self.sample_course))

        # updated
        self.assertFalse(all_items_are_visible(self.sample_course))
        self.assertFalse(all_selections_are_visible(self.sample_course))
Exemplo n.º 8
0
    def get_choices(self, request, project):
        choices = []
        if request.course.is_faculty(request.user):
            if not project or project.get_collaboration().children.count() < 1:
                choices.append(PUBLISH_DRAFT)
            choices.append(PUBLISH_WHOLE_CLASS)
        else:
            # Student
            choices.append(PUBLISH_DRAFT)
            choices.append(PUBLISH_INSTRUCTOR_SHARED)
            choices.append(PUBLISH_WHOLE_CLASS)

        if course_details.allow_public_compositions(request.course) and \
           project and (project.is_composition() or project.is_sequence()):
            choices.append(PUBLISH_WHOLE_WORLD)

        return choices
Exemplo n.º 9
0
    def test_post(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))
        data = {
            course_details.COURSE_INFORMATION_TITLE_KEY: "Foo",
            course_details.SELECTION_VISIBILITY_KEY: 0,
            course_details.ITEM_VISIBILITY_KEY: 0,
            course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY: 1
        }

        response = self.client.post('/dashboard/settings/', data)
        self.assertEquals(response.status_code, 302)
        self.assertEquals(course_information_title(self.sample_course), "Foo")
        self.assertTrue(allow_public_compositions(self.sample_course))
        self.assertFalse(all_items_are_visible(self.sample_course))
        self.assertFalse(all_selections_are_visible(self.sample_course))
Exemplo n.º 10
0
    def get_choices(self, request, project):
        choices = []
        if request.course.is_faculty(request.user):
            if not project or project.get_collaboration().children.count() < 1:
                choices.append(PUBLISH_DRAFT)
            choices.append(PUBLISH_WHOLE_CLASS)
        else:
            # Student
            choices.append(PUBLISH_DRAFT)
            choices.append(PUBLISH_INSTRUCTOR_SHARED)
            choices.append(PUBLISH_WHOLE_CLASS)

        if course_details.allow_public_compositions(request.course) and \
           project and (project.is_composition() or project.is_sequence()):
            choices.append(PUBLISH_WHOLE_WORLD)

        return choices
Exemplo n.º 11
0
    def __init__(self, request, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)

        lst = [(u.id, get_public_name(u, request))
               for u in request.course.user_set.all()]
        self.fields['participants'].choices = sorted(
            lst, key=lambda participant: participant[1])
        self.fields['participants'].widget.attrs = {
            'id': "id_participants_%s" % self.instance.id
        }

        col = kwargs['instance'].collaboration()
        if col:
            pol = col._policy.policy_name
            if pol not in dict(self.fields['publish'].choices):
                self.fields['publish'].choices.append((pol, pol))
            self.initial['publish'] = pol

        if request.course.is_faculty(request.user):
            # Faculty
            self.fields['publish'].choices = \
                [choice for choice in self.fields['publish'].choices
                 if choice[0] in PUBLISH_OPTIONS_FACULTY]
        else:
            # Student
            if kwargs['instance'].assignment():
                # Assignment response
                self.fields['publish'].choices = \
                    [choice for choice in self.fields['publish'].choices
                     if choice[0] in PUBLISH_OPTIONS_STUDENT_ASSIGNMENT]
            else:
                self.fields['publish'].choices = \
                    [choice for choice in self.fields['publish'].choices
                     if choice[0] in PUBLISH_OPTIONS_STUDENT_COMPOSITION]

        if course_details.allow_public_compositions(request.course):
            self.fields['publish'].choices.append(PUBLISH_OPTIONS_PUBLIC)

        self.fields['participants'].required = False
        self.fields['body'].required = False
        self.fields['submit'].required = False
        self.fields['publish'].required = False

        # for structured collaboration
        self.fields['title'].widget.attrs['maxlength'] = 80
Exemplo n.º 12
0
    def __init__(self, request, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)

        lst = [(u.id, get_public_name(u, request))
               for u in request.course.user_set.all()]
        self.fields['participants'].choices = sorted(
            lst, key=lambda participant: participant[1])
        self.fields['participants'].widget.attrs = {
            'id': "id_participants_%s" % self.instance.id
        }

        col = kwargs['instance'].collaboration()
        if col:
            pol = col._policy.policy_name
            if pol not in dict(self.fields['publish'].choices):
                self.fields['publish'].choices.append((pol, pol))
            self.initial['publish'] = pol

        if request.course.is_faculty(request.user):
            # Faculty
            self.fields['publish'].choices = \
                [choice for choice in self.fields['publish'].choices
                 if choice[0] in PUBLISH_OPTIONS_FACULTY]
        else:
            # Student
            if kwargs['instance'].assignment():
                # Assignment response
                self.fields['publish'].choices = \
                    [choice for choice in self.fields['publish'].choices
                     if choice[0] in PUBLISH_OPTIONS_STUDENT_ASSIGNMENT]
            else:
                self.fields['publish'].choices = \
                    [choice for choice in self.fields['publish'].choices
                     if choice[0] in PUBLISH_OPTIONS_STUDENT_COMPOSITION]

        if course_details.allow_public_compositions(request.course):
            self.fields['publish'].choices.append(PUBLISH_OPTIONS_PUBLIC)

        self.fields['participants'].required = False
        self.fields['body'].required = False
        self.fields['submit'].required = False
        self.fields['publish'].required = False

        # for structured collaboration
        self.fields['title'].widget.attrs['maxlength'] = 80
Exemplo n.º 13
0
    def __init__(self, *args, **kwargs):
        r = super(DashboardSettingsForm, self).__init__(*args, **kwargs)
        self.fields['publish_to_world'].initial = \
            allow_public_compositions(self.instance)
        self.fields['homepage_title'].initial = \
            course_information_title(self.instance)
        self.fields['see_eachothers_items'].initial = \
            all_items_are_visible(self.instance)
        self.fields['see_eachothers_selections'].initial = \
            all_selections_are_visible(self.instance)
        self.fields['allow_item_download'].initial = \
            allow_item_download(self.instance)
        lti_context = LTICourseContext.objects.filter(
            group=self.instance.group.id,
            faculty_group=self.instance.faculty_group.id).first()
        self.fields['lti_integration'].initial = \
            (lti_context and lti_context.enable)

        return r
Exemplo n.º 14
0
def mediathread_activity_by_course(request):
    """STAFF ONLY reporting of entire application activity """
    if not request.user.is_staff:
        return HttpResponseForbidden("forbidden")

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = \
        'attachment; filename=mediathread_activity_by_course.csv'
    writer = csv.writer(response)
    headers = ['Id', 'Title', 'Instructor', 'Course String',
               'Term', 'Year', 'Section', 'Course Number', 'School',
               'Students', 'Items', 'Selections',
               'Compositions', 'Assignments', 'Discussions',
               'Public To World Compositions',
               'All Selections Visible']
    writer.writerow(headers)

    rows = []
    for c in Course.objects.all().order_by('-id'):
        if (c.faculty_group is None or
            (not (c.faculty_group.name.startswith('t1') or
                  c.faculty_group.name.startswith('t2') or
                  c.faculty_group.name.startswith('t3')))):
            continue

        row = []
        row.append(c.id)
        row.append(c.title)

        if 'instructor' in c.details():
            row.append(c.details()['instructor'].value)
        else:
            row.append('')

        course_string = c.faculty_group.name
        row.append(course_string)

        bits = c.faculty_group.name.split('.')
        row.append(bits[0])  # term
        row.append(bits[1][1:])  # year
        row.append(bits[2])  # section
        row.append(bits[3])  # courseNo
        row.append(bits[4])  # school
        row.append(len(c.students))

        items = Asset.objects.filter(course=c)
        row.append(len(items))

        selections = SherdNote.objects.filter(asset__course=c)
        row.append(len(selections))

        compositions = 0
        assignments = 0

        projects = Project.objects.filter(course=c)
        for p in projects:
            if p.visibility_short() == 'Assignment':
                assignments += 1
            else:
                compositions += 1

        row.append(compositions)
        row.append(assignments)
        try:
            row.append(len(get_course_discussions(c)))
        except Collaboration.DoesNotExist:
            row.append(0)

        row.append(course_details.allow_public_compositions(c))
        row.append(course_details.all_selections_are_visible(c))

        rows.append(row)

    for row in rows:
        try:
            writer.writerow(row)
        except:
            pass

    return response
Exemplo n.º 15
0
    def get(self, request, *args, **kwargs):
        headers = [
            'Id', 'Created', 'Title', 'Instructor', 'Course String', 'Term',
            'Year', 'Section', 'Course Number', 'School', 'Students',
            '% Active Students', 'Total Items', 'Student Items',
            'Student Selections', 'Compositions', 'Assignments', 'Responses',
            'Discussions', 'Public To World Compositions',
            'All Selections Visible', '# of Active Tags', '% Using Tags',
            '% Items Tagged', '% Selections Tagged',
            '# of Active Vocabulary Terms', '% Using Vocabulary',
            '% Items Classified', '% Selections Classified'
        ]

        rows = []
        # Hard-coding date until we have time to code a proper ui
        qs = Course.objects.filter(created_at__year__gte='2019',
                                   created_at__month__gte='6')
        for the_course in qs.order_by('-id'):
            row = []
            row.append(the_course.id)
            row.append(the_course.created_at.strftime(self.date_fmt))
            row.append(the_course.title)

            if 'instructor' in the_course.details():
                row.append(the_course.details()['instructor'].value)
            else:
                row.append('')

            course_string = the_course.faculty_group.name
            row.append(course_string)

            bits = the_course.faculty_group.name.split('.')
            if len(bits) >= 5:
                row.append(bits[0])  # term
                row.append(bits[1][1:])  # year
                row.append(bits[2])  # section
                row.append(bits[3])  # courseNo
                row.append(bits[4])  # school
            else:
                row.append('')
                row.append('')
                row.append('')
                row.append('')
                row.append('')

            students = self.all_students(the_course)
            row.append(len(students))
            row.append(self.active_students(students))

            items = Asset.objects.filter(course=the_course)
            row.append(len(items))

            # student work only
            student_ids = students.values('id')
            items = Asset.objects.filter(course=the_course,
                                         author__id__in=student_ids)
            row.append(len(items))

            selections = SherdNote.objects.filter(asset__course=the_course,
                                                  author__id__in=student_ids)
            row.append(len(selections))

            compositions, assignments, responses = \
                self.project_count(the_course)
            row.append(compositions)
            row.append(assignments)
            row.append(responses)
            row.append(self.discussion_count(the_course))
            row.append(course_details.allow_public_compositions(the_course))
            row.append(course_details.all_selections_are_visible(the_course))

            # Breakdown tags & vocabulary terms by item & selection
            if len(selections) > 0:
                item_notes = selections.filter(range1=None, range2=None)
                sel_notes = selections.exclude(range1=None, range2=None)

                tags = Tag.objects.usage_for_queryset(selections)
                row.append(len(tags))  # # of Active Tags',

                tagged = selections.filter(tags__isnull=False).values('author')
                tag_users = tagged.distinct().count()
                if len(students) > 0:
                    # % users using tags
                    row.append(float(tag_users) / len(students) * 100)
                else:
                    row.append(0)

                # '% Items Tagged', '% Selections Tagged'
                t = item_notes.filter(tags__isnull=False).exclude(
                    tags__exact='')
                row.append(float(len(t)) / len(selections) * 100)
                t = sel_notes.filter(tags__isnull=False).exclude(
                    tags__exact='')
                row.append(float(len(t)) / len(selections) * 100)

                # Vocabulary
                related = TermRelationship.objects.filter(
                    term__vocabulary__course=the_course,
                    sherdnote__id__in=selections.values_list('id', flat=True))

                # '# of Active Vocabulary Terms'
                q = related.aggregate(Count('term', distinct=True))
                active_terms = q['term__count']
                q = related.aggregate(Count('sherdnote__author',
                                            distinct=True))
                vocab_users = q['sherdnote__author__count']

                row.append(active_terms)
                if len(students) > 0:
                    # % users
                    row.append(float(vocab_users) / len(students) * 100)
                else:
                    row.append(0)

                related_ids = related.values_list('sherdnote__id', flat=True)
                items = len(
                    SherdNote.objects.filter(id__in=related_ids,
                                             range1=None,
                                             range2=None))
                row.append(float(items) / len(selections) * 100)  # % Items
                sel = len(
                    SherdNote.objects.filter(id__in=related_ids).exclude(
                        range1=None, range2=None))
                row.append(float(sel) / len(selections) * 100)  # % Selections

            rows.append(row)

        return self.render_csv_response('mediathread_activity_by_course',
                                        headers, rows)
Exemplo n.º 16
0
def mediathread_activity_by_course(request):
    """STAFF ONLY reporting of entire application activity """
    if not request.user.is_staff:
        return HttpResponseForbidden("forbidden")

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = \
        'attachment; filename=mediathread_activity_by_course.csv'
    writer = csv.writer(response)
    headers = [
        'Id', 'Title', 'Instructor', 'Course String', 'Term', 'Year',
        'Section', 'Course Number', 'School', 'Students', '% Active Students',
        'Items', 'Selections', 'Compositions', 'Assignments', 'Discussions',
        'Public To World Compositions', 'All Selections Visible',
        '# of Active Tags', '% Using Tags', '% Items Tagged',
        '% Selections Tagged', '# of Active Vocabulary Terms',
        '% Using Vocabulary', '% Items Classified', '% Selections Classified'
    ]
    writer.writerow(headers)

    rows = []
    for the_course in Course.objects.all().order_by('-id'):
        if (the_course.faculty_group is None
                or (not (the_course.faculty_group.name.startswith('t1')
                         or the_course.faculty_group.name.startswith('t2')
                         or the_course.faculty_group.name.startswith('t3')))):
            continue

        row = []
        row.append(the_course.id)
        row.append(the_course.title)

        if 'instructor' in the_course.details():
            row.append(the_course.details()['instructor'].value)
        else:
            row.append('')

        course_string = the_course.faculty_group.name
        row.append(course_string)

        bits = the_course.faculty_group.name.split('.')
        row.append(bits[0])  # term
        row.append(bits[1][1:])  # year
        row.append(bits[2])  # section
        row.append(bits[3])  # courseNo
        row.append(bits[4])  # school

        students = the_course.group.user_set.all()
        if the_course.faculty_group:
            ids = the_course.faculty_group.user_set.values('id')
            students = students.exclude(id__in=ids)
        row.append(len(students))

        if len(students) > 0:
            active = students.filter(
                Q(projects__isnull=False)
                | Q(sherdnote__isnull=False)).distinct()
            row.append(float(len(active)) / len(students) * 100)
        else:
            row.append(0)

        items = Asset.objects.filter(course=the_course)
        row.append(len(items))

        selections = SherdNote.objects.filter(asset__course=the_course)
        row.append(len(selections))

        compositions = 0
        assignments = 0

        projects = Project.objects.filter(course=the_course)
        for project in projects:
            if project.visibility_short() == 'Assignment':
                assignments += 1
            else:
                compositions += 1

        row.append(compositions)
        row.append(assignments)
        try:
            discussions = get_course_discussions(the_course)
            row.append(len(discussions))
            '# of Discussion Items', '% participating in Discussions',
        except Collaboration.DoesNotExist:
            row.append(0)

        row.append(course_details.allow_public_compositions(the_course))
        row.append(course_details.all_selections_are_visible(the_course))

        # Breakdown tags & vocabulary terms by item & selection
        if len(selections) > 0:
            item_notes = selections.filter(range1=None, range2=None)
            sel_notes = selections.exclude(range1=None, range2=None)

            tags = Tag.objects.usage_for_queryset(selections)
            row.append(len(tags))  # # of Active Tags',
            tag_users = len(
                selections.filter(tags__isnull=False).distinct('author'))
            if len(students) > 0:
                # % users using tags
                row.append(float(tag_users) / len(students) * 100)
            else:
                row.append(0)

            # '% Items Tagged', '% Selections Tagged'
            t = item_notes.filter(tags__isnull=False).exclude(tags__exact='')
            row.append(float(len(t)) / len(selections) * 100)
            t = sel_notes.filter(tags__isnull=False).exclude(tags__exact='')
            row.append(float(len(t)) / len(selections) * 100)

            # Vocabulary
            vocab = Vocabulary.objects.get_for_object(the_course)
            content_type = ContentType.objects.get_for_model(SherdNote)
            related = TermRelationship.objects.filter(
                term__vocabulary__in=vocab,
                content_type=content_type,
                object_id__in=selections.values_list('id'))

            # '# of Active Vocabulary Terms'
            q = related.aggregate(Count('term', distinct=True))
            active_terms = q['term__count']
            vocab_users = len(
                SherdNote.objects.filter(id__in=related.values_list(
                    'object_id')).distinct('author'))

            row.append(active_terms)
            if len(students) > 0:
                row.append(float(vocab_users) / len(students) * 100)  # % users
            else:
                row.append(0)

            related_ids = related.values_list('object_id')
            items = len(
                SherdNote.objects.filter(id__in=related_ids,
                                         range1=None,
                                         range2=None))
            row.append(float(items) / len(selections) * 100)  # % Items
            sel = len(
                SherdNote.objects.filter(id__in=related_ids).exclude(
                    range1=None, range2=None))
            row.append(float(sel) / len(selections) * 100)  # % Selections

        rows.append(row)

    for row in rows:
        try:
            writer.writerow(row)
        except:
            pass

    return response
Exemplo n.º 17
0
    def get(self, request, *args, **kwargs):
        headers = ['Id', 'Title', 'Instructor', 'Course String',
                   'Term', 'Year', 'Section', 'Course Number', 'School',
                   'Students', '% Active Students',
                   'Items', 'Selections',
                   'Compositions', 'Assignments', 'Discussions',
                   'Public To World Compositions', 'All Selections Visible',
                   '# of Active Tags', '% Using Tags',
                   '% Items Tagged', '% Selections Tagged',
                   '# of Active Vocabulary Terms', '% Using Vocabulary',
                   '% Items Classified', '% Selections Classified']

        rows = []
        for the_course in Course.objects.all().order_by('-id'):
            if not self.include_course(the_course):
                continue

            row = []
            row.append(the_course.id)
            row.append(the_course.title)

            if 'instructor' in the_course.details():
                row.append(the_course.details()['instructor'].value)
            else:
                row.append('')

            course_string = the_course.faculty_group.name
            row.append(course_string)

            bits = the_course.faculty_group.name.split('.')
            row.append(bits[0])  # term
            row.append(bits[1][1:])  # year
            row.append(bits[2])  # section
            row.append(bits[3])  # courseNo
            row.append(bits[4])  # school

            students = self.all_students(the_course)
            row.append(len(students))
            row.append(self.active_students(students))

            items = Asset.objects.filter(course=the_course)
            row.append(len(items))

            selections = SherdNote.objects.filter(asset__course=the_course)
            row.append(len(selections))

            compositions, assignments = self.project_count(the_course)
            row.append(compositions)
            row.append(assignments)
            row.append(self.discussion_count(the_course))
            row.append(course_details.allow_public_compositions(the_course))
            row.append(course_details.all_selections_are_visible(the_course))

            # Breakdown tags & vocabulary terms by item & selection
            if len(selections) > 0:
                item_notes = selections.filter(range1=None, range2=None)
                sel_notes = selections.exclude(range1=None, range2=None)

                tags = Tag.objects.usage_for_queryset(selections)
                row.append(len(tags))  # # of Active Tags',

                tagged = selections.filter(tags__isnull=False).values('author')
                tag_users = tagged.distinct().count()
                if len(students) > 0:
                    # % users using tags
                    row.append(float(tag_users) / len(students) * 100)
                else:
                    row.append(0)

                # '% Items Tagged', '% Selections Tagged'
                t = item_notes.filter(tags__isnull=False).exclude(
                    tags__exact='')
                row.append(float(len(t)) / len(selections) * 100)
                t = sel_notes.filter(tags__isnull=False).exclude(
                    tags__exact='')
                row.append(float(len(t)) / len(selections) * 100)

                # Vocabulary
                vocab = Vocabulary.objects.get_for_object(the_course)
                content_type = ContentType.objects.get_for_model(SherdNote)
                related = TermRelationship.objects.filter(
                    term__vocabulary__in=vocab,
                    content_type=content_type,
                    object_id__in=selections.values_list('id'))

                # '# of Active Vocabulary Terms'
                q = related.aggregate(Count('term', distinct=True))
                active_terms = q['term__count']
                termed = SherdNote.objects.filter(
                    id__in=related.values_list('object_id')).values('author')
                vocab_users = termed.distinct().count()

                row.append(active_terms)
                if len(students) > 0:
                    # % users
                    row.append(float(vocab_users) / len(students) * 100)
                else:
                    row.append(0)

                related_ids = related.values_list('object_id')
                items = len(SherdNote.objects.filter(id__in=related_ids,
                                                     range1=None, range2=None))
                row.append(float(items) / len(selections) * 100)  # % Items
                sel = len(SherdNote.objects.filter(id__in=related_ids).exclude(
                    range1=None, range2=None))
                row.append(float(sel) / len(selections) * 100)  # % Selections

            rows.append(row)

        return self.render_csv_response(
            'mediathread_activity_by_course', headers, rows)
Exemplo n.º 18
0
def mediathread_activity_by_course(request):
    """STAFF ONLY reporting of entire application activity """
    if not request.user.is_staff:
        return HttpResponseForbidden("forbidden")

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = \
        'attachment; filename=mediathread_activity_by_course.csv'
    writer = csv.writer(response)
    headers = ['Id', 'Title', 'Instructor', 'Course String',
               'Term', 'Year', 'Section', 'Course Number', 'School',
               'Students', '% Active Students',
               'Items', 'Selections',
               'Compositions', 'Assignments', 'Discussions',
               'Public To World Compositions', 'All Selections Visible',
               '# of Active Tags', '% Using Tags',
               '% Items Tagged', '% Selections Tagged',
               '# of Active Vocabulary Terms', '% Using Vocabulary',
               '% Items Classified', '% Selections Classified']
    writer.writerow(headers)

    rows = []
    for the_course in Course.objects.all().order_by('-id'):
        if (the_course.faculty_group is None or
            (not (the_course.faculty_group.name.startswith('t1') or
                  the_course.faculty_group.name.startswith('t2') or
                  the_course.faculty_group.name.startswith('t3')))):
            continue

        row = []
        row.append(the_course.id)
        row.append(the_course.title)

        if 'instructor' in the_course.details():
            row.append(the_course.details()['instructor'].value)
        else:
            row.append('')

        course_string = the_course.faculty_group.name
        row.append(course_string)

        bits = the_course.faculty_group.name.split('.')
        row.append(bits[0])  # term
        row.append(bits[1][1:])  # year
        row.append(bits[2])  # section
        row.append(bits[3])  # courseNo
        row.append(bits[4])  # school

        students = the_course.group.user_set.all()
        if the_course.faculty_group:
            ids = the_course.faculty_group.user_set.values('id')
            students = students.exclude(id__in=ids)
        row.append(len(students))

        if len(students) > 0:
            active = students.filter(Q(projects__isnull=False) |
                                     Q(sherdnote__isnull=False)).distinct()
            row.append(float(len(active)) / len(students) * 100)
        else:
            row.append(0)

        items = Asset.objects.filter(course=the_course)
        row.append(len(items))

        selections = SherdNote.objects.filter(asset__course=the_course)
        row.append(len(selections))

        compositions = 0
        assignments = 0

        projects = Project.objects.filter(course=the_course)
        for project in projects:
            if project.visibility_short() == 'Assignment':
                assignments += 1
            else:
                compositions += 1

        row.append(compositions)
        row.append(assignments)
        try:
            discussions = get_course_discussions(the_course)
            row.append(len(discussions))
            '# of Discussion Items', '% participating in Discussions',
        except Collaboration.DoesNotExist:
            row.append(0)

        row.append(course_details.allow_public_compositions(the_course))
        row.append(course_details.all_selections_are_visible(the_course))

        # Breakdown tags & vocabulary terms by item & selection
        if len(selections) > 0:
            item_notes = selections.filter(range1=None, range2=None)
            sel_notes = selections.exclude(range1=None, range2=None)

            tags = Tag.objects.usage_for_queryset(selections)
            row.append(len(tags))  # # of Active Tags',
            tag_users = len(
                selections.filter(tags__isnull=False).distinct('author'))
            if len(students) > 0:
                # % users using tags
                row.append(float(tag_users) / len(students) * 100)
            else:
                row.append(0)

            # '% Items Tagged', '% Selections Tagged'
            t = item_notes.filter(tags__isnull=False).exclude(tags__exact='')
            row.append(float(len(t)) / len(selections) * 100)
            t = sel_notes.filter(tags__isnull=False).exclude(tags__exact='')
            row.append(float(len(t)) / len(selections) * 100)

            # Vocabulary
            vocab = Vocabulary.objects.get_for_object(the_course)
            content_type = ContentType.objects.get_for_model(SherdNote)
            related = TermRelationship.objects.filter(
                term__vocabulary__in=vocab,
                content_type=content_type,
                object_id__in=selections.values_list('id'))

            # '# of Active Vocabulary Terms'
            q = related.aggregate(Count('term', distinct=True))
            active_terms = q['term__count']
            vocab_users = len(SherdNote.objects.filter(
                id__in=related.values_list('object_id')).distinct(
                'author'))

            row.append(active_terms)
            if len(students) > 0:
                row.append(float(vocab_users) / len(students) * 100)  # % users
            else:
                row.append(0)

            related_ids = related.values_list('object_id')
            items = len(SherdNote.objects.filter(id__in=related_ids,
                                                 range1=None, range2=None))
            row.append(float(items) / len(selections) * 100)  # % Items
            sel = len(SherdNote.objects.filter(id__in=related_ids).exclude(
                range1=None, range2=None))
            row.append(float(sel) / len(selections) * 100)  # % Selections

        rows.append(row)

    for row in rows:
        try:
            writer.writerow(row)
        except:
            pass

    return response
Exemplo n.º 19
0
    def get(self, request, *args, **kwargs):
        headers = ['Id', 'Created', 'Title', 'Instructor', 'Course String',
                   'Term', 'Year', 'Section', 'Course Number', 'School',
                   'Students', '% Active Students',
                   'Total Items', 'Student Items', 'Student Selections',
                   'Compositions', 'Assignments', 'Responses', 'Discussions',
                   'Public To World Compositions', 'All Selections Visible',
                   '# of Active Tags', '% Using Tags',
                   '% Items Tagged', '% Selections Tagged',
                   '# of Active Vocabulary Terms', '% Using Vocabulary',
                   '% Items Classified', '% Selections Classified']

        rows = []
        # Hard-coding date until we have time to code a proper ui
        qs = Course.objects.filter(created_at__year__gte='2018')
        for the_course in qs.order_by('-id'):
            row = []
            row.append(the_course.id)
            row.append(the_course.created_at.strftime(self.date_fmt))
            row.append(the_course.title)

            if 'instructor' in the_course.details():
                row.append(the_course.details()['instructor'].value)
            else:
                row.append('')

            course_string = the_course.faculty_group.name
            row.append(course_string)

            bits = the_course.faculty_group.name.split('.')
            if len(bits) >= 5:
                row.append(bits[0])  # term
                row.append(bits[1][1:])  # year
                row.append(bits[2])  # section
                row.append(bits[3])  # courseNo
                row.append(bits[4])  # school
            else:
                row.append('')
                row.append('')
                row.append('')
                row.append('')
                row.append('')

            students = self.all_students(the_course)
            row.append(len(students))
            row.append(self.active_students(students))

            items = Asset.objects.filter(course=the_course)
            row.append(len(items))

            # student work only
            student_ids = students.values('id')
            items = Asset.objects.filter(
                course=the_course, author__id__in=student_ids)
            row.append(len(items))

            selections = SherdNote.objects.filter(
                asset__course=the_course, author__id__in=student_ids)
            row.append(len(selections))

            compositions, assignments, responses = \
                self.project_count(the_course)
            row.append(compositions)
            row.append(assignments)
            row.append(responses)
            row.append(self.discussion_count(the_course))
            row.append(course_details.allow_public_compositions(the_course))
            row.append(course_details.all_selections_are_visible(the_course))

            # Breakdown tags & vocabulary terms by item & selection
            if len(selections) > 0:
                item_notes = selections.filter(range1=None, range2=None)
                sel_notes = selections.exclude(range1=None, range2=None)

                tags = Tag.objects.usage_for_queryset(selections)
                row.append(len(tags))  # # of Active Tags',

                tagged = selections.filter(tags__isnull=False).values('author')
                tag_users = tagged.distinct().count()
                if len(students) > 0:
                    # % users using tags
                    row.append(float(tag_users) / len(students) * 100)
                else:
                    row.append(0)

                # '% Items Tagged', '% Selections Tagged'
                t = item_notes.filter(tags__isnull=False).exclude(
                    tags__exact='')
                row.append(float(len(t)) / len(selections) * 100)
                t = sel_notes.filter(tags__isnull=False).exclude(
                    tags__exact='')
                row.append(float(len(t)) / len(selections) * 100)

                # Vocabulary
                related = TermRelationship.objects.filter(
                    term__vocabulary__course=the_course,
                    sherdnote__id__in=selections.values_list('id', flat=True))

                # '# of Active Vocabulary Terms'
                q = related.aggregate(Count('term', distinct=True))
                active_terms = q['term__count']
                q = related.aggregate(
                    Count('sherdnote__author', distinct=True))
                vocab_users = q['sherdnote__author__count']

                row.append(active_terms)
                if len(students) > 0:
                    # % users
                    row.append(float(vocab_users) / len(students) * 100)
                else:
                    row.append(0)

                related_ids = related.values_list('sherdnote__id', flat=True)
                items = len(SherdNote.objects.filter(id__in=related_ids,
                                                     range1=None, range2=None))
                row.append(float(items) / len(selections) * 100)  # % Items
                sel = len(SherdNote.objects.filter(id__in=related_ids).exclude(
                    range1=None, range2=None))
                row.append(float(sel) / len(selections) * 100)  # % Selections

            rows.append(row)

        return self.render_csv_response(
            'mediathread_activity_by_course', headers, rows)
Exemplo n.º 20
0
 def test_allow_public_compositions(self):
     # default
     self.assertFalse(allow_public_compositions(self.sample_course))
Exemplo n.º 21
0
 def test_allow_public_compositions(self):
     # default
     self.assertFalse(allow_public_compositions(self.sample_course))
Exemplo n.º 22
0
def mediathread_activity_by_course(request):
    """STAFF ONLY reporting of entire application activity """
    if not request.user.is_staff:
        return HttpResponseForbidden("forbidden")

    response = HttpResponse(mimetype='text/csv')
    response['Content-Disposition'] = \
        'attachment; filename=mediathread_activity_by_course.csv'
    writer = csv.writer(response)
    headers = [
        'Id', 'Title', 'Instructor', 'Course String', 'Term', 'Year',
        'Section', 'Course Number', 'School', 'Students', 'Items',
        'Selections', 'Compositions', 'Assignments', 'Discussions',
        'Public To World Compositions', 'All Selections Visible'
    ]
    writer.writerow(headers)

    rows = []
    for the_course in Course.objects.all().order_by('-id'):
        if (the_course.faculty_group is None
                or (not (the_course.faculty_group.name.startswith('t1')
                         or the_course.faculty_group.name.startswith('t2')
                         or the_course.faculty_group.name.startswith('t3')))):
            continue

        row = []
        row.append(the_course.id)
        row.append(the_course.title)

        if 'instructor' in the_course.details():
            row.append(the_course.details()['instructor'].value)
        else:
            row.append('')

        course_string = the_course.faculty_group.name
        row.append(course_string)

        bits = the_course.faculty_group.name.split('.')
        row.append(bits[0])  # term
        row.append(bits[1][1:])  # year
        row.append(bits[2])  # section
        row.append(bits[3])  # courseNo
        row.append(bits[4])  # school
        row.append(len(the_course.students))

        items = Asset.objects.filter(course=the_course)
        row.append(len(items))

        selections = SherdNote.objects.filter(asset__course=the_course)
        row.append(len(selections))

        compositions = 0
        assignments = 0

        projects = Project.objects.filter(course=the_course)
        for project in projects:
            if project.visibility_short() == 'Assignment':
                assignments += 1
            else:
                compositions += 1

        row.append(compositions)
        row.append(assignments)
        try:
            row.append(len(get_course_discussions(the_course)))
        except Collaboration.DoesNotExist:
            row.append(0)

        row.append(course_details.allow_public_compositions(the_course))
        row.append(course_details.all_selections_are_visible(the_course))

        rows.append(row)

    for row in rows:
        try:
            writer.writerow(row)
        except:
            pass

    return response