Exemplo n.º 1
0
def triple_homepage(request):
    if not request.course:
        return HttpResponseRedirect('/accounts/login/')

    logged_in_user = request.user
    classwork_owner = request.user  # Viewing your own work by default
    if request.GET.has_key('username'):
        user_name = request.GET['username']
        in_course_or_404(user_name, request.course)
        classwork_owner = get_object_or_404(User, username=user_name)

    context = {
        'classwork_owner':
        classwork_owner,
        'help_homepage_instructor_column':
        UserSetting.get_setting(logged_in_user,
                                "help_homepage_instructor_column", True),
        'help_homepage_classwork_column':
        UserSetting.get_setting(logged_in_user,
                                "help_homepage_classwork_column", True),
        'faculty_feed':
        get_prof_feed(request.course, request),
        'is_faculty':
        request.course.is_faculty(logged_in_user),
        'discussions':
        get_course_discussions(request.course),
        'msg':
        request.GET.get('msg', ''),
        'tag':
        request.GET.get('tag', ''),
        'view':
        request.GET.get('view', '')
    }
    return context
Exemplo n.º 2
0
def triple_homepage(request):
    if not request.course:
        return HttpResponseRedirect('/accounts/login/')
    
    logged_in_user = request.user
    classwork_owner = request.user # Viewing your own work by default
    if request.GET.has_key('username'):
        user_name = request.GET['username']
        in_course_or_404(user_name, request.course)
        classwork_owner = get_object_or_404(User, username=user_name)

    context = {
        'classwork_owner': classwork_owner,
        'help_homepage_instructor_column': UserSetting.get_setting(logged_in_user, "help_homepage_instructor_column", True),
        'help_homepage_classwork_column':  UserSetting.get_setting(logged_in_user, "help_homepage_classwork_column", True),

        'faculty_feed': get_prof_feed(request.course, request),
        'is_faculty': request.course.is_faculty(logged_in_user),
        'discussions': get_course_discussions(request.course),
        
        'msg': request.GET.get('msg', ''),
        'tag': request.GET.get('tag', ''),
        'view': request.GET.get('view', '')
    }
    return context
Exemplo n.º 3
0
def dashboard(request):
    user = request.user
    
    return { 
       "space_viewer": request.user,
       "help_dashboard_nav_actions": UserSetting.get_setting(user, "help_dashboard_nav_actions", True),
       "help_dashboard_nav_reports": UserSetting.get_setting(user, "help_dashboard_nav_reports", True)      
    }
def class_settings(request):
    c = request.course
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")

    context = {
        'asset_request': request.GET,
        'course': c,
        'space_viewer': request.user,
        'is_staff': request.user.is_staff,
        'help_public_compositions': UserSetting.get_setting(
            user, "help_public_compositions", True),
        'help_selection_visibility': UserSetting.get_setting(
            user, "help_selection_visibility", True),
    }

    public_composition_key = course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY
    context[course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY] = \
        int(c.get_detail(public_composition_key,
                         course_details.ALLOW_PUBLIC_COMPOSITIONS_DEFAULT))

    selection_visibility_key = course_details.SELECTION_VISIBILITY_KEY
    context[course_details.SELECTION_VISIBILITY_KEY] = \
        int(c.get_detail(selection_visibility_key,
                         course_details.SELECTION_VISIBILITY_DEFAULT))

    if request.method == "POST":
        if selection_visibility_key in request.POST:
            selection_visibility_value = \
                int(request.POST.get(selection_visibility_key))
            request.course.add_detail(selection_visibility_key,
                                      selection_visibility_value)
            context[selection_visibility_key] = selection_visibility_value

        if public_composition_key in request.POST:
            public_composition_value = \
                int(request.POST.get(public_composition_key))
            request.course.add_detail(public_composition_key,
                                      public_composition_value)
            context[public_composition_key] = public_composition_value

            if public_composition_value == 0:
                # Check any existing projects -- if they are
                # world publishable, turn this feature OFF
                projects = Project.objects.filter(course=c)
                for p in projects:
                    try:
                        col = Collaboration.get_associated_collab(p)
                        if col._policy.policy_name == 'PublicEditorsAreOwners':
                            col.policy = 'CourseProtected'
                            col.save()
                    except:
                        pass

        context['changes_saved'] = True

    return context
