def post(self, request, modelType, objectID): # User has submitted new/reply comment - validate and save to DB. obj, con_type = BioGPSModel.get_object_and_ctype(modelType, pk=objectID) comment_form = BiogpsThreadedCommentForm(target_object=obj, parent=request.POST['parent'], data=request.POST) if comment_form.is_valid(): #parent_link = request.META['HTTP_REFERER'] user_comment = comment_form.cleaned_data['comment'] username = getattr(request.user, 'username') c = ThreadedComment() c.user_name = username c.user_id = getattr(request.user, 'id') c.comment = user_comment cleaned_parent = comment_form.cleaned_data['parent'] if cleaned_parent is not None: #parent_link += '#%s' % cleaned_parent c.parent = get_object_or_404(ThreadedComment, pk=cleaned_parent) c.object_pk = comment_form.cleaned_data['object_pk'] c.content_type = con_type c.site = Site.objects.get_current() c.save() # Use new comment ID in link if no parent #if parent_link.find('#') == -1: # parent_link += '#%s' % c.id # If missing request HTTP_REFERER re-direct to landing page http_referer = 'http://biogps.org/%s/%s/' % (modelType, objectID) try: http_referer = request.META['HTTP_REFERER'] except KeyError: # No referer, possibly b/c of private browsing pass # If comment was made on plugin email owner bcc admins if con_type.model == 'biogpsplugin': from django.core.mail import EmailMessage msg = EmailMessage('[BioGPS] New comment on plugin: %s' % obj.title, 'New comment:<br><br>%s<br> '\ ' -posted by %s<br><br>Link: %s' % (user_comment, request.user.get_valid_name(), http_referer), # request.user.get_valid_name(), parent_link), settings.DEFAULT_FROM_EMAIL, [obj.owner.email], [i[1] for i in settings.ADMINS]) msg.content_subtype = "html" msg.send(fail_silently=False) # Re-direct to parent comment that user replied to. #return HttpResponseRedirect(parent_link) return HttpResponseRedirect(http_referer) else: return HttpResponse("A comment is required. Please use your\ browser's back button to edit your comment.")
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()