コード例 #1
0
ファイル: views.py プロジェクト: aayman/mediathread
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 )
コード例 #2
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)))
コード例 #3
0
ファイル: views.py プロジェクト: avorio/mediathread
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')
コード例 #4
0
ファイル: views.py プロジェクト: oaubert/mediathread
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')
コード例 #5
0
ファイル: views.py プロジェクト: tomaszzielinski/mediathread
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")
コード例 #6
0
ファイル: views.py プロジェクト: tmnogueira/mediathread
    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')
コード例 #7
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)