Exemplo n.º 5
0
def dashboard(request):
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")
    
    return { 
       "space_viewer": user,
       "help_dashboard_nav_actions": UserSetting.get_setting(user, "help_dashboard_nav_actions", False),
       "help_dashboard_nav_reports": UserSetting.get_setting(user, "help_dashboard_nav_reports", False)      
    }
Exemplo n.º 6
0
def browse_sources(request):
    c = request.course

    user = request.user
    archives = []
    upload_archive = None
    for a in c.asset_set.archives().order_by('title'):
        archive = a.sources['archive']
        thumb = a.sources.get('thumb',None)
        description = a.metadata().get('description','')
        uploader = a.metadata().get('upload', 0)
        
        archive_context = {
            "id":a.id,
            "title":a.title,
            "thumb":(None if not thumb else {"id":thumb.id, "url":thumb.url}),
            "archive":{"id":archive.id, "url":archive.url},
            #is description a list or a string?
            "metadata": (description[0] if hasattr(description,'append') else description)
        }
        
        if (uploader[0] if hasattr(uploader,'append') else uploader):
            upload_archive = archive_context
        else:
            archives.append(archive_context)
        
    archives.sort(key=operator.itemgetter('title'))
    
    owners = []
    if in_course(user.username, request.course) and (user.is_staff or user.has_perm('assetmgr.can_upload_for')):
        owners = [{ 'username': m.username, 'public_name': get_public_name(m, request) } for m in request.course.members]
        
    rv = {"archives":archives,
          "upload_archive": upload_archive,
          "is_faculty":c.is_faculty(user),
          "space_viewer":user,
          'newsrc':request.GET.get('newsrc', ''),
          'can_upload': course_details.can_upload(request.user, request.course),
          'upload_service': getattr(settings,'UPLOAD_SERVICE',None),
          "help_browse_sources": UserSetting.get_setting(user, "help_browse_sources", True),
          "help_no_sources": UserSetting.get_setting(user, "help_no_sources", True),
          'msg': request.GET.get('msg', ''),
          'owners': owners, 
          }
    if not rv['archives']:
        rv['faculty_assets'] = [a for a in Asset.objects.filter(c.faculty_filter).order_by('added')
                                if a not in rv['archives'] ]

    if getattr(settings,'DJANGOSHERD_FLICKR_APIKEY',None):
        # MUST only contain string values for now!! 
        # (see templates/assetmgr/bookmarklet.js to see why or fix)
        rv['bookmarklet_vars'] = {'flickr_apikey':settings.DJANGOSHERD_FLICKR_APIKEY }
        
    
    return rv
Exemplo n.º 7
0
def set_user_setting(request, user_name):
    if not request.is_ajax():
        raise Http404()

    user = get_object_or_404(User, username=user_name)
    name = request.POST.get("name")
    value = request.POST.get("value")

    UserSetting.set_setting(user, name, value)

    json_stream = simplejson.dumps({'success': True})
    return HttpResponse(json_stream, mimetype='application/json')
Exemplo n.º 8
0
def class_addsource(request):
    key = course_details.UPLOAD_PERMISSION_KEY

    c = request.course
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")

    upload_enabled = False
    for a in c.asset_set.archives().order_by('title'):
        attribute = a.metadata().get('upload', 0)
        value = attribute[0] if hasattr(attribute, 'append') else attribute
        if value and int(value) == 1:
            upload_enabled = True
            break

    context = {
        'asset_request':
        request.GET,
        'course':
        c,
        'supported_archives':
        SupportedSource.objects.all().order_by("title"),  # sort by title
        'space_viewer':
        request.user,
        'is_staff':
        request.user.is_staff,
        'newsrc':
        request.GET.get('newsrc', ''),
        'upload_enabled':
        upload_enabled,
        'permission_levels':
        course_details.UPLOAD_PERMISSION_LEVELS,
        'help_video_upload':
        UserSetting.get_setting(user, "help_video_upload", True),
        'help_supported_collections':
        UserSetting.get_setting(user, "help_supported_collections", True),
        'help_dashboard_nav_actions':
        UserSetting.get_setting(user, "help_dashboard_nav_actions", False),
        'help_dashboard_nav_reports':
        UserSetting.get_setting(user, "help_dashboard_nav_reports", False)
    }

    if request.method == "GET":
        context[key] = int(
            c.get_detail(key, course_details.UPLOAD_PERMISSION_DEFAULT))
    else:
        upload_permission = request.POST.get(key)
        request.course.add_detail(key, upload_permission)
        context['changes_saved'] = True
        context[key] = int(upload_permission)

    return context
