Example #1
0
    def get_context(self, request, assets, notes):
        # Allow the logged in user to add assets to his composition
        citable = request.GET.get('citable', '') == 'true'

        # Include annotation metadata. (makes response much larger)
        include_annotations = request.GET.get('annotations', '') == 'true'

        # Initialize the context
        ures = UserResource()
        ctx = {
            'space_viewer': ures.render_one(request, self.record_viewer),
            'is_faculty': self.is_viewer_faculty
        }

        if self.record_owner:
            ctx['space_owner'] = ures.render_one(request, self.record_owner)

        ctx['active_filters'] = {}
        for key, val in request.GET.items():
            if (key in self.valid_filters or key.startswith('vocabulary-')):
                ctx['active_filters'][key] = val

        ctx['editable'] = self.viewing_own_records
        ctx['citable'] = citable

        # render the assets
        ares = AssetResource(include_annotations=include_annotations,
                             extras={
                                 'editable': self.viewing_own_records,
                                 'citable': citable
                             })
        ctx['assets'] = ares.render_list(request, self.record_viewer, assets,
                                         notes)

        return ctx
Example #2
0
    def get_context(self, request, assets, notes):
        # Allow the logged in user to add assets to his composition
        citable = request.GET.get('citable', '') == 'true'

        # Include annotation metadata. (makes response much larger)
        include_annotations = request.GET.get('annotations', '') == 'true'

        # Initialize the context
        ures = UserResource()
        ctx = {
            'space_viewer': ures.render_one(request, self.record_viewer),
            'is_faculty': self.is_viewer_faculty
        }

        if self.record_owner:
            ctx['space_owner'] = ures.render_one(request, self.record_owner)

        ctx['active_filters'] = {}
        for key, val in request.GET.items():
            if (key in self.valid_filters or key.startswith('vocabulary-')):
                ctx['active_filters'][key] = val

        ctx['editable'] = self.viewing_own_records
        ctx['citable'] = citable

        # render the assets
        ares = AssetResource(include_annotations=include_annotations,
                             extras={'editable': self.viewing_own_records,
                                     'citable': citable})
        ctx['assets'] = ares.render_list(request,
                                         self.record_viewer,
                                         assets, notes)

        return ctx
