Esempio n. 1
0
def get_experience_details(request, id):
    experience = get_object_or_404(Experience, pk=id)

    experience.views += 1
    experience.save()

    comments = Comment.objects.all()
    comment_list = []

    for comment in comments:
        comment_list = Comment.objects.all().order_by('-pub_date').filter(
            experience__id=experience.id)

    # add comment
    form = CommentForm(request.POST)
    user = request.user

    if form.is_valid() and user.is_authenticated:
        content = form.cleaned_data['content']
        comment = Comment()
        comment.experience_id = experience.id
        comment.content = content
        comment.save()
        return HttpResponseRedirect(
            reverse('get_experience_details', args=(experience.id, )))

    contexts = {
        'experience': experience,
        'form': form,
        'comment_list': comment_list
    }

    return render(request, 'experience_details.html', contexts)
Esempio n. 2
0
 def post_handler(request):
     # JSON post body of what you post to a posts' comemnts
     # POST to http://service/posts/{POST_ID}/comments
     output = {
         "query": "addComment",
     }
     # change body = request.POST to body = request.body.decode('utf-8'),
     # because request.POST only accepts form, but here is json format.
     # change new_comment.comment to new_comment.content,
     # because that's how it defined in comment model.
     
     try:
         body = request.body.decode('utf-8')
         comment_info = loads(body)
         comment_info = comment_info['comment']
         new_comment = Comment()
         new_comment.contentType = comment_info['contentType']
         new_comment.content = comment_info['comment']
         new_comment.published = comment_info['published']
         new_comment.author = Author.objects.filter(id=comment_info['author']['id']).first()
         new_comment.parentPost = Post.objects.filter(id=post_id).first()
         new_comment.save()
         output['type'] = True
         output['message'] = "Comment added"
     except Exception as e:
         output['type'] = False
         output['message'] = "Comment not allowed"
         output['error'] = str(e)
     finally:
         return JsonResponse(output)
def post_detail(request, pk):
    """
    Create a view that returns a single
    Post object based on the post ID (pk) and
    render it to the 'postdetail.html' template.
    Or return a 404 error if the post is
    not found
    """
    post = get_object_or_404(Post, pk=pk)
    post.views += 1
    post.save()

    comments = Comment.objects.all()
    comment_list = []

    for comment in comments:
        comment_list = Comment.objects.all().order_by(
            '-pub_date').filter(post_id=post.pk)

    # add comment
    form = CommentForm(request.POST)

    user = request.user
    if form.is_valid() and user.is_authenticated:
        content = form.cleaned_data['content']
        comment = Comment()
        comment.post_id = post.id
        comment.content = content
        comment.save()
        return HttpResponseRedirect(reverse('post_detail', args=(post.id,)))

    return render(request, "postdetail.html", {'post': post, 'comments': comments, 'comment_list': comment_list, 'form': form})
Esempio n. 4
0
 def inject_comments(self):
     logging.info('Injecting comments...')
     with open('utils/dbinjector/comments.csv', newline='') as csv_file:
         csv_reader = csv.reader(csv_file, delimiter='|')
         for row in csv_reader:
             comment = Comment()
             comment.user = User.objects.get(username=row[0])
             comment.post = Post.objects.get(title=row[1])
             comment.content = row[2]
             comment.save()
Esempio n. 5
0
def add(request):
    print "Hit add request for comment"
    r = '/'
    if request.method =='POST':
        form = CommentForm(request.POST)
        #print repr(form.cleaned_data)
        #print request.POST
        if form.is_valid():
            d = form.cleaned_data
            #print d['suid']
            if suid_store.check(d['suid']):
                suid_store.add(d['suid'])
                suid_store.trim()
                c = Comment()
                p = d['parent'].split(':')
                pt = Ticket
                r = '/tickets/'
                print p[0]
                if p[0] in ('ticket','Ticket'):
                    pt = Ticket
                    r = '/tickets/'
                elif p[0] in ('comment','com','Comment','comments','Comments'):
                    pt = Comment
                    r = '/comments/'
                #print r
                #Insert other comment parents here
                try:
                    p = pt.objects.get(id=int(p[1]))
                    #print "Got model of type " + str(type(pt))
                    r += str(p.id) + '/'
                except:
                    #print 'Cannot get model of type ' + str(type(pt))
                    return HttpResponse('Invalid Parent')
                #c.content_type = ContentType.objects.get_for_model(pt)
                c.parent = p
                c.submittedby = request.user.member
                c.submittedtime = datetime.datetime.now()
                c.content = d['content']

                c.save()
                #print d['files']
                fs = getfilesfromfields(d['files'],d['autofiles'])
                if fs:
                    print fs
                    c.attachedfiles.add(*fs)
                c.save()
                
                #print "Id for new comment", c.id
                #print r
            else:
                print "Suid seen before"
        else:
            print "Form is invalid"
        #print r
        return HttpResponseRedirect(r)