Exemplo n.º 9
0
def set_user_setting(request, user_name):
    if not request.is_ajax():
        raise Http404()
    
    user = get_object_or_404(User, username=user_name)
    name = request.POST.get("name")
    value = request.POST.get("value")
    
    UserSetting.set_setting(user, name, value)
    
    json_stream = simplejson.dumps({ 'success': True })
    return HttpResponse(json_stream, mimetype='application/json')
Exemplo n.º 10
0
def dashboard(request):
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")

    return {
        "space_viewer":
        user,
        "help_dashboard_nav_actions":
        UserSetting.get_setting(user, "help_dashboard_nav_actions", False),
        "help_dashboard_nav_reports":
        UserSetting.get_setting(user, "help_dashboard_nav_reports", False)
    }
Exemplo n.º 11
0
def triple_homepage(request):
    c = request.course

    if not c:
        return HttpResponseRedirect('/accounts/login/')

    user = request.user
    if request.GET.has_key('username'):
        user_name = request.GET['username']
        in_course_or_404(user_name, c)
        user = get_object_or_404(User, username=user_name)
    elif user.is_staff and request.GET.has_key('as'):
        user = get_object_or_404(User, username=request.GET['as'])
        
    #bad language, we should change this to user_of_assets or something
    space_viewer = request.user 
    if request.GET.has_key('as') and request.user.is_staff:
        space_viewer = get_object_or_404(User, username=request.GET['as'])   

    user_records = {
       'space_viewer': space_viewer,
       'space_owner' : user,
       "help_homepage_instructor_column": UserSetting.get_setting(user, "help_homepage_instructor_column", True),
       "help_homepage_classwork_column":  UserSetting.get_setting(user, "help_homepage_classwork_column", True)
    }
    prof_feed = get_prof_feed(c, request)
    discussions = get_discussions(c)

    full_prof_list = []
    for lis in (prof_feed['projects'], prof_feed['assignments'], discussions,):
        full_prof_list.extend(lis)
    full_prof_list.sort(lambda a, b:cmp(a.title.lower(), b.title.lower()))
    
    user_records.update(
        {'faculty_feed':prof_feed,
         'instructor_full_feed':full_prof_list,
         'is_faculty':c.is_faculty(user),
         'display':{'instructor':prof_feed['show'],
                    'course': (len(prof_feed['tags']) < 5)
                    },
         'discussions' : discussions,
         'msg': request.GET.get('msg', ''),
         'tag': request.GET.get('tag', ''),
         'view': request.GET.get('view', '')
         })
    return user_records
def class_manage_sources(request):
    key = course_details.UPLOAD_PERMISSION_KEY

    c = request.course
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")

    upload_enabled = False
    for a in c.asset_set.archives().order_by('title'):
        attribute = a.metadata().get('upload', 0)
        value = attribute[0] if hasattr(attribute, 'append') else attribute
        if value and int(value) == 1:
            upload_enabled = True
            break

    context = {
        'asset_request': request.GET,
        'course': c,
        'supported_archives': SupportedSource.objects.all().order_by("title"),
        'space_viewer': request.user,
        'is_staff': request.user.is_staff,
        'newsrc': request.GET.get('newsrc', ''),
        'delsrc': request.GET.get('delsrc', ''),
        'upload_enabled': upload_enabled,
        'permission_levels': course_details.UPLOAD_PERMISSION_LEVELS,
        'help_video_upload': UserSetting.get_setting(
            user, "help_video_upload", True),
        'help_supported_collections': UserSetting.get_setting(
            user, "help_supported_collections", True),
        'help_dashboard_nav_actions': UserSetting.get_setting(
            user, "help_dashboard_nav_actions", False),
        'help_dashboard_nav_reports': UserSetting.get_setting(
            user, "help_dashboard_nav_reports", False)
    }

    if request.method == "GET":
        context[key] = int(c.get_detail(
            key, course_details.UPLOAD_PERMISSION_DEFAULT))
    else:
        upload_permission = request.POST.get(key)
        request.course.add_detail(key, upload_permission)
        context['changes_saved'] = True
        context[key] = int(upload_permission)

    return context