def all_projects(request):
    """
    An ajax-only request to retrieve a course's projects,
    assignment responses and selections
    """

    if not request.is_ajax():
        raise Http404()

    if not request.user.is_staff:
        in_course_or_404(request.user.username, request.course)

    course = request.course
    logged_in_user = request.user

    projects = Project.objects.visible_by_course(request, course)

    # Assemble the context
    user_rez = UserResource()
    course_rez = CourseSummaryResource()
    data = {'projects': homepage_project_json(request, projects, False),
            'space_viewer': user_rez.render_one(request, logged_in_user),
            'course': course_rez.render_one(request, course),
            'compositions': len(projects) > 0,
            'is_faculty': course.is_faculty(logged_in_user)}

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
def your_projects(request, record_owner_name):
    """
    An ajax-only request to retrieve a specified user's projects,
    assignment responses and selections
    """
    if not request.is_ajax():
        raise Http404()

    course = request.course
    in_course_or_404(record_owner_name, course)

    logged_in_user = request.user
    is_faculty = course.is_faculty(logged_in_user)
    record_owner = get_object_or_404(User, username=record_owner_name)
    viewing_own_work = record_owner == logged_in_user

    # Record Owner's Visible Work,
    # sorted by modified date & feedback (if applicable)
    projects = Project.objects.visible_by_course_and_user(request,
                                                          course,
                                                          record_owner)

    # Show unresponded assignments if viewing self & self is a student
    assignments = []
    if not is_faculty and viewing_own_work:
        assignments = Project.objects.unresponded_assignments(request,
                                                              logged_in_user)

    # Assemble the context
    user_rez = UserResource()
    course_rez = CourseSummaryResource()
    data = {
        'assignments': homepage_assignment_json(assignments, is_faculty),
        'projects': homepage_project_json(request, projects, viewing_own_work),
        'space_viewer': user_rez.render_one(request, logged_in_user),
        'space_owner': user_rez.render_one(request, record_owner),
        'editable': viewing_own_work,
        'course': course_rez.render_one(request, course),
        'compositions': len(projects) > 0 or len(assignments) > 0,
        'is_faculty': is_faculty}

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
Example #5
0
def your_projects(request, record_owner_name):
    """
    An ajax-only request to retrieve a specified user's projects,
    assignment responses and selections
    """
    course = request.course
    in_course_or_404(record_owner_name, course)

    logged_in_user = request.user
    is_faculty = course.is_faculty(logged_in_user)
    record_owner = get_object_or_404(User, username=record_owner_name)
    viewing_own_work = record_owner == logged_in_user

    # Record Owner's Visible Work,
    # sorted by modified date & feedback (if applicable)
    projects = Project.objects.visible_by_course_and_user(request,
                                                          course,
                                                          record_owner)

    # Show unresponded assignments if viewing self & self is a student
    assignments = []
    if not is_faculty and viewing_own_work:
        assignments = Project.objects.unresponded_assignments(request,
                                                              logged_in_user)

    # Assemble the context
    user_rez = UserResource()
    course_rez = CourseSummaryResource()
    data = {
        'assignments': homepage_assignment_json(assignments, is_faculty),
        'projects': homepage_project_json(request, projects, viewing_own_work),
        'space_viewer': user_rez.render_one(request, logged_in_user),
        'space_owner': user_rez.render_one(request, record_owner),
        'editable': viewing_own_work,
        'course': course_rez.render_one(request, course),
        'compositions': len(projects) > 0 or len(assignments) > 0,
        'is_faculty': is_faculty}

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
Example #6
0
    def get(self, request):
        ures = UserResource()
        course_res = CourseResource()
        pres = ProjectResource(editable=self.viewing_own_records,
                               record_viewer=self.record_viewer,
                               is_viewer_faculty=self.is_viewer_faculty)
        assignments = []

        ctx = {
            'space_viewer': ures.render_one(request, self.record_viewer),
            'editable': self.viewing_own_records,
            'course': course_res.render_one(request, request.course),
            'is_faculty': self.is_viewer_faculty,
            'is_superuser': request.user.is_superuser,
        }

        if self.record_owner:
            ctx['space_owner'] = ures.render_one(request, self.record_owner)

            if not request.course.is_true_member(self.record_owner):
                return self.render_to_json_response(ctx)

            projects = Project.objects.visible_by_course_and_user(
                request.course, request.user, self.record_owner,
                self.viewing_faculty_records)

            # Show unresponded assignments if viewing self & self is a student
            if not self.is_viewer_faculty and self.viewing_own_records:
                assignments = list(
                    Project.objects.unresponded_assignments(
                        request.course, request.user))
        else:
            projects = Project.objects.visible_by_course(
                request.course, request.user)

        # update counts and paginate
        ctx['compositions'] = len(projects) > 0 or len(assignments) > 0
        ctx.update(self.paginate(pres, assignments, projects))
        return self.render_to_json_response(ctx)
Example #7
0
    def get(self, request):
        ures = UserResource()
        course_rez = CourseResource()
        pres = ProjectResource(editable=self.viewing_own_records,
                               record_viewer=self.record_viewer,
                               is_viewer_faculty=self.is_viewer_faculty)
        assignments = []

        ctx = {
            'space_viewer': ures.render_one(request, self.record_viewer),
            'editable': self.viewing_own_records,
            'course': course_rez.render_one(request, request.course),
            'is_faculty': self.is_viewer_faculty
        }

        if (self.record_owner):
            in_course_or_404(self.record_owner.username, request.course)

            projects = Project.objects.visible_by_course_and_user(
                request, request.course, self.record_owner)

            # Show unresponded assignments if viewing self & self is a student
            if not self.is_viewer_faculty and self.viewing_own_records:
                assignments = Project.objects.unresponded_assignments(
                    request, self.record_viewer)

            ctx['space_owner'] = ures.render_one(request, self.record_owner)
            ctx['assignments'] = pres.render_assignments(request, assignments)
        else:
            projects = Project.objects.visible_by_course(request,
                                                         request.course)

        #offset = int(request.GET.get("offset", 0))
        #limit = int(request.GET.get("limit", 20))

        ctx['projects'] = pres.render_projects(request, projects)
        ctx['compositions'] = len(projects) > 0 or len(assignments) > 0

        return self.render_to_json_response(ctx)
