Beispiel #1
0
    def create_or_update_collaboration(self, policy_name):
        try:
            col = Collaboration.objects.get_for_object(self)
            col.title = self.title
        except Collaboration.DoesNotExist:
            context = Collaboration.objects.get_for_object(self.course)
            col = Collaboration(user=self.author, title=self.title,
                                content_object=self, context=context)
        col.set_policy(policy_name)
        col.save()

        self.collaboration_sync_group(col)
        return col
Beispiel #2
0
def show_discussion(request, root_comment):
    space_viewer = request.user
    if space_viewer.is_staff and request.GET.has_key('as'):
        space_viewer = get_object_or_404(User,username=request.GET['as'])

    if request.method == "DELETE":
        return delete_collaboration(request, root_comment.object_pk)

    if not root_comment.content_object.permission_to('read',request):
        return HttpResponseForbidden('You do not have permission to view this discussion.')
    
    try:
        my_course = root_comment.content_object.context.content_object
    except:
        #legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = Collaboration.get_associated_collab(my_course)
        root_comment.content_object.save()

    target = None
    if root_comment.content_object._parent_id and \
            root_comment.content_object._parent.object_pk:
        target = root_comment.content_object._parent

    rv = {
        'is_space_owner': True,
        'edit_comment_permission': my_course.is_faculty(space_viewer),
        'space_owner': space_viewer, #for now
        'space_viewer': space_viewer,
        'root_comment': root_comment,
        'target':target,        
        'COMMENT_MAX_LENGTH':COMMENT_MAX_LENGTH, #change this in settings.COMMENT_MAX_LENGTH
        }
    
    return render_to_response('discussions/discussion.html', rv, context_instance=RequestContext(request))
Beispiel #3
0
def show(request, discussion_id):
    """Show a threadedcomments discussion of an arbitrary object.
    discussion_id is the pk of the root comment."""
    root_comment = get_object_or_404(ThreadedComment, pk = discussion_id)

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

    if not root_comment.content_object.permission_to('read',request):
        return HttpResponseForbidden('You do not have permission to view this discussion.')
    
    try:
        my_course = root_comment.content_object.context.content_object
    except:
        #temporary:
        my_courses = [c for c in Course.objects.all() if request.user in c.members]
        my_course = my_courses[-1]
        root_comment.content_object.context = Collaboration.get_associated_collab(my_course)

    assets = annotated_by(Asset.objects.filter(course=my_course), space_viewer)

    return {
        'is_space_owner': True,
        'edit_comment_permission': my_course.is_faculty,
        'space_owner': space_owner,
        'space_viewer': space_viewer,
        'root_comment': root_comment,
        'assets': assets,
        'page_in_edit_mode': True,
        }
Beispiel #4
0
def discussion_view(request, discussion_id):
    """Show a threadedcomments discussion of an arbitrary object.
    discussion_id is the pk of the root comment."""

    root_comment = get_object_or_404(ThreadedComment, pk=discussion_id)
    if not root_comment.content_object.permission_to('read', request):
        return HttpResponseForbidden('You do not have permission \
                                     to view this discussion.')

    try:
        my_course = root_comment.content_object.context.content_object
    except:
        # legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = \
            Collaboration.get_associated_collab(my_course)
        root_comment.content_object.save()

    data = {'space_owner': request.user.username}

    if not request.is_ajax():
        data['discussion'] = root_comment
        return render_to_response('discussions/discussion.html', data,
                                  context_instance=RequestContext(request))
    else:
        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(request.course))

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

        data['panels'] = [{
            'panel_state': 'open',
            'subpanel_state': 'open',
            'panel_state_label': "Discussion",
            'template': 'discussion',
            'owners': owners,
            'vocabulary': vocabulary,
            'title': root_comment.title,
            'can_edit_title': my_course.is_faculty(request.user),
            'root_comment_id': root_comment.id,
            'context': threaded_comment_json(request, root_comment)
        }]

        # Create a place for asset editing
        panel = {'panel_state': 'closed',
                 'panel_state_label': "Item Details",
                 'template': 'asset_quick_edit',
                 'update_history': False,
                 'show_collection': False,
                 'owners': owners,
                 'vocabulary': vocabulary,
                 'context': {'type': 'asset'}}

        data['panels'].append(panel)

        return HttpResponse(simplejson.dumps(data, indent=2),
                            mimetype='application/json')