Exemplo n.º 13
0
def notifications(request):
    c = request.course

    if not c:
        return HttpResponseRedirect('/accounts/login/')

    user = request.user
    if user.is_staff and request.GET.has_key('as'):
        user = get_object_or_404(User, username=request.GET['as'])

    class_feed = []

    #personal feed
    my_assets = {}
    for n in SherdNote.objects.filter(author=user, asset__course=c):
        my_assets[str(n.asset_id)] = 1
    for comment in Comment.objects.filter(user=user):
        if c == getattr(comment.content_object, 'course', None):
            my_assets[str(comment.object_pk)] = 1
    my_discussions = [
        d.collaboration_id for d in DiscussionIndex.objects.filter(
            participant=user,
            collaboration__context=request.collaboration_context)
    ]

    my_feed = Clumper(
        Comment.objects.filter(
            content_type=ContentType.objects.get_for_model(Asset),
            object_pk__in=my_assets.keys()).order_by(
                '-submit_date'),  #so the newest ones show up
        SherdNote.objects.filter(
            asset__in=my_assets.keys(),
            #no global annotations
            #warning: if we include global annotations
            #we need to stop it from autocreating one on-view
            #of the asset somehow
            range1__isnull=False).order_by('-added'),
        Project.objects.filter(Q(participants=user.pk) | Q(author=user.pk),
                               course=c).order_by('-modified'),
        DiscussionIndex.with_permission(
            request,
            DiscussionIndex.objects.filter(
                Q(Q(asset__in=my_assets.keys())
                  | Q(collaboration__in=my_discussions)
                  | Q(collaboration__user=request.user)
                  | Q(collaboration__group__user=request.user),
                  participant__isnull=False)).order_by('-modified')),
    )

    return {
        'my_feed':
        my_feed,
        'space_viewer':
        user,
        "help_notifications":
        UserSetting.get_setting(user, "help_notifications", True)
    }
Exemplo n.º 14
0
def notifications(request):
    c = request.course

    if not c:
        return HttpResponseRedirect('/accounts/login/')

    user = request.user
    if user.is_staff and request.GET.has_key('as'):
        user = get_object_or_404(User, username=request.GET['as'])

    class_feed = []

    #personal feed
    my_assets = {}
    for n in SherdNote.objects.filter(author=user, asset__course=c):
        my_assets[str(n.asset_id)] = 1
    for comment in Comment.objects.filter(user=user):
        if c == getattr(comment.content_object, 'course', None):
            my_assets[str(comment.object_pk)] = 1
    my_discussions = [d.collaboration_id for d in DiscussionIndex.objects
                      .filter(participant=user,
                              collaboration__context=request.collaboration_context
                              )]

    my_feed = Clumper(Comment.objects
                    .filter(content_type=ContentType.objects.get_for_model(Asset),
                            object_pk__in=my_assets.keys())
                    .order_by('-submit_date'), #so the newest ones show up
                    SherdNote.objects.filter(asset__in=my_assets.keys(),
                                             #no global annotations
                                             #warning: if we include global annotations
                                             #we need to stop it from autocreating one on-view
                                             #of the asset somehow
                                             range1__isnull=False
                                             )
                    .order_by('-added'),
                    Project.objects
                    .filter(Q(participants=user.pk) | Q(author=user.pk), course=c)
                    .order_by('-modified'),
                    DiscussionIndex.with_permission(request,
                                                    DiscussionIndex.objects
                                                    .filter(Q(Q(asset__in=my_assets.keys())
                                                              | Q(collaboration__in=my_discussions)
                                                              | Q(collaboration__user=request.user)
                                                              | Q(collaboration__group__user=request.user),
                                                              participant__isnull=False
                                                              )
                                                       )
                                                       .order_by('-modified')
                                                    ),
                    )

    return {
        'my_feed':my_feed,
        'space_viewer': user,
        "help_notifications": UserSetting.get_setting(user, "help_notifications", True)
    }
