当前位置: 首页>>代码示例>>Python>>正文


Python Comment.text方法代码示例

本文整理汇总了Python中models.Comment.text方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.text方法的具体用法?Python Comment.text怎么用?Python Comment.text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Comment的用法示例。


在下文中一共展示了Comment.text方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: article

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
def article(request, post_id, post_name):
    post = Post.posts.get_visible_post(post_id)

    if not post:
        raise Http404

    if request.method == "POST":
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment = Comment()
            comment.author = comment_form.cleaned_data['author']
            comment.post = post
            comment.email = comment_form.cleaned_data['email']
            comment.text = comment_form.cleaned_data['text']
            comment.save()
            return HttpResponseRedirect("/")
        else:
            # TODO SHOW ERRORS
            pass

    spotlighted = Project.objects.filter(related_posts=post)
    comments = Comment.objects.filter(post=post)
    related = TaggedItem.objects.get_related(post, Post)[:6]
    comment_form = CommentForm()

    return render_to_response('article.html',
            {
                "post": post,
                "comments": comments,
                "related": related,
                "spotlighted": spotlighted,
                "comment_form": comment_form
            },
            context_instance=RequestContext(request))
开发者ID:MightyPixel,项目名称:MightyBlog,代码行数:36,代码来源:views.py

示例2: sp

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
def sp(request, id='1'):
    if request.method == "POST":
        text = request.POST['text']
        user = User.objects.get(username=request.user)
        nn = get_object_or_404(News, id=id)
        nc = Comment()
        nc.owner = user
        nc.text = text
        nc.news = nn
        nc.save()
        return redirect(request.path)
    from_date = datetime.datetime.now() - datetime.timedelta(days=2)
    l2dn = News.objects.all().order_by('-date').filter(date__range=[from_date, datetime.datetime.now()])
    ln = News.objects.all()[:5]
    ct = City.objects.all()
    n = get_object_or_404(News, id=id)
    c = Categoryitem.objects.select_related().filter(parent=None)
    com = Comment.objects.select_related().filter(news=n, parent=None)
    context = {'news': n,
               'cats': c,
               'citys': ct,
               'comments': com,
               'lnews': ln,
               'last_news': l2dn}
    return render(request, 'news/sp.html', context)
开发者ID:TorinAsakura,项目名称:gk,代码行数:27,代码来源:views.py

示例3: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
  def post(self, forum_id, post_reference):
    user = self.user_model
    post = ForumPost.query(ForumPost.forum_name == forum_id, ForumPost.reference == post_reference).get()
    text = cgi.escape(self.request.get('text'))
    sender = cgi.escape(self.request.get('sender'))
    recipient = cgi.escape(self.request.get('recipient'))
    replied_to_urlsafe = cgi.escape(self.request.get('parent'))
    comment = Comment(parent = post.key)
    if len(replied_to_urlsafe) != 0:
      replied_to_key = ndb.Key(urlsafe=replied_to_urlsafe)
      parent_comment = replied_to_key.get()
      comment.parent = replied_to_key
      comment.offset = parent_comment.offset + 20
      recipient_comment = ndb.Key(urlsafe=replied_to_urlsafe).get()
      comment.recipient = recipient_comment.sender
      comment.sender = user.username
      comment.root = False
    else:
      comment.sender = sender
      comment.recipient = recipient

    comment.text = text
    comment.time = datetime.datetime.now() - datetime.timedelta(hours=7) #For PST
    comment.put()

    if comment.root == False:
      parent_comment.children.append(comment.key)
      parent_comment.put()
      
    post.comment_count += 1
    post.put()
    self.redirect('/tech/{}/{}'.format(forum_id, post_reference))
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:34,代码来源:Forum.py

