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