def should_show_tour(request, course, user):
    assets = annotated_by(Asset.objects.filter(course=course),
                          user,
                          include_archives=False)

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

    return UserSetting.get_setting(user,
                                   "help_show_homepage_tour",
                                   len(assets) < 1 and len(projects) < 1)
Exemplo n.º 16
0
def triple_homepage(request):
    c = request.course

    if not c:
        return HttpResponseRedirect('/accounts/login/')

    user = request.user        

    user_records = {
       'space_viewer': user,
       'space_owner' : user,
       "help_homepage_instructor_column": UserSetting.get_setting(user, "help_homepage_instructor_column", True),
       "help_homepage_classwork_column":  UserSetting.get_setting(user, "help_homepage_classwork_column", True)
    }
    prof_feed = get_prof_feed(c, request)
    discussions = get_course_discussions(c)

    full_prof_list = []
    for lis in (prof_feed['projects'], prof_feed['assignments'], discussions,):
        full_prof_list.extend(lis)
    full_prof_list.sort(lambda a, b:cmp(a.title.lower(), b.title.lower()))
    
    user_records.update({
        'faculty_feed': prof_feed,
        'instructor_full_feed': full_prof_list,
        'is_faculty': c.is_faculty(user),
        'display': {
           'instructor': prof_feed['show'],
           'course': (len(prof_feed['tags']) < 5)
         },
         'discussions': discussions,
         'msg': request.GET.get('msg', ''),
         'tag': request.GET.get('tag', ''),
         'view': request.GET.get('view', '')
         })
    return user_records
Exemplo n.º 17
0
def class_settings(request):
    import operator
    
    c = request.course
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")
    
    context = {
            'asset_request': request.GET,
            'course': c,
            'space_viewer': request.user,
            'is_staff': request.user.is_staff,
            'help_public_compositions': UserSetting.get_setting(user, "help_public_compositions", True),
    }
    
    key = course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY
    context[course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY] = int(c.get_detail(key, course_details.ALLOW_PUBLIC_COMPOSITIONS_DEFAULT))
    
    if request.method == "POST":
        value = int(request.POST.get(key))
        request.course.add_detail(key, value)
        context['changes_saved'] = True
        context[key] = value
        
        if value == 0:
            # Check any existing projects -- if they are world publishable, turn this feature OFF
            projects = Project.objects.filter(course=c)
            for p in projects:
                try:
                    col = Collaboration.get_associated_collab(p)
                    if col._policy.policy_name == 'PublicEditorsAreOwners':
                        col.policy = 'CourseProtected'
                        col.save()
                except:
                    pass
                
    return context
Exemplo n.º 18
0
def class_settings(request):
    c = request.course
    user = request.user
    if not request.course.is_faculty(user):
        return HttpResponseForbidden("forbidden")

    context = {
        'asset_request':
        request.GET,
        'course':
        c,
        'space_viewer':
        request.user,
        'is_staff':
        request.user.is_staff,
        'help_public_compositions':
        UserSetting.get_setting(user, "help_public_compositions", True),
        'help_selection_visibility':
        UserSetting.get_setting(user, "help_selection_visibility", True),
    }

    public_composition_key = course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY
    context[course_details.ALLOW_PUBLIC_COMPOSITIONS_KEY] = int(
        c.get_detail(public_composition_key,
                     course_details.ALLOW_PUBLIC_COMPOSITIONS_DEFAULT))

    selection_visibility_key = course_details.SELECTION_VISIBILITY_KEY
    context[course_details.SELECTION_VISIBILITY_KEY] = int(
        c.get_detail(selection_visibility_key,
                     course_details.SELECTION_VISIBILITY_DEFAULT))

    if request.method == "POST":
        if request.POST.has_key(selection_visibility_key):
            selection_visibility_value = int(
                request.POST.get(selection_visibility_key))
            request.course.add_detail(selection_visibility_key,
                                      selection_visibility_value)
            context[selection_visibility_key] = selection_visibility_value

        if request.POST.has_key(public_composition_key):
            public_composition_value = int(
                request.POST.get(public_composition_key))
            request.course.add_detail(public_composition_key,
                                      public_composition_value)
            context[public_composition_key] = public_composition_value

            if public_composition_value == 0:
                # Check any existing projects -- if they are world publishable, turn this feature OFF
                projects = Project.objects.filter(course=c)
                for p in projects:
                    try:
                        col = Collaboration.get_associated_collab(p)
                        if col._policy.policy_name == 'PublicEditorsAreOwners':
                            col.policy = 'CourseProtected'
                            col.save()
                    except:
                        pass

        context['changes_saved'] = True

    return context
