示例#1
0
    def test_post(self):
        self.assertTrue(
            self.client.login(username=self.instructor_one.username,
                              password='******'))
        data = {
            course_details.UPLOAD_PERMISSION_KEY:
            course_details.UPLOAD_PERMISSION_ADMINISTRATOR
        }

        self.client.post('/dashboard/sources/', data)
        self.assertTrue(course_details.can_upload(self.superuser,
                                                  self.sample_course))
        self.assertFalse(course_details.can_upload(self.instructor_one,
                                                   self.sample_course))
        self.assertFalse(course_details.can_upload(self.student_one,
                                                   self.sample_course))
示例#2
0
def deprecated_course_detail_view(request, course_pk):
    try:
        course = get_object_or_404(Course, pk=course_pk)
        request.course = course
        request.session[SESSION_KEY] = course
    except Course.DoesNotExist:
        return HttpResponseRedirect('/accounts/login/')

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

    qs = ExternalCollection.objects.filter(course=request.course)
    collections = qs.filter(uploader=False).order_by('title')
    uploader = qs.filter(uploader=True).first()

    owners = []
    if (request.course.is_member(logged_in_user)
            and (logged_in_user.is_staff
                 or logged_in_user.has_perm('assetmgr.can_upload_for'))):
        owners = UserResource().render_list(request, request.course.members)

    context = {
        'classwork_owner':
        classwork_owner,
        'information_title':
        course_information_title(course),
        'faculty_feed':
        Project.objects.faculty_compositions(course, logged_in_user),
        'is_faculty':
        cached_course_is_faculty(course, logged_in_user),
        'discussions':
        get_course_discussions(course),
        'msg':
        request.GET.get('msg', ''),
        'view':
        request.GET.get('view', ''),
        'collections':
        collections,
        'uploader':
        uploader,
        'can_upload':
        course_details.can_upload(request.user, request.course),
        'owners':
        owners
    }

    return context
    def test_can_upload(self):
        # default value - instructor level
        self.assertTrue(can_upload(self.superuser, self.sample_course))
        self.assertTrue(can_upload(self.instructor_one, self.sample_course))
        self.assertFalse(can_upload(self.student_one, self.sample_course))

        # set to - administrators only
        self.sample_course.add_detail(UPLOAD_PERMISSION_KEY,
                                      UPLOAD_PERMISSION_ADMINISTRATOR)
        self.assertTrue(can_upload(self.superuser, self.sample_course))
        self.assertFalse(can_upload(self.instructor_one, self.sample_course))
        self.assertFalse(can_upload(self.student_one, self.sample_course))

        # set to - student, instructor & admins
        self.sample_course.add_detail(UPLOAD_PERMISSION_KEY,
                                      UPLOAD_PERMISSION_STUDENT)
        self.assertTrue(can_upload(self.superuser, self.sample_course))
        self.assertTrue(can_upload(self.instructor_one, self.sample_course))
        self.assertTrue(can_upload(self.student_one, self.sample_course))
示例#4
0
    def test_can_upload(self):
        # default value - instructor level
        self.assertTrue(can_upload(self.superuser, self.sample_course))
        self.assertTrue(can_upload(self.instructor_one, self.sample_course))
        self.assertFalse(can_upload(self.student_one, self.sample_course))

        # set to - administrators only
        self.sample_course.add_detail(UPLOAD_PERMISSION_KEY,
                                      UPLOAD_PERMISSION_ADMINISTRATOR)
        self.assertTrue(can_upload(self.superuser, self.sample_course))
        self.assertFalse(can_upload(self.instructor_one, self.sample_course))
        self.assertFalse(can_upload(self.student_one, self.sample_course))

        # set to - student, instructor & admins
        self.sample_course.add_detail(UPLOAD_PERMISSION_KEY,
                                      UPLOAD_PERMISSION_STUDENT)
        self.assertTrue(can_upload(self.superuser, self.sample_course))
        self.assertTrue(can_upload(self.instructor_one, self.sample_course))
        self.assertTrue(can_upload(self.student_one, self.sample_course))
示例#5
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 'username' in request.GET:
        user_name = request.GET['username']
        in_course_or_404(user_name, request.course)
        classwork_owner = get_object_or_404(User, username=user_name)

    course = request.course

    collections = ExternalCollection.objects.filter(
        course=request.course, uploader=False).order_by('title')
    uploader = ExternalCollection.objects.filter(course=request.course,
                                                 uploader=True).first()

    owners = []
    if (in_course(logged_in_user.username, request.course) and
        (logged_in_user.is_staff or
         logged_in_user.has_perm('assetmgr.can_upload_for'))):
        owners = UserResource().render_list(request, request.course.members)

    context = {
        'classwork_owner': classwork_owner,
        "information_title": course_information_title(course),
        'faculty_feed': Project.objects.faculty_compositions(course,
                                                             logged_in_user),
        'is_faculty': course.is_faculty(logged_in_user),
        'discussions': get_course_discussions(course),
        'msg': request.GET.get('msg', ''),
        'view': request.GET.get('view', ''),
        'collections': collections,
        'uploader': uploader,
        'can_upload': course_details.can_upload(request.user, request.course),
        'owners': owners
    }

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

    return context