Beispiel #5
0
 def set_course(self, course):
     """ set this discussion's collaboration to the course's collaboration"""
     assert isinstance (course, Course)
     if course is None:
         self.collaboration = None
     course_ct =  ContentType.objects.get (name = 'course')
     sc = Collaboration.get_associated_collab(course)
     assert sc is not None
     self.collaboration = sc
Beispiel #6
0
def class_settings(request):
    course = request.course
    user = request.user

    context = {
        'asset_request': request.GET,
        'course': course,
        '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(
        course.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(
        course.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=course)
                for project in projects:
                    try:
                        col = Collaboration.get_associated_collab(project)
                        if col._policy.policy_name == 'PublicEditorsAreOwners':
                            col.policy = 'CourseProtected'
                            col.save()
                    except:
                        pass

        context['changes_saved'] = True

    return context
Beispiel #7
0
def class_settings(request):
    c = request.course
    user = request.user

    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
Beispiel #8
0
def new(request):
    """Start a discussion of an arbitrary model instance."""
    #pdb.set_trace()
    rp = request.POST
    app_label, model, obj_pk, comment_html =  ( rp['app_label'], rp['model'], rp['obj_pk'], rp['comment_html'] )
    #Find the object we're discussing.
    the_content_type = ContentType.objects.get(app_label=app_label, model=model)
    assert the_content_type != None
    
    the_object = the_content_type.get_object_for_this_type(pk = obj_pk)
    assert the_object != None
    
    
    try:
        obj_sc = Collaboration.get_associated_collab(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)

    #now create the CHILD collaboration object for the discussion to point at.
    #This represents the auth for the discussion itself.
    disc_sc = Collaboration(_parent=obj_sc,
                            title=comment_html,
                            #or we could point it at the root threadedcomments object.
                            #content_object=None,
                            context=request.collaboration_context,
                            )
    disc_sc.save()

    #finally create the root discussion object, pointing it at the CHILD.
    #TODO point the context at the course
    new_threaded_comment = ThreadedComment(parent=None, 
                                           title=comment_html,
                                           comment=comment_html, 
                                           user=request.user, 
                                           content_object=disc_sc)
    
    #TODO: find the default site_id
    new_threaded_comment.site_id = 1
    new_threaded_comment.save()
    return HttpResponseRedirect( "/discussion/show/%d" % new_threaded_comment.id )
Beispiel #9
0
def show_discussion(request, root_comment):
    space_viewer = request.user
    if space_viewer.is_staff and request.GET.has_key('as'):
        space_viewer = get_object_or_404(User, username=request.GET['as'])

    if request.method == "DELETE":
        return delete_collaboration(request, root_comment.object_pk)

    if not root_comment.content_object.permission_to('read', request):
        return HttpResponseForbidden(
            'You do not have permission to view this discussion.')

    try:
        my_course = root_comment.content_object.context.content_object
    except:
        #legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = Collaboration.get_associated_collab(
            my_course)
        root_comment.content_object.save()

    switcher = {
        'init': reverse('annotations-fragment', args=[space_viewer.username])
    }
    target = None
    if root_comment.content_object._parent_id and \
            root_comment.content_object._parent.object_pk:
        target = root_comment.content_object._parent

        if 'project' == target.content_type.model:
            switcher['init'] = reverse('annotations-fragment-none',
                                       args=['none'])
            switcher['project_json'] = '%s%s' % (
                target.content_object.get_absolute_url(),
                'json',  #appended for json content (and avoiding cache poisoning webkit)
            )
        elif 'course' == target.content_type.model:
            #so we don't show a pointer for global discussions
            target = None

    return {
        'is_space_owner': True,
        'edit_comment_permission': my_course.is_faculty(space_viewer),
        'space_owner': space_viewer,  #for now
        'space_viewer': space_viewer,
        'root_comment': root_comment,
        'target': target,
        'switcher': switcher,
        'page_in_edit_mode': True,
        #change this in settings.COMMENT_MAX_LENGTH
        'COMMENT_MAX_LENGTH': COMMENT_MAX_LENGTH,
    }
