def handle(self, *args, **options): with open('media/csv/users.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: user = User() user.id = int(row['ID']) user.username = row['user_login'] user.email = row['user_email'] user.date_joined = row['user_registered'] user.first_name = row['display_name'].split(' ')[0] user.last_name = row['display_name'].split(' ')[-1] user.save() with open('media/csv/posts.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: post = Post() post.id = int(row['ID']) post.title = row['post_title'] post.content = row['post_content'] post.published_at = row['post_date'] post.slug = row['post_name'] post.user_id = row['post_author'] post.save() with open('media/csv/comments.csv') as csvfile: reader = csv.DictReader(csvfile) for row in reader: comment = ThreadedComment() comment.id = int(row['comment_ID']) comment.object_pk = row['comment_post_ID'] comment.content_type_id = 15 comment.site_id = 1 comment.user_name = row['comment_author'] comment.user_email = row['comment_author_email'] comment.user_url = row['comment_author_url'] comment.ip_address = row['comment_author_IP'] comment.submit_date = row['comment_date'] comment.comment = row['comment_content'] if row['comment_parent'] != '0': comment.parent_id = row['comment_parent'] if row['user_id'] != '0': comment.user_id = row['user_id'] comment.save()
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')
def import_place_comment(content_type, place): comment = ThreadedComment() comment.content_type = content_type comment.site_id = settings.SITE_ID