Example #8
0
    def get(self, request):
        ures = UserResource()
        course_res = CourseResource()
        pres = ProjectResource(editable=self.viewing_own_records,
                               record_viewer=self.record_viewer,
                               is_viewer_faculty=self.is_viewer_faculty)
        assignments = []

        ctx = {
            'space_viewer': ures.render_one(request, self.record_viewer),
            'editable': self.viewing_own_records,
            'course': course_res.render_one(request, request.course),
            'is_faculty': self.is_viewer_faculty,
            'is_superuser': request.user.is_superuser,
        }

        if self.record_owner:
            ctx['space_owner'] = ures.render_one(request, self.record_owner)

            if not request.course.is_true_member(self.record_owner):
                return self.render_to_json_response(ctx)

            projects = Project.objects.visible_by_course_and_user(
                request.course, request.user, self.record_owner,
                self.viewing_faculty_records)

            # Show unresponded assignments if viewing self & self is a student
            if not self.is_viewer_faculty and self.viewing_own_records:
                assignments = Project.objects.unresponded_assignments(
                    request.course, request.user)
        else:
            projects = Project.objects.visible_by_course(request.course,
                                                         request.user)

        # update counts and paginate
        ctx['compositions'] = len(projects) > 0 or len(assignments) > 0
        ctx.update(self.paginate(pres, assignments, projects))
        return self.render_to_json_response(ctx)
Example #9
0
    def get(self, request):
        ures = UserResource()
        course_rez = CourseResource()
        pres = ProjectResource(editable=self.viewing_own_records,
                               record_viewer=self.record_viewer,
                               is_viewer_faculty=self.is_viewer_faculty)
        assignments = []

        ctx = {
            'space_viewer': ures.render_one(request, self.record_viewer),
            'editable': self.viewing_own_records,
            'course': course_rez.render_one(request, request.course),
            'is_faculty': self.is_viewer_faculty
        }

        if (self.record_owner):
            in_course_or_404(self.record_owner.username, request.course)

            projects = Project.objects.visible_by_course_and_user(
                request, request.course, self.record_owner,
                self.viewing_faculty_records)

            # Show unresponded assignments if viewing self & self is a student
            if not self.is_viewer_faculty and self.viewing_own_records:
                assignments = Project.objects.unresponded_assignments(
                    request, self.record_viewer)

            ctx['space_owner'] = ures.render_one(request, self.record_owner)
            ctx['assignments'] = pres.render_assignments(request, assignments)
        else:
            projects = Project.objects.visible_by_course(
                request, request.course)

        ctx['projects'] = pres.render_projects(request, projects)
        ctx['compositions'] = len(projects) > 0 or len(assignments) > 0

        return self.render_to_json_response(ctx)