Beispiel #10
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)))
Beispiel #11
0
def show_discussion(request, root_comment):
    space_viewer = request.user
    if space_viewer.is_staff and request.GET.has_key('as'):
        space_viewer = get_object_or_404(User,username=request.GET['as'])

    if request.method == "DELETE":
        return delete_collaboration(request, root_comment.object_pk)

    if not root_comment.content_object.permission_to('read',request):
        return HttpResponseForbidden('You do not have permission to view this discussion.')
    
    try:
        my_course = root_comment.content_object.context.content_object
    except:
        #legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = Collaboration.get_associated_collab(my_course)
        root_comment.content_object.save()

    switcher = {
        'init':reverse('annotations-fragment', args=[space_viewer.username])
        }
    target = None
    if root_comment.content_object._parent_id and \
            root_comment.content_object._parent.object_pk:
        target = root_comment.content_object._parent

        if 'project'==target.content_type.model:
            switcher['init'] = reverse('annotations-fragment-none', args=['none'])
            switcher['project_json'] = '%s%s' % (
                target.content_object.get_absolute_url(),
                'json', #appended for json content (and avoiding cache poisoning webkit)
                )
        elif 'course'==target.content_type.model:
            #so we don't show a pointer for global discussions
            target = None

    return {
        'is_space_owner': True,
        'edit_comment_permission': my_course.is_faculty(space_viewer),
        'space_owner': space_viewer, #for now
        'space_viewer': space_viewer,
        'root_comment': root_comment,
        'target':target,
        'switcher':switcher,
        'page_in_edit_mode': True,
        #change this in settings.COMMENT_MAX_LENGTH
        'COMMENT_MAX_LENGTH':COMMENT_MAX_LENGTH,
        }
Beispiel #12
0
    def create_or_update_collaboration(self, policy_name):
        try:
            col = Collaboration.objects.get_for_object(self)
            col.title = self.title
        except Collaboration.DoesNotExist:
            col = Collaboration(user=self.author,
                                title=self.title,
                                content_object=self)
        if col.context is None:
            col.context = Collaboration.objects.get_for_object(self.course)
        col.set_policy(policy_name)
        col.save()

        self.collaboration_sync_group(col)
        return col
Beispiel #13
0
    def collaboration(self, request=None, sync_group=False):
        col = None
        policy = None
        if request and request.method == "POST":
            policy = request.POST.get("publish", "PrivateEditorsAreOwners")

        try:
            col = Collaboration.get_associated_collab(self)
        except Collaboration.DoesNotExist:
            if policy is None:
                policy = "PrivateEditorsAreOwners"

            if request is not None:
                col = Collaboration.objects.create(
                    user=self.author,
                    title=self.title,
                    content_object=self,
                    context=request.collaboration_context,
                    policy=policy,
                )

        if col is None:  # iff collab did not exist and request is None
            return

        if sync_group:
            part = self.participants.all()
            if (
                len(part) > 1
                or (col.group_id and col.group.user_set.count() > 1)
                or (self.author not in part and len(part) > 0)
            ):
                colgrp = col.have_group()
                already_grp = set(colgrp.user_set.all())
                for p in part:
                    if p in already_grp:
                        already_grp.discard(p)
                    else:
                        colgrp.user_set.add(p)
                for oldp in already_grp:
                    colgrp.user_set.remove(oldp)
            if request and request.method == "POST" and (col.policy != policy or col.title != self.title):
                col.title = self.title
                col.policy = policy
                col.save()

        return col
Beispiel #14
0
    def collaboration(self, request=None, sync_group=False):
        col = None
        policy = None
        if request and request.method == "POST":
            policy = request.POST.get('publish', 'PrivateEditorsAreOwners')

        try:
            col = Collaboration.get_associated_collab(self)
        except Collaboration.DoesNotExist:
            if policy is None:
                policy = "PrivateEditorsAreOwners"

            if request is not None:
                col = Collaboration.objects.create(
                    user=self.author,
                    title=self.title,
                    content_object=self,
                    context=request.collaboration_context,
                    policy=policy,
                )

        if col is None:  # iff collab did not exist and request is None
            return

        if sync_group:
            participants = self.participants.all()
            if (len(participants) > 1
                    or (col.group_id and col.group.user_set.count() > 1) or
                (self.author not in participants and len(participants) > 0)):
                colgrp = col.have_group()
                already_grp = set(colgrp.user_set.all())
                for user in participants:
                    if user in already_grp:
                        already_grp.discard(user)
                    else:
                        colgrp.user_set.add(user)
                for oldp in already_grp:
                    colgrp.user_set.remove(oldp)
            if request and request.method == "POST" and \
                    (col.policy != policy or col.title != self.title):
                col.title = self.title
                col.policy = policy
                col.save()

        return col