Esempio n. 6
0
def add_comment(request, article_id):
    if request.user.is_authenticated and request.POST:
        print(request.POST)
        comment = Comment()
        comment.author = request.user
        comment.article_id = article_id
        comment.content = request.POST["comment_body"]
        comment.save()
        return redirect(reverse("main:single_art", args=[article_id]))
    else:
        return HttpResponseNotFound()
Esempio n. 7
0
 def post(self, request, id):
     name = request.POST.get("name")
     email = request.POST.get("email")
     url = request.POST.get("url")
     content = request.POST.get("content")
     comment = Comment()
     comment.name = name
     comment.email = email
     comment.url = url
     comment.content = content
     comment.article = get_object_or_404(Article, pk=id)
     comment.save()
     return redirect(reverse("article:single", args=(id, )))
Esempio n. 8
0
    def post(self, req, id):
        name = req.POST.get('name')
        url = req.POST.get('url')
        email = req.POST.get('email')
        content = req.POST.get('content')

        comment = Comment()
        comment.name = name
        comment.url = url
        comment.email = email
        comment.content = content
        comment.blog = get_object_or_404(Blog, pk=id)
        comment.save()
        return redirect(reverse('sport:single', args=(id, )))
Esempio n. 9
0
    def setUp(self):
        self.user = User.objects.all()[0]
        self.video = Video.objects.all()[0]

        self.auth = dict(username='******', password='******')
        self.logged_user = User.objects.get(username=self.auth['username'])
        l = self.video.subtitle_language()
        l.language_code = "en"
        l.save()
        comment = Comment(content_object=self.video)
        comment.user = self.logged_user
        comment.content = "testme"
        comment.submit_date = datetime.datetime.now()
        comment.save()
        self.comment = comment
Esempio n. 10
0
    def post_handler(request):
        # JSON post body of what you post to a posts' comemnts
        # POST to http://service/posts/{POST_ID}/comments
        output = {
            "query": "addComment",
        }

        # checks if local host
        if Post.objects.filter(id=post_id).exists():
            # checks visibility of the post
            if not check_get_perm(
                    request,
                    Post.objects.get(id=post_id).to_api_object()):
                return JsonResponse(
                    {
                        "query": "addComment",
                        "success": False,
                        "message": "Comment not allowed"
                    },
                    status=403)

        # change body = request.POST to body = request.body.decode('utf-8'),
        # because request.POST only accepts form, but here is json format.
        # change new_comment.comment to new_comment.content,
        # because that's how it defined in comment model.
        try:
            body = request.body.decode('utf-8')
            comment_info = loads(body)
            comment_info = comment_info['comment']
            new_comment = Comment()
            new_comment.contentType = comment_info['contentType']
            new_comment.content = comment_info['comment']
            new_comment.published = comment_info['published']
            new_comment.author = url_regex.sub(
                '', comment_info['author']['id']).rstrip("/")
            new_comment.parentPost = Post.objects.filter(id=post_id).first()
            new_comment.save()
            output['success'] = True
            output['message'] = "Comment added"
        except Exception as e:
            output['success'] = False
            output['message'] = "Comment not allowed"
            output['error'] = str(e)
        finally:
            if output["success"]:
                return JsonResponse(output, status=200)
            else:
                return JsonResponse(output, status=403)
Esempio n. 11
0
def replyCreate_view(request):
    if request.method == "POST":
        parent_obj = None
        try:
            account = Account.objects.get(user=request.user)
            parent_id = int(request.POST.get('parent_id'))
            content = request.POST.get('reply')
            post = Post.objects.get(slug=request.POST.get('post_slug'))
        except:
            parent_id = None

        if parent_id:
            parent_obj = Comment.objects.get(id=parent_id)
            if parent_obj:
                reply_comment = Comment()
                reply_comment.account = account
                reply_comment.post = post
                reply_comment.content = content
                reply_comment.parent = parent_obj
                reply_comment.save()
                post.comments += 1
                post.save()
                # notify to the comment owner
                if parent_obj.account != reply_comment.account:
                    content = reply_comment.account.user.first_name + ' ' + reply_comment.account.user.last_name + ' replied to your comment "' + reply_comment.content[:
                                                                                                                                                                        20] + '"'
                    notf = Notification()
                    notf.account = parent_obj.account
                    notf.post = post
                    notf.content = content
                    notf.save()

                # notify others who also replied to the comment avoiding repeatation...
                marked = []
                replies = parent_obj.replies.all()
                for replied in replies:
                    if replied.account.user.email not in marked:
                        if reply_comment.account != replied.account and parent_obj.account != replied.account:  # don't notify the replier him/her-self
                            content = reply_comment.account.user.first_name + ' ' + reply_comment.account.user.last_name + ' also replied on ' + parent_obj.account.user.first_name + "'s comment " + '"' + reply_comment.content[:
                                                                                                                                                                                                                                  20] + '"'
                            notf = Notification()
                            notf.account = replied.account
                            notf.post = post
                            notf.content = content
                            notf.save()
                            marked.append(replied.account.user.email)
        return HttpResponseRedirect(post.get_absolute_url)
    return HttpResponseRedirect('/posts/')