示例4: addToDatabase

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
def addToDatabase(parent, subtree, i):

    subComments = subtree["data"]["children"]
    if len(subComments) == 0:
        pass
        # print "List EMPTY"
    w = 0
    for j in subComments:
        comment = Comment()
        comment.reddit_id = j["data"]["id"]
        comment.text = j["data"]["body"]
        comment.user_name = j["data"]["author"]
        comment.upvotes = int(j["data"]["ups"])
        comment.downvotes = j["data"]["downs"]
        comment.date_of_last_sweep = datetime.now()
        comment.parent = parent
        comment.post_id = parent.post_id
        session.add(comment)
        if j["data"]["replies"] == "":
            comment.weight = comment.upvotes
            # print "Dict Empty"
            # print type(j["data"]["replies"])

        else:
            addToDatabase(comment, j["data"]["replies"], i + 1)
            comment.weight = comment.weight + comment.upvotes
        w = comment.weight + w
    parent.weight = w

    """
开发者ID:NSkelsey,项目名称:reddit_sweep,代码行数:32,代码来源:comments.py

示例5: test_comment_crud_methods

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
    def test_comment_crud_methods(self):
        text = 'Test message'
        user = UserFactory.create(remote_id=TRAVIS_USER_ID)
        post = PostFactory.create(remote_id=TR_POST_ID, wall_owner=user)
        mock_comment = CommentFactory.create(text=text, post=post, wall_owner=user)

        # Create
        comment = Comment.objects.create(
                **CommentFactory.get_mock_params_dict(
                    mock_comment, commit_remote=True)
        )

        self.assertTrue(comment.remote_id > 0)
        self.assertEqual(comment.text, text)

        fetched_comment = post.fetch_comments(sort='asc').first()
        self.assertEqual(fetched_comment.text, text)

        # Update
        edited_message = 'Edited comment message'
        comment = Comment.objects.get(id=comment.id)
        comment.text = edited_message
        comment.save(commit_remote=True)

        self.assertEqual(comment.text, edited_message)

        fetched_comment = post.fetch_comments(sort='asc').first()
        self.assertEqual(fetched_comment.text, edited_message)

        # Delete
        comment.delete()
        comment1 = Comment.objects.get(id=comment.id)
        self.assertTrue(comment1.archived)

        fetched_ids = [comment.remote_id for comment in post.fetch_comments()]
        self.assertFalse(comment1.remote_id in fetched_ids)

        # Restore
        comment.restore()
        comment1 = Comment.objects.get(id=comment.id)
        self.assertFalse(comment1.archived)

        fetched_ids = [comment.remote_id for comment in post.fetch_comments()]
        self.assertTrue(comment1.remote_id in fetched_ids)

        # Create with save()
        comment = Comment()
        comment.__dict__.update(
            CommentFactory.get_mock_params_dict(mock_comment)
        )
        comment.text = text + text
        comment.save(commit_remote=True)

        self.assertTrue(comment.remote_id > 0)
        self.assertEqual(comment.text, text + text)

        fetched_comment = post.fetch_comments(sort='asc').first()
        self.assertEqual(fetched_comment.text, text + text)

        comment.delete()
开发者ID:rkmarvin,项目名称:django-vkontakte-wall,代码行数:62,代码来源:tests.py

示例6: new_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
def new_comment(request,idnum):
	try:
		post = request.POST
		sentiment = post["sentiment"]	
		title = post["comment_title"]
		text = post["comment_text"]
		all = post["images"]
		images = map(int,post["images"].split("_")) if all else []
		venue = Venue.objects.get(id=idnum)
		if sentiment and title and text:
			comment = Comment()
			comment.set_sentiment_by_index(int(sentiment))
			comment.title = title
			comment.text = text
			comment.venue = venue
			comment.user = request.user
			comment.save()
			for id in images:
				image = VenueImage.objects.get(id=id)
				image.comment = comment
				image.save()
		else:
			raise Exception("invalid post content")
	except Exception, e:
		pass
开发者ID:michaelgiba,项目名称:JustOpenedDjango,代码行数:27,代码来源:views.py

示例7: parse_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
    def parse_comment(self, content, wall_owner=None):
        from models import Comment

        remote_id = content['id'][4:]
        try:
            instance = Comment.objects.get(remote_id=remote_id)
        except Comment.DoesNotExist:
            instance = Comment(remote_id=remote_id)

        comment_text = content.find('div', {'class': 'fw_reply_text'})
        if comment_text:
            instance.text = comment_text.text

        # date
        instance.date = self.parse_container_date(content)
        # likes
        instance.likes = self.parse_container_likes(content, 'like_count fl_l')

        # author
        users = content.findAll('a', {'class': 'fw_reply_author'})
        slug = users[0]['href'][1:]
        if wall_owner and wall_owner.screen_name == slug:
            instance.author = wall_owner
        else:
            avatar = content.find('a', {'class': 'fw_reply_thumb'}).find('img')['src']
            name_parts = users[0].text.split(' ')

            user = get_object_by_slug(slug)
            if user:
                user.first_name = name_parts[0]
                if len(name_parts) > 1:
                    user.last_name = name_parts[1]
                user.photo = avatar
                user.save()
                instance.author = user

        if len(users) == 2:
            # this comment is answer
            slug = users[1]['href'][1:]
            if wall_owner and wall_owner.screen_name == slug:
                instance.reply_for = wall_owner
            else:
                instance.reply_for = get_object_by_slug(slug)
                # имя в падеже, аватара нет
                # чтобы получть текст и ID родительского коммента нужно отправить:
                #http://vk.com/al_wall.php
                #act:post_tt
                #al:1
                #post:-16297716_126263
                #reply:1

        instance.fetched = datetime.now()

        comment_parsed.send(sender=Comment, instance=instance, raw_html=str(content))
        return instance
开发者ID:akropotov,项目名称:django-vkontakte-wall,代码行数:57,代码来源:parser.py

示例8: do_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
def do_comment(request, post, attrs, all_comments=None):
    # make sure the form came through correctly
    if not ("name" in attrs and "text" in attrs and "email" in attrs and "lastname" in attrs):
        return False
    # 'lastname' is a honeypot field
    if not attrs["lastname"] == "":
        return False
    # keyword parameter is for prefetching
    if all_comments is None:
        all_comments = list(post.comments.all())
    else:
        all_comments = all_comments[:]  # copy so we don't mutate later
    ### create a new comment record
    comment = Comment()
    comment.post = post
    comment.name = attrs["name"].strip()
    if len(comment.name) == 0:
        comment.name = "Anonymous"
    comment.text = attrs["text"]
    comment.email = attrs["email"]
    ### check for spam (requires a web request to Akismet)
    is_spam = akismet_check(request, comment)
    if is_spam:
        return False  # don't even save spam comments
    comment.spam = False

    ### set the comment's parent if necessary
    if "parent" in attrs and attrs["parent"] != "":
        comment.parent_id = int(attrs["parent"])

    if isLegitEmail(comment.email):
        comment.subscribed = attrs.get("subscribed", False)
    else:
        comment.subscribed = False
        # make sure comments under the same name have a consistent gravatar
        comment.email = hashlib.sha1(comment.name.encode("utf-8")).hexdigest()
    comment.save()
    all_comments.append(comment)
    ### send out notification emails
    emails = {}
    for c in all_comments:
        if c.subscribed and c.email != comment.email and isLegitEmail(c.email):
            emails[c.email] = c.name
    for name, email in settings.MANAGERS:
        emails[email] = name
    template = get_template("comment_email.html")
    subject = "Someone replied to your comment"
    for email, name in emails.iteritems():
        text = template.render(Context({"comment": comment, "email": email, "name": name}))
        msg = EmailMessage(subject, text, "[email protected]", [email])
        msg.content_subtype = "html"
        msg.send()
    return True
开发者ID:benkuhn,项目名称:benkuhn.net,代码行数:55,代码来源:views.py

示例9: test_comment_crud_methods

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
    def test_comment_crud_methods(self):
        group = GroupFactory(remote_id=GROUP_CRUD_ID)
        post = PostFactory(remote_id=POST_CRUD_ID, text='', wall_owner=group)
        user = UserFactory(remote_id=USER_AUTHOR_ID)

        def assert_local_equal_to_remote(comment):
            comment_remote = Comment.remote.fetch_post(post=comment.post).get(remote_id=comment.remote_id)
            self.assertEqual(comment_remote.remote_id, comment.remote_id)
            self.assertEqual(comment_remote.text, comment.text)

        Comment.remote.fetch_post(post=post)
        self.assertEqual(Comment.objects.count(), 0)

        # create
        comment = Comment(text='Test comment', post=post, wall_owner=group, author=user, date=datetime.now())
        comment.save(commit_remote=True)
        self.objects_to_delete += [comment]

        self.assertEqual(Comment.objects.count(), 1)
        self.assertNotEqual(len(comment.remote_id), 0)
        assert_local_equal_to_remote(comment)

        # create by manager
        comment = Comment.objects.create(text='Test comment created by manager', post=post, wall_owner=group, author=user, date=datetime.now(), commit_remote=True)
        self.objects_to_delete += [comment]

        self.assertEqual(Comment.objects.count(), 2)
        self.assertNotEqual(len(comment.remote_id), 0)
        assert_local_equal_to_remote(comment)

        # update
        comment.text = 'Test comment updated'
        comment.save(commit_remote=True)

        self.assertEqual(Comment.objects.count(), 2)
        assert_local_equal_to_remote(comment)

        # delete
        comment.delete(commit_remote=True)

        self.assertEqual(Comment.objects.count(), 2)
        self.assertTrue(comment.archived)
        self.assertEqual(Comment.remote.fetch_post(post=comment.post).filter(remote_id=comment.remote_id).count(), 0)

        # restore
        comment.restore(commit_remote=True)
        self.assertFalse(comment.archived)

        self.assertEqual(Comment.objects.count(), 2)
        assert_local_equal_to_remote(comment)
开发者ID:Core2Duo,项目名称:django-vkontakte-wall,代码行数:52,代码来源:tests.py

示例10: addcomment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
def addcomment(request):
    if request.method == "POST":
        news = News.objects.get(id=request.POST['news'])
        text = request.POST['text']
        user = User.objects.get(username=request.user)
        c = Comment()
        c.news = news
        c.owner = user
        c.text = text
        if request.POST['pid'] != 'false':
            pid = request.POST['pid']
            c.parent = Comment.objects.get(id=pid)
        c.save()
        return HttpResponse(c.id)
开发者ID:TorinAsakura,项目名称:gk,代码行数:16,代码来源:views.py

示例11: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
    def post(self, album_id):
        user = get_user()

        if user:
            album = Album.get_by_id(
                int(album_id),
                parent=DEFAULT_DOMAIN_KEY
            )

            comment = Comment(parent=album.key)
            comment.text = self.request.get('comment_text')
            comment.author = user.key
            comment.parent = album.key

            comment.put()

            self.redirect('/album/%s/view' % album.key.integer_id())
        else:
            self.redirect_to_login()
开发者ID:MichaelAquilina,项目名称:Photo-Nebula,代码行数:21,代码来源:views.py

示例12: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import text [as 别名]
  def post(self):
    origin = cgi.escape(self.request.get('origin'))
    text = cgi.escape(self.request.get('text'))
    sender = cgi.escape(self.request.get('sender'))
    recipient = cgi.escape(self.request.get('recipient'))
    replied_to_urlsafe = cgi.escape(self.request.get('parent'))
    viewer = self.user_model
    comment = Comment()
    if len(replied_to_urlsafe) != 0:
      replied_to_key = ndb.Key(urlsafe=replied_to_urlsafe)
      parent_comment = replied_to_key.get() #parent comment
      comment.parent = replied_to_key
      comment.offset = parent_comment.offset + 20
      recipient_comment = ndb.Key(urlsafe=replied_to_urlsafe).get()
      comment.recipient = recipient_comment.sender
      comment.sender = viewer.username
      comment.root = False
    else:
      comment.sender = sender
      comment.recipient = recipient

    # Not double adding User Keys
    if sender != recipient:
      comment.sender_key = User.query(User.username == sender).get().key
      comment.recipient_key = User.query(User.username== recipient).get().key
    else:
      comment.sender_key = User.query(User.username == sender).get().key
      comment.recipient_key = None
    comment.text = text
    comment.time = datetime.datetime.now() - datetime.timedelta(hours=8) #For PST
    comment.put()
    
    if comment.root == False:
      parent_comment.children.append(comment.key)
      parent_comment.put()

    self.redirect('/profile/{}'.format(recipient))
开发者ID:nikko0327,项目名称:Ninja-Tutor,代码行数:39,代码来源:Feed.py


注:本文中的models.Comment.text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。