Beispiel #15
0
def discussion_view(request, discussion_id):
    """Show a threadedcomments discussion of an arbitrary object.
    discussion_id is the pk of the root comment."""
    
    root_comment = get_object_or_404(ThreadedComment, pk=discussion_id)
    if not root_comment.content_object.permission_to('read', request):
        return HttpResponseForbidden('You do not have permission to view this discussion.')
    
    try:
        my_course = root_comment.content_object.context.content_object
    except:
        #legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = Collaboration.get_associated_collab(my_course)
        root_comment.content_object.save()
        
    data = { 'space_owner' : request.user.username }    

    if not request.is_ajax():
        data['discussion'] = root_comment
        return render_to_response('discussions/discussion.html', data, context_instance=RequestContext(request))
    else:
        data['panels'] = [{ 
            'panel_state': 'open',
            'subpanel_state': 'open',
            'panel_state_label': "Discussion",
            'template': 'discussion',
            'title': root_comment.title,
            'can_edit_title': my_course.is_faculty(request.user),
            'root_comment_id': root_comment.id,
            'context': threaded_comment_json(root_comment, request.user)
        }]
        
        # Create a place for asset editing
        panel = { 'panel_state': 'closed',
                  'panel_state_label': "Item Details",
                  'template': 'asset_quick_edit',
                  'update_history': False,
                  'show_colleciton': False,
                  'context': { 'type': 'asset' }
        }
        data['panels'].append(panel)    

        
        return HttpResponse(simplejson.dumps(data, indent=2), mimetype='application/json')
Beispiel #16
0
def discussion_view(request, discussion_id):
    """Show a threadedcomments discussion of an arbitrary object.
    discussion_id is the pk of the root comment."""

    root_comment = get_object_or_404(ThreadedComment, pk=discussion_id)
    if not root_comment.content_object.permission_to("read", request):
        return HttpResponseForbidden("You do not have permission to view this discussion.")

    try:
        my_course = root_comment.content_object.context.content_object
    except:
        # legacy: for when contexts weren't being set in new()
        my_course = request.course
        root_comment.content_object.context = Collaboration.get_associated_collab(my_course)
        root_comment.content_object.save()

    data = {"space_owner": request.user.username}

    if not request.is_ajax():
        data["discussion"] = root_comment
        return render_to_response("discussions/discussion.html", data, context_instance=RequestContext(request))
    else:
        data["panels"] = [
            {
                "panel_state": "open",
                "subpanel_state": "open",
                "panel_state_label": "Discussion",
                "template": "discussion",
                "title": root_comment.title,
                "can_edit_title": my_course.is_faculty(request.user),
                "root_comment_id": root_comment.id,
                "context": threaded_comment_json(root_comment, request.user),
            }
        ]

        return HttpResponse(simplejson.dumps(data, indent=2), mimetype="application/json")
Beispiel #17
0
 def test_get_associated_collaboration_course(self):
     course = Course.objects.get(id=2)
     collaboration = Collaboration.get_associated_collab(course)
     self.assertIsNotNone(collaboration)
