示例#1
0
 def read(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return coll.context == course_collaboration and (
         (course and cached_course_is_faculty(course, user))
         or coll.user_id == user.id
         or (coll.group_id and user in coll.group.user_set.all())
     )
示例#2
0
    def read(self, coll, course, user):
        if not course:
            return False

        course_collaboration = cached_course_collaboration(course)
        return (coll.context == course_collaboration
                and cached_course_is_member(course, user))
示例#3
0
    def post(self, request):
        # create a project
        project = self.create_project()

        # get the project's collaboration object
        project_collab = project.get_collaboration()

        # construct a collaboration for this discussion
        # the parent will be this project within the course context
        # all course members can participate in the discussion
        course_collab = cached_course_collaboration(request.course)
        disc_collab = Collaboration(_parent=project_collab,
                                    title=project.title,
                                    context=course_collab)
        disc_collab.set_policy('CourseProtected')
        disc_collab.save()

        # Create a ThreadedComment that will act as the discussion root
        # It will be tied to the project via the collaboration object
        # as a generic foreign key
        new_threaded_comment = ThreadedComment.objects.create(
            parent=None,
            title=project.title,
            comment=project.body,
            user=request.user,
            site_id=1,
            content_object=disc_collab)

        # Conversely, the discussion collaboration will hold the
        # discussion root in its generic foreign key
        # this thread can now be accessed via the "course_discussion"
        # model attribute
        disc_collab.content_object = new_threaded_comment
        disc_collab.save()

        DiscussionIndex.update_class_references(
            new_threaded_comment.comment, new_threaded_comment.user,
            new_threaded_comment, new_threaded_comment.content_object,
            new_threaded_comment.user)

        return HttpResponseRedirect(
            reverse('project-workspace', args=(request.course.pk, project.pk)))
示例#4
0
    def post(self, request, *args, **kwargs):
        """Start a discussion of an arbitrary model instance."""
        title = request.POST['comment_html']
        comment = request.POST.get('comment', '')

        # Find the object we're discussing.
        model = request.POST['model']
        the_content_type = ContentType.objects.get(
            app_label=request.POST['app_label'], model=model)
        assert the_content_type is not None

        the_object = the_content_type.get_object_for_this_type(
            pk=request.POST['obj_pk'])
        assert the_object is not None

        try:
            obj_sc = Collaboration.objects.get_for_object(the_object)
        except Collaboration.DoesNotExist:
            obj_sc = Collaboration()
            # TODO: populate this collab with sensible auth defaults.
            obj_sc.content_object = the_object
            obj_sc.save()

        # sky: I think what I want to do is have the ThreadedComment
        # point to the_object
        # and the collaboration will point to the threaded root comment
        # that way, whereas, if we live in Collaboration-land,
        # we can get to ThreadedComments
        # threaded comments can also live in it's own world without 'knowing'
        # about SC OTOH, threaded comment shouldn't be able
        # to point to the regular object
        # until Collaboration says it's OK (i.e. has permissions)
        # ISSUE: how to migrate? (see models.py)

        # now create the CHILD collaboration object for the
        # discussion to point at.
        # This represents the auth for the discussion itself.
        collaboration_context = cached_course_collaboration(request.course)
        disc_sc = Collaboration(
            _parent=obj_sc,
            title=title,
            context=collaboration_context,
        )
        disc_sc.set_policy(request.POST.get('publish', None))
        disc_sc.save()

        # finally create the root discussion object, pointing it at the CHILD.
        new_threaded_comment = ThreadedComment(parent=None,
                                               title=title,
                                               comment=comment,
                                               user=request.user,
                                               content_object=disc_sc)

        # TODO: find the default site_id
        new_threaded_comment.site_id = 1
        new_threaded_comment.save()

        disc_sc.content_object = new_threaded_comment
        disc_sc.save()

        DiscussionIndex.update_class_references(
            new_threaded_comment.comment, new_threaded_comment.user,
            new_threaded_comment, new_threaded_comment.content_object,
            new_threaded_comment.user)

        if not request.is_ajax():
            if model == 'project':
                discussion_url = reverse('project-workspace',
                                         args=(request.course.pk,
                                               the_object.pk))
            else:
                discussion_url = reverse('discussion-view',
                                         args=(request.course.pk,
                                               new_threaded_comment.id))

            return HttpResponseRedirect(discussion_url)
        else:
            vocabulary = VocabularyResource().render_list(
                request, Vocabulary.objects.filter(course=request.course))

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

            data = {
                'panel_state': 'open',
                'panel_state_label': "Instructor Feedback",
                'template': 'discussion',
                'owners': owners,
                'vocabulary': vocabulary,
                'context': threaded_comment_json(request, new_threaded_comment)
            }

            return HttpResponse(json.dumps(data, indent=2),
                                content_type='application/json')
示例#5
0
 def manage(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return (coll.context == course_collaboration
             and (coll.user == user or
                  (coll.group and user in coll.group.user_set.all())))
示例#6
0
 def read(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return (coll.context == course_collaboration)
示例#7
0
 def manage(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return (coll.context == course_collaboration
             and ((course and cached_course_is_faculty(course, user))
                  or coll.user == user))
示例#8
0
 def read(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return (coll.context == course_collaboration
             and ((course and cached_course_is_faculty(course, user))
                  or coll.user_id == user.id or
                  (coll.group_id and user in coll.group.user_set.all())))
示例#9
0
    def read(self, coll, course, user):
        if not course:
            return False

        course_collaboration = cached_course_collaboration(course)
        return coll.context == course_collaboration and course.is_member(user)
示例#10
0
 def manage(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return coll.context == course_collaboration and (
         coll.user == user or (coll.group and user in coll.group.user_set.all())
     )
示例#11
0
 def read(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return coll.context == course_collaboration
示例#12
0
 def manage(self, coll, course, user):
     course_collaboration = cached_course_collaboration(course)
     return coll.context == course_collaboration and (
         (course and cached_course_is_faculty(course, user)) or coll.user == user
     )