示例#6
0
def course_detail_view(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 'username' in request.GET:
        user_name = request.GET['username']
        in_course_or_404(user_name, request.course)
        classwork_owner = get_object_or_404(User, username=user_name)

    course = request.course

    qs = ExternalCollection.objects.filter(course=request.course)
    collections = qs.filter(uploader=False).order_by('title')
    uploader = qs.filter(uploader=True).first()

    owners = []
    if (request.course.is_member(logged_in_user) and
        (logged_in_user.is_staff or
         logged_in_user.has_perm('assetmgr.can_upload_for'))):
        owners = UserResource().render_list(request, request.course.members)

    context = {
        'classwork_owner': classwork_owner,
        'information_title': course_information_title(course),
        'faculty_feed': Project.objects.faculty_compositions(course,
                                                             logged_in_user),
        'is_faculty': cached_course_is_faculty(course, logged_in_user),
        'discussions': get_course_discussions(course),
        'msg': request.GET.get('msg', ''),
        'view': request.GET.get('view', ''),
        'collections': collections,
        'uploader': uploader,
        'can_upload': course_details.can_upload(request.user, request.course),
        'owners': owners
    }

    return context
示例#7
0
    def get_context_data(self, **kwargs):
        context = super(CourseDetailView, self).get_context_data(**kwargs)
        course = context.get('object')

        qs = ExternalCollection.objects.filter(course=self.request.course)
        collections = qs.filter(uploader=False).order_by('title')
        uploader = qs.filter(uploader=True).first()

        owners = []
        if (self.request.course.is_member(self.request.user) and
            (self.request.user.is_staff
             or self.request.user.has_perm('assetmgr.can_upload_for'))):
            owners = UserResource().render_list(self.request, course.members)

        context.update({
            'course':
            course,
            'classwork_owner':
            self.request.user,
            'information_title':
            course_information_title(course),
            'faculty_feed':
            Project.objects.faculty_compositions(course, self.request.user),
            'is_faculty':
            cached_course_is_faculty(course, self.request.user),
            'owners':
            owners,
            'collections':
            collections,
            'uploader':
            uploader,
            'msg':
            self.request.GET.get('msg', ''),
            'can_upload':
            course_details.can_upload(self.request.user, self.request.course),
        })
        return context
示例#8
0
文件: views.py 项目: 6C1/mediathread
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 'username' in request.GET:
        user_name = request.GET['username']
        in_course_or_404(user_name, request.course)
        classwork_owner = get_object_or_404(User, username=user_name)

    c = request.course

    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},
            "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'))

    show_tour = should_show_tour(request, c, logged_in_user)

    owners = []
    if (in_course(logged_in_user.username, request.course) and
        (logged_in_user.is_staff or
         logged_in_user.has_perm('assetmgr.can_upload_for'))):
        owners = UserResource().render_list(request, request.course.members)

    discussions = get_course_discussions(c)

    context = {
        'classwork_owner': classwork_owner,
        'help_homepage_instructor_column': False,
        'help_homepage_classwork_column': False,
        'faculty_feed': get_prof_feed(c, request),
        'is_faculty': c.is_faculty(logged_in_user),
        'discussions': discussions,
        'msg': request.GET.get('msg', ''),
        'view': request.GET.get('view', ''),
        'archives': archives,
        'upload_archive': upload_archive,
        'can_upload': course_details.can_upload(request.user, request.course),
        'show_tour': show_tour,
        'owners': owners
    }

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

    return context
示例#9
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 'username' in request.GET:
        user_name = request.GET['username']
        in_course_or_404(user_name, request.course)
        classwork_owner = get_object_or_404(User, username=user_name)

    course = request.course

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

        archive_context = {
            "id": item.id,
            "title": item.title,
            "thumb": (None if not thumb else {"id": thumb.id,
                                              "url": thumb.url}),
            "archive": {"id": archive.id, "url": archive.url},
            "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(logged_in_user.username, request.course) and
        (logged_in_user.is_staff or
         logged_in_user.has_perm('assetmgr.can_upload_for'))):
        owners = UserResource().render_list(request, request.course.members)

    context = {
        'classwork_owner': classwork_owner,
        'help_homepage_instructor_column': False,
        'help_homepage_classwork_column': False,
        'faculty_feed': get_prof_feed(course, request),
        'is_faculty': course.is_faculty(logged_in_user),
        'discussions': get_course_discussions(course),
        'msg': request.GET.get('msg', ''),
        'view': request.GET.get('view', ''),
        'archives': archives,
        'upload_archive': upload_archive,
        'can_upload': course_details.can_upload(request.user, request.course),
        'show_tour': should_show_tour(request, course, logged_in_user),
        'owners': owners
    }

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

    return context