Beispiel #18
0
def discussion_create(request):
    """Start a discussion of an arbitrary model instance."""
    title = request.POST['comment_html']

    # Find the object we're discussing.
    the_content_type = ContentType.objects.get(
        app_label=request.POST['app_label'], model=request.POST['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.get_associated_collab(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.
    disc_sc = Collaboration(
        _parent=obj_sc,
        title=title,
        # or we could point it at the root
        # threadedcomments object.
        # content_object=None,
        context=request.collaboration_context,
    )
    disc_sc.policy = request.POST.get('publish', None)
    if request.POST.get('inherit', None) == 'true':
        disc_sc.group_id = obj_sc.group_id
        disc_sc.user_id = obj_sc.user_id
    disc_sc.save()

    # finally create the root discussion object, pointing it at the CHILD.
    new_threaded_comment = ThreadedComment(parent=None,
                                           title=title,
                                           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()

    if not request.is_ajax():
        return HttpResponseRedirect("/discussion/%d/" %
                                    new_threaded_comment.id)
    else:
        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(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(simplejson.dumps(data, indent=2),
                            mimetype='application/json')
Beispiel #19
0
def new(request):
    """Start a discussion of an arbitrary model instance."""
    rp = request.POST

    title = rp['comment_html']
    #Find the object we're discussing.
    the_content_type = ContentType.objects.get(app_label=rp['app_label'],
                                               model=rp['model'])
    assert the_content_type != None

    the_object = the_content_type.get_object_for_this_type(pk=rp['obj_pk'])
    assert the_object != None

    try:
        obj_sc = Collaboration.get_associated_collab(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.
    disc_sc = Collaboration(
        _parent=obj_sc,
        title=title,
        #or we could point it at the root threadedcomments object.
        #content_object=None,
        context=request.collaboration_context,
    )
    disc_sc.policy = rp.get('publish', None)
    if rp.get('inherit', None) == 'true':
        disc_sc.group_id = obj_sc.group_id
        disc_sc.user_id = obj_sc.user_id
    disc_sc.save()

    #finally create the root discussion object, pointing it at the CHILD.
    new_threaded_comment = ThreadedComment(parent=None,
                                           title=title,
                                           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()

    return HttpResponseRedirect("/discussion/show/%d" %
                                new_threaded_comment.id)
Beispiel #20
0
def discussion_create(request):
    if not request.course.is_faculty(request.user):
        return HttpResponseForbidden("forbidden")

    """Start a discussion of an arbitrary model instance."""
    rp = request.POST

    title = rp["comment_html"]

    # Find the object we're discussing.
    the_content_type = ContentType.objects.get(app_label=rp["app_label"], model=rp["model"])
    assert the_content_type != None

    the_object = the_content_type.get_object_for_this_type(pk=rp["obj_pk"])
    assert the_object != None

    try:
        obj_sc = Collaboration.get_associated_collab(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.
    disc_sc = Collaboration(
        _parent=obj_sc,
        title=title,
        # or we could point it at the root threadedcomments object.
        # content_object=None,
        context=request.collaboration_context,
    )
    disc_sc.policy = rp.get("publish", None)
    if rp.get("inherit", None) == "true":
        disc_sc.group_id = obj_sc.group_id
        disc_sc.user_id = obj_sc.user_id
    disc_sc.save()

    # finally create the root discussion object, pointing it at the CHILD.
    new_threaded_comment = ThreadedComment(
        parent=None, title=title, 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()

    if not request.is_ajax():
        return HttpResponseRedirect("/discussion/show/%d" % new_threaded_comment.id)
    else:
        data = {
            "panel_state": "open",
            "panel_state_label": "Instructor Feedback",
            "template": "discussion",
            "context": threaded_comment_json(new_threaded_comment, request.user),
        }
        return HttpResponse(simplejson.dumps(data, indent=2), mimetype="application/json")
Beispiel #21
0
 def test_get_associated_collaboration_project(self):
     project = Project.objects.get(id=2)
     collaboration = Collaboration.get_associated_collab(project)
     self.assertIsNotNone(collaboration)
Beispiel #22
0
def discussion_create(request):

    """Start a discussion of an arbitrary model instance."""
    title = request.POST['comment_html']

    # Find the object we're discussing.
    the_content_type = ContentType.objects.get(
        app_label=request.POST['app_label'], model=request.POST['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.
    disc_sc = Collaboration(_parent=obj_sc,
                            title=title,
                            # or we could point it at the root
                            # threadedcomments object.
                            # content_object=None,
                            context=request.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='',
                                           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()

    if not request.is_ajax():
        return HttpResponseRedirect("/discussion/%d/" %
                                    new_threaded_comment.id)
    else:
        vocabulary = VocabularyResource().render_list(
            request, Vocabulary.objects.get_for_object(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')
Beispiel #23
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')