Beispiel #1
0
def add_comment(request):
    if request.method == 'POST':
        content = request.POST.get('content').replace('\r', '<br>')
        id = request.POST.get('article_id')
        article = Article.objects.get(id=int(id))
        comment = ArticleComment(comment=content, user=request.user, article=article)
        comment.save()
        return redirect('/articles/' + id +'#' + id)
    else:
        return HttpResponseBadRequest()
Beispiel #2
0
def add_comment(request):
    if request.method == 'POST':
        content = request.POST.get('content').replace('\r', '<br>')
        id = request.POST.get('article_id')
        article = Article.objects.get(id=int(id))
        comment = ArticleComment(comment=content,
                                 user=request.user,
                                 article=article)
        comment.save()
        return redirect('/articles/' + id + '#' + id)
    else:
        return HttpResponseBadRequest()
Beispiel #3
0
def comment(request):
    try:
        if request.method == 'POST':
            article_id = request.POST.get('article')
            article = Article.objects.get(pk=article_id)
            comment = request.POST.get('comment')
            comment = comment.strip()
            if len(comment) > 0:
                article_comment = ArticleComment(user=request.user, article=article, comment=comment)
                article_comment.save()
            html = u''
            for comment in article.get_comments():
                html = u'{0}{1}'.format(html, render_to_string('articles/partial_article_comment.html', {'comment': comment}))
            return HttpResponse(html)
        else:
            return HttpResponseBadRequest()
    except Exception, e:
        return HttpResponseBadRequest()
Beispiel #4
0
def comment(request):
    try:
        if request.method == 'POST':
            article_id = request.POST.get('article')
            article = Article.objects.get(pk=article_id)
            comment = request.POST.get('comment')
            comment = comment.strip()
            if len(comment) > 0:
                article_comment = ArticleComment(user=request.user, article=article, comment=comment)
                article_comment.save()
            html = u''
            for comment in article.get_comments():
                html = u'{0}{1}'.format(html, render_to_string('articles/partial_article_comment.html', {'comment': comment}))
            return HttpResponse(html)
        else:
            return HttpResponseBadRequest()
    except Exception:
        return HttpResponseBadRequest()
Beispiel #5
0
def create_article_comment(request, *args, **kwargs):

    if request.is_ajax() and request.method == 'POST':
        if (not request.user.is_authenticated()):
            return_url = request.get_full_path()
            return HttpResponseRedirect('/home/login?next=' + return_url)

        comment = ArticleComment()
        comment.article_id = request.POST['article_id']
        comment.content = request.POST['content']
        current_time = datetime.utcnow()
        comment.create_date_time = current_time
        comment.update_date_time = current_time
        comment.author = request.user
        comment.save(force_insert=True)
        data = {'success': True}
        return HttpResponse(simplejson.dumps(data),
                            mimetype='application/json')
    else:
        return HttpResponseNotAllowed()
Beispiel #6
0
def create_article_comment(request, *args, **kwargs):
    
    if request.is_ajax() and request.method == 'POST':
        if (not request.user.is_authenticated()):
            return_url = request.get_full_path()
            return HttpResponseRedirect('/home/login?next=' + return_url)
        
        comment = ArticleComment()
        comment.article_id = request.POST['article_id']
        comment.content = request.POST['content']
        current_time = datetime.utcnow()
        comment.create_date_time = current_time
        comment.update_date_time = current_time
        comment.author = request.user
        comment.save(force_insert=True)
        data = {'success': True}
        return HttpResponse(simplejson.dumps(data), mimetype='application/json')
    else:
        return HttpResponseNotAllowed()
Beispiel #7
0
def comment(request):
    try:
        if request.method == 'POST':
            article_id = request.POST.get('article')
            article = Article.objects.get(pk=article_id)
            comment = request.POST.get('comment')
            comment = comment.strip()
            if len(comment) > 0:
                article_comment = ArticleComment(user=request.user,
                                                 article=article,
                                                 comment=comment)
                article_comment.save()
            html = ''
            for comment in article.get_comments():
                html = '{0}{1}'.format(html, render_to_string(
                    'articles/partial_article_comment.html',
                    {'comment': comment}))

            return HttpResponse(html)

        else:   # pragma: no cover
            return HttpResponseBadRequest()

    except Exception:   # pragma: no cover
        return HttpResponseBadRequest()


# def articlce_image(request):
#     uploaded_image = False
#     try:
#         if request.GET.get('upload_image') == 'uploaded':
#             uploaded_image = True
#
#     except Exception:  # pragma: no cover
#         pass
#
#     return render(request, 'core/picture.html',
#                   {'uploaded_picture': uploaded_image})
#
# def upload_picture(request):
#     try:
#         profile_pictures = django_settings.MEDIA_ROOT + '/profile_pictures/'
#         if not os.path.exists(profile_pictures):
#             os.makedirs(profile_pictures)
#         f = request.FILES['picture']
#         filename = profile_pictures + request.user.username + '_tmp.jpg'
#         with open(filename, 'wb+') as destination:
#             for chunk in f.chunks():
#                 destination.write(chunk)
#         im = Image.open(filename)
#         width, height = im.size
#         if width > 350:
#             new_width = 350
#             new_height = (height * 350) / width
#             new_size = new_width, new_height
#             im.thumbnail(new_size, Image.ANTIALIAS)
#             im.save(filename)
#
#         return redirect('/settings/picture/?upload_picture=uploaded')
#
#     except Exception as e:
#         return redirect('/settings/picture/')
#
#
# @login_required
# def save_uploaded_picture(request):
#     try:
#         x = int(request.POST.get('x'))
#         y = int(request.POST.get('y'))
#         w = int(request.POST.get('w'))
#         h = int(request.POST.get('h'))
#         tmp_filename = django_settings.MEDIA_ROOT + '/profile_pictures/' +\
#             request.user.username + '_tmp.jpg'
#         filename = django_settings.MEDIA_ROOT + '/profile_pictures/' +\
#             request.user.username + '.jpg'
#         im = Image.open(tmp_filename)
#         cropped_im = im.crop((x, y, w+x, h+y))
#         cropped_im.thumbnail((200, 200), Image.ANTIALIAS)
#         cropped_im.save(filename)
#         os.remove(tmp_filename)
#
#     except Exception:
#         pass
#
#     return redirect('/settings/picture/')