Exemplo n.º 19
0
def detail_asset_json(request, asset_id, options):
    asset = get_object_or_404(Asset, pk=asset_id)

    selections_visible = course_details.all_selections_are_visible(request.course) or \
        request.course.is_faculty(request.user)

    asset_json = asset.sherd_json(request)
    asset_key = 'x_%s' % asset.pk

    asset_json['user_analysis'] = 0

    ga = asset.global_annotation(request.user, False)
    if ga:
        asset_json['global_annotation_id'] = ga.id
        asset_json['notes'] = ga.body
        asset_json['user_tags'] = tag_json(ga.tags_split())

        if (asset_json['notes'] and len(asset_json['notes']) > 0) or \
            (asset_json['user_tags'] and len(asset_json['user_tags']) > 0):
            asset_json['user_analysis'] += 1

    if not selections_visible:
        owners = [request.user]
        owners.extend(request.course.faculty)
        asset_json['tags'] = tag_json(asset.filter_tags_by_users(owners, True))

    # DiscussionIndex is misleading. Objects returned are projects & discussions
    # title, object_pk, content_type, modified
    asset_json['references'] = [{
        'id':
        obj.collaboration.object_pk,
        'title':
        obj.collaboration.title,
        'type':
        obj.get_type_label(),
        'url':
        obj.get_absolute_url(),
        'modified':
        obj.modified.strftime("%m/%d/%y %I:%M %p")
    } for obj in DiscussionIndex.with_permission(
        request,
        DiscussionIndex.objects.filter(asset=asset).order_by('-modified'))]

    annotations = [{
        'asset_key': asset_key,
        'range1': None,
        'range2': None,
        'annotation': None,
        'id': 'asset-%s' % asset.pk,
        'asset_id': asset.pk,
    }]


    if request.GET.has_key('annotations') or \
        (options and options.has_key('include_annotations') and options['include_annotations']):
        # @todo: refactor this serialization into a common place.
        def author_name(request, annotation, key):
            if not annotation.author_id:
                return None
            return 'author_name', get_public_name(annotation.author, request)

        def primary_type(request, annotation, key):
            return "primary_type", asset.primary.label

        for ann in asset.sherdnote_set.filter(range1__isnull=False):
            visible = selections_visible or request.user == ann.author or request.course.is_faculty(
                ann.author)
            if visible:
                if request.user == ann.author:
                    asset_json['user_analysis'] += 1
                ann_json = ann.sherd_json(
                    request, 'x',
                    ('title', 'author', 'tags', author_name, 'body',
                     'modified', 'timecode', primary_type))
                annotations.append(ann_json)

    rv = {
        'type': 'asset',
        'assets': {
            asset_key: asset_json
        },  #we make assets plural here to be compatible with the project JSON structure
        'annotations': annotations,
        'user_settings': {
            'help_item_detail_view':
            UserSetting.get_setting(request.user, "help_item_detail_view",
                                    True)
        }
    }
    return rv