Esempio n. 12
0
def submit_comment(request):

    if request.method == 'POST':

        comment_title = request.POST.get('comment_title')
        comment_content = request.POST.get('comment_content')
        post_id = request.POST.get('post_id')
        current_user = request.user
        profile = UserProfileInfo.objects.get(user=current_user)

        c = Comment()
        c.post = Post.objects.get(id=post_id)
        c.content = comment_content
        c.author = UserProfileInfo.objects.get(id=profile.id)
        c.published_date = datetime.now()
        c.save()

    return HttpResponseRedirect(reverse('blog:post_details', args=(post_id, )))
Esempio n. 13
0
def create_view(request):
    if request.method == "POST":
        try:
            post = Post.objects.get(slug=request.POST.get('slug'))
            account = Account.objects.get(user=request.user)
            content = request.POST.get('comment')
        except:
            return HttpResponseRedirect('/posts/')
        comment = Comment()
        comment.account = account
        comment.post = post
        comment.content = content
        comment.save()
        post.comments += 1
        post.save()

        # notify the owner of the post
        if post.account != comment.account:
            notf = Notification()
            notf.account = post.account
            notf.post = post
            content = comment.account.user.first_name + ' ' + comment.account.user.last_name + ' commented on your post "' + comment.content[:
                                                                                                                                             20] + '"'
            notf.content = content
            notf.save()
        commented_all = Comment.objects.all().filter(post=post)
        marked = []
        # notify others who also commented
        for commented in commented_all:
            if commented.account.user.email not in marked:
                if comment.account != post.account and comment.account != commented.account and commented.account != post.account:
                    notf = Notification()
                    notf.account = commented.account
                    notf.post = post
                    content = comment.account.user.first_name + ' ' + comment.account.user.last_name + ' also commented ' + post.account.user.first_name + "'s post " + '"' + comment.content[:
                                                                                                                                                                                              20] + '"'
                    notf.content = content
                    notf.save()
                    marked.append(commented.account.user.email)
        return HttpResponseRedirect(post.get_absolute_url)
    return HttpResponseRedirect('/posts/')
Esempio n. 14
0
def comment_add(request, type, id):
    if request.method == 'POST':
        if 'content' in request.POST:
            comment = Comment(parent=id,
                              parent_type=type,
                              member=request.user.members)
            comment.content = request.POST['content']
            comment.save()
            instance = COMMENTS_MAP[type].objects.get(pk__exact=id)
            instance.comments_number = instance.comments_number + 1
            instance.save()
            template_dict = {
                'member': request.user.members,
                'comment': comment,
                'instance': instance,
            }
            return render_to_response(
                'user_pages/ajax_delivery/comment_single.html',
                template_dict,
                context_instance=RequestContext(request))
    return HttpResponse(0)
Esempio n. 15
0
 def post(self, request, id):
     cf = CommentForm(request.POST)
     if cf.is_valid():
         article = get_object_or_404(Article, pk=id)
         username = cf.cleaned_data['name']
         # email=cf.changed_data['email']
         email = request.POST.get('email')
         url = request.POST.get('url')
         # url=cf.changed_data['url']
         # comment=cf.changed_data['comment']
         comment = request.POST.get('comment')
         c = Comment()
         c.username = username
         c.url = url
         c.article = article
         c.email = email
         c.content = comment
         c.save()
         return redirect(reverse('article:detail', args=(id, )))
     else:
         return redirect(reverse('article:detail', args=(id, )))
Esempio n. 16
0
    def post(self, req, id):
        # cf =CommentForm(req.POST)
        # if cf.is_valid():
        #     cf.save(commit=False)
        #     article = get_object_or_404(Article,pk=id)
        #     cf.article = article
        #     cf.save()
        #     return HttpResponse("评论成功")
        name = req.POST.get("name")
        url = req.POST.get("url")
        eamil = req.POST.get("email")
        content = req.POST.get("content")

        comment = Comment()
        comment.name = name
        comment.url = url
        comment.email = eamil
        comment.content = content
        comment.article = get_object_or_404(Article, pk=id)

        comment.save()
        return redirect(reverse("blog:single", args=(id, )))