Example #10
0
def all_projects(request):
    """
    An ajax-only request to retrieve a course's projects,
    assignment responses and selections
    """
    if not request.user.is_staff:
        in_course_or_404(request.user.username, request.course)

    course = request.course
    logged_in_user = request.user

    projects = Project.objects.visible_by_course(request, course)

    # Assemble the context
    user_rez = UserResource()
    course_rez = CourseSummaryResource()
    data = {'projects': homepage_project_json(request, projects, False),
            'space_viewer': user_rez.render_one(request, logged_in_user),
            'course': course_rez.render_one(request, course),
            'compositions': len(projects) > 0,
            'is_faculty': course.is_faculty(logged_in_user)}

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
Example #11
0
def render_assets(request, record_owner, assets):
    course = request.course
    logged_in_user = request.user

    # Is the current user faculty OR staff
    is_faculty = cached_course_is_faculty(course, logged_in_user)

    # Can the record_owner edit the records
    viewing_own_records = (record_owner == logged_in_user)
    viewing_faculty_records = record_owner and course.is_faculty(record_owner)

    # Allow the logged in user to add assets to his composition
    citable = request.GET.get('citable', '') == 'true'

    # Does the course allow viewing other user selections?
    owner_selections_are_visible = (
        course_details.all_selections_are_visible(course) or
        viewing_own_records or viewing_faculty_records or is_faculty)

    # Spew out json for the assets
    if request.GET.get('annotations', '') == 'true':
        resource = AssetResource(owner_selections_are_visible,
                                 record_owner,
                                 {'editable': viewing_own_records,
                                  'citable': citable})
    else:
        resource = AssetSummaryResource({'editable': viewing_own_records,
                                         'citable': citable})

    asset_json = resource.render_list(request, assets)

    active_filters = {}
    for k, val in request.GET.items():
        if (k == 'tag' or k == 'modified' or k.startswith('vocabulary-')):
            active_filters[k] = val

    user_resource = UserResource()

    # #todo -- figure out a cleaner way to do this. Ugli-ness
    # Collate tag set & vocabulary set for the result set.
    # Get all visible notes for the returned asset set
    # These notes may include global annotations for all users,
    # whereas the rendered set will not
    active_asset_ids = [a['id'] for a in asset_json]
    active_notes = []
    if record_owner:
        if owner_selections_are_visible:
            active_notes = SherdNote.objects.filter(
                asset__course=course, asset__id__in=active_asset_ids,
                author__id=record_owner.id)
    else:
        if all_selections_are_visible(course) or is_faculty:
            # Display all tags for the asset set including globals
            active_notes = SherdNote.objects.filter(
                asset__course=course, asset__id__in=active_asset_ids)
        else:
            whitelist = [f.id for f in course.faculty]
            whitelist.append(request.user.id)
            active_notes = SherdNote.objects.filter(
                asset__course=course,
                asset__id__in=active_asset_ids,
                author__id__in=whitelist)

    tags = []
    if len(active_notes) > 0:
        tags = Tag.objects.usage_for_queryset(active_notes)
        tags.sort(lambda a, b: cmp(a.name.lower(), b.name.lower()))

    active_vocabulary = []
    note_ids = [n.id for n in active_notes]
    content_type = ContentType.objects.get_for_model(SherdNote)
    term_resource = TermResource()
    for v in Vocabulary.objects.get_for_object(request.course):
        vocabulary = {
            'id': v.id,
            'display_name': v.display_name,
            'term_set': []
        }
        related = TermRelationship.objects.filter(term__vocabulary=v,
                                                  content_type=content_type,
                                                  object_id__in=note_ids)

        terms = []
        for r in related:
            if r.term.display_name not in terms:
                the_term = term_resource.render_one(request, r.term)
                vocabulary['term_set'].append(the_term)
                terms.append(r.term.display_name)

        active_vocabulary.append(vocabulary)

    # Assemble the context
    data = {'assets': asset_json,
            'active_tags': TagResource().render_list(request, tags),
            'active_filters': active_filters,
            'active_vocabulary': active_vocabulary,
            'space_viewer': user_resource.render_one(request, logged_in_user),
            'editable': viewing_own_records,
            'citable': citable,
            'is_faculty': is_faculty}

    if record_owner:
        data['space_owner'] = user_resource.render_one(request, record_owner)

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
Example #12
0
def render_assets(request, record_owner, assets):
    course = request.course
    logged_in_user = request.user

    # Is the current user faculty OR staff
    is_faculty = cached_course_is_faculty(course, logged_in_user)

    # Can the record_owner edit the records
    viewing_own_records = (record_owner == logged_in_user)
    viewing_faculty_records = record_owner and course.is_faculty(record_owner)

    # Allow the logged in user to add assets to his composition
    citable = request.GET.get('citable', '') == 'true'

    # Does the course allow viewing other user selections?
    owner_selections_are_visible = (
        course_details.all_selections_are_visible(course)
        or viewing_own_records or viewing_faculty_records or is_faculty)

    # Spew out json for the assets
    if request.GET.get('annotations', '') == 'true':
        resource = AssetResource(owner_selections_are_visible, record_owner, {
            'editable': viewing_own_records,
            'citable': citable
        })
    else:
        resource = AssetSummaryResource({
            'editable': viewing_own_records,
            'citable': citable
        })

    asset_json = resource.render_list(request, assets)

    active_filters = {}
    for key, val in request.GET.items():
        if (key == 'tag' or key == 'modified'
                or key.startswith('vocabulary-')):
            active_filters[key] = val

    user_resource = UserResource()

    # #todo -- figure out a cleaner way to do this. Ugli-ness
    # Collate tag set & vocabulary set for the result set.
    # Get all visible notes for the returned asset set
    # These notes may include global annotations for all users,
    # whereas the rendered set will not
    active_asset_ids = [a['id'] for a in asset_json]
    active_notes = []
    if record_owner:
        if owner_selections_are_visible:
            active_notes = SherdNote.objects.filter(
                asset__course=course,
                asset__id__in=active_asset_ids,
                author__id=record_owner.id)
    else:
        if all_selections_are_visible(course) or is_faculty:
            # Display all tags for the asset set including globals
            active_notes = SherdNote.objects.filter(
                asset__course=course, asset__id__in=active_asset_ids)
        else:
            whitelist = [f.id for f in course.faculty]
            whitelist.append(request.user.id)
            active_notes = SherdNote.objects.filter(
                asset__course=course,
                asset__id__in=active_asset_ids,
                author__id__in=whitelist)

    tags = []
    if len(active_notes) > 0:
        tags = Tag.objects.usage_for_queryset(active_notes)
        tags.sort(lambda a, b: cmp(a.name.lower(), b.name.lower()))

    active_vocabulary = []
    note_ids = [n.id for n in active_notes]
    content_type = ContentType.objects.get_for_model(SherdNote)
    term_resource = TermResource()
    for vocab in Vocabulary.objects.get_for_object(request.course):
        vocabulary = {
            'id': vocab.id,
            'display_name': vocab.display_name,
            'term_set': []
        }
        related = TermRelationship.objects.filter(term__vocabulary=vocab,
                                                  content_type=content_type,
                                                  object_id__in=note_ids)

        terms = []
        for rel in related:
            if rel.term.display_name not in terms:
                the_term = term_resource.render_one(request, rel.term)
                vocabulary['term_set'].append(the_term)
                terms.append(rel.term.display_name)

        active_vocabulary.append(vocabulary)

    # Assemble the context
    data = {
        'assets': asset_json,
        'active_tags': TagResource().render_list(request, tags),
        'active_filters': active_filters,
        'active_vocabulary': active_vocabulary,
        'space_viewer': user_resource.render_one(request, logged_in_user),
        'editable': viewing_own_records,
        'citable': citable,
        'is_faculty': is_faculty
    }

    if record_owner:
        data['space_owner'] = user_resource.render_one(request, record_owner)

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')
def get_records(request, record_owner, assets):
    course = request.course
    logged_in_user = request.user

    # Can the record_owner edit the records
    viewing_own_work = (record_owner == logged_in_user)
    viewing_faculty_records = record_owner and course.is_faculty(record_owner)

    # Allow the logged in user to add assets to his composition
    citable = ('citable' in request.GET and
               request.GET.get('citable') == 'true')

    # Is the current user faculty OR staff
    is_faculty = course.is_faculty(logged_in_user)

    # Does the course allow viewing other user selections?
    owner_selections_are_visible = (
        course_details.all_selections_are_visible(course) or
        viewing_own_work or viewing_faculty_records or is_faculty)

    # Filter the assets
    for fil in filter_by:
        filter_value = request.GET.get(fil)
        if filter_value:
            assets = [asset for asset in assets
                      if filter_by[fil](asset, filter_value, record_owner)]

    active_filters = get_active_filters(request, filter_by)

    # Spew out json for the assets
    asset_json = []
    options = {
        'owner_selections_are_visible': ('annotations' in request.GET and
                                         owner_selections_are_visible),
        'all_selections_are_visible':
        course_details.all_selections_are_visible(course) or is_faculty,
        'can_edit': viewing_own_work,
        'citable': citable
    }

    for asset in assets:
        asset_json.append(gallery_asset_json(request, asset, logged_in_user,
                                             record_owner, options))
    # Tags
    tags = []
    if record_owner:
        if owner_selections_are_visible:
            # Tags for selected user
            tags = Tag.objects.usage_for_queryset(
                record_owner.sherdnote_set.filter(asset__course=course),
                counts=True)
    else:
        if owner_selections_are_visible:
            # Tags for the whole class
            tags = Tag.objects.usage_for_queryset(
                SherdNote.objects.filter(asset__course=course),
                counts=True)
        else:
            # Tags for myself and faculty members
            tags = Tag.objects.usage_for_queryset(
                logged_in_user.sherdnote_set.filter(asset__course=course),
                counts=True)

            for f in course.faculty:
                tags.extend(Tag.objects.usage_for_queryset(
                            f.sherdnote_set.filter(asset__course=course),
                            counts=True))

    tags.sort(lambda a, b: cmp(a.name.lower(), b.name.lower()))

    user_resource = UserResource()
    owners = user_resource.render_list(request, request.course.members)

    # Assemble the context
    data = {'assets': asset_json,
            'tags': [{'name': tag.name} for tag in tags],
            'active_filters': active_filters,
            'space_viewer': user_resource.render_one(request, logged_in_user),
            'editable': viewing_own_work,
            'citable': citable,
            'owners': owners,
            'is_faculty': is_faculty, }

    if record_owner:
        data['space_owner'] = user_resource.render_one(request, record_owner)

    json_stream = simplejson.dumps(data, indent=2)
    return HttpResponse(json_stream, mimetype='application/json')