Exemplo n.º 20
0
def browse_sources(request):
    c = request.course

    user = request.user
    if user.is_staff and request.GET.has_key('as'):
        user = get_object_or_404(User, username=request.GET['as'])

    archives = []
    upload_archive = None
    for a in c.asset_set.archives().order_by('title'):
        archive = a.sources['archive']
        thumb = a.sources.get('thumb', None)
        description = a.metadata().get('description', '')
        uploader = a.metadata().get('upload', 0)

        archive_context = {
            "id":
            a.id,
            "title":
            a.title,
            "thumb": (None if not thumb else {
                "id": thumb.id,
                "url": thumb.url
            }),
            "archive": {
                "id": archive.id,
                "url": archive.url
            },
            #is description a list or a string?
            "metadata":
            (description[0] if hasattr(description, 'append') else description)
        }

        if (uploader[0] if hasattr(uploader, 'append') else uploader):
            upload_archive = archive_context
        else:
            archives.append(archive_context)

    archives.sort(key=operator.itemgetter('title'))

    rv = {
        "archives":
        archives,
        "upload_archive":
        upload_archive,
        "is_faculty":
        c.is_faculty(user),
        "space_viewer":
        user,
        'newsrc':
        request.GET.get('newsrc', ''),
        'can_upload':
        course_details.can_upload(request.user, request.course),
        'upload_service':
        getattr(settings, 'UPLOAD_SERVICE', None),
        "help_browse_sources":
        UserSetting.get_setting(user, "help_browse_sources", True),
        "help_no_sources":
        UserSetting.get_setting(user, "help_no_sources", True),
        'msg':
        request.GET.get('msg', '')
    }
    if not rv['archives']:
        rv['faculty_assets'] = [
            a for a in Asset.objects.filter(c.faculty_filter).order_by('added')
            if a not in rv['archives']
        ]

    if getattr(settings, 'DJANGOSHERD_FLICKR_APIKEY', None):
        # MUST only contain string values for now!!
        # (see templates/assetmgr/bookmarklet.js to see why or fix)
        rv['bookmarklet_vars'] = {
            'flickr_apikey': settings.DJANGOSHERD_FLICKR_APIKEY
        }

    return rv
Exemplo n.º 21
0
def detail_asset_json(request, asset_id, options):    
    asset = get_object_or_404(Asset, pk=asset_id)
    
    selections_visible = course_details.all_selections_are_visible(request.course) or \
        request.course.is_faculty(request.user)

    asset_json = asset.sherd_json(request)
    asset_key = 'x_%s' % asset.pk
    
    asset_json['user_analysis'] = 0
    
    ga = asset.global_annotation(request.user, False)
    if ga:
        asset_json['global_annotation_id'] = ga.id
        asset_json['notes'] = ga.body
        asset_json['user_tags'] = tag_json(ga.tags_split())
        
        if (asset_json['notes'] and len(asset_json['notes']) > 0) or \
            (asset_json['user_tags'] and len(asset_json['user_tags']) > 0):
            asset_json['user_analysis'] += 1
    
    if not selections_visible:
        owners = [ request.user ]
        owners.extend(request.course.faculty)
        asset_json['tags'] = tag_json(asset.filter_tags_by_users(owners, True))
        
        
    # DiscussionIndex is misleading. Objects returned are projects & discussions
    # title, object_pk, content_type, modified
    asset_json['references'] = [ {'id': obj.collaboration.object_pk, 
                                  'title': obj.collaboration.title, 
                                  'type': obj.get_type_label(), 
                                  'url': obj.get_absolute_url(),
                                  'modified': obj.modified.strftime("%m/%d/%y %I:%M %p") }
        for obj in DiscussionIndex.with_permission(request,
            DiscussionIndex.objects.filter(asset=asset).order_by('-modified')) ]
    
    
    annotations = [{
            'asset_key': asset_key,
            'range1': None,
            'range2': None,
            'annotation': None,
            'id': 'asset-%s' % asset.pk,
            'asset_id': asset.pk,
            }]
    
    
    if request.GET.has_key('annotations') or \
        (options and options.has_key('include_annotations') and options['include_annotations']):
        # @todo: refactor this serialization into a common place.
        def author_name(request, annotation, key):
            if not annotation.author_id:
                return None
            return 'author_name', get_public_name(annotation.author, request)
        def primary_type(request, annotation, key):
            return "primary_type", asset.primary.label
        for ann in asset.sherdnote_set.filter(range1__isnull=False):
            visible = selections_visible or request.user == ann.author or request.course.is_faculty(ann.author)
            if visible:
                if request.user == ann.author:
                    asset_json['user_analysis'] += 1     
                ann_json = ann.sherd_json(request, 'x', ('title', 'author', 'tags', author_name, 'body', 'modified', 'timecode', primary_type))
                annotations.append(ann_json)

    rv = {
        'type': 'asset',
        'assets': { asset_key: asset_json }, #we make assets plural here to be compatible with the project JSON structure
        'annotations': annotations,
        'user_settings': { 'help_item_detail_view': UserSetting.get_setting(request.user, "help_item_detail_view", True) }
    }
    return rv