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


Python Comment.name方法代码示例

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


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

示例1: do_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import name [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

示例2: post

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import name [as 别名]
def post(request, id):
	posts = Post.objects.all()
	post = Post.objects.get(id=id)
	comments = Comment.objects.filter(post = post, approved = True)
	
	teve_comentario = False
	if request.method == 'POST':
		teve_comentario = True
		comment = Comment()
		comment.post = post
		comment.name = request.POST['nome']
		comment.email = request.POST['email']
		comment.comment = request.POST['comentario']
		comment.save()
		
	return render(request, 'blog/post.html', locals())
开发者ID:bobeirasa,项目名称:sitedecompras,代码行数:18,代码来源:views.py

示例3: save_comment

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import name [as 别名]
def save_comment():
	msg = "Comment not saved."
	try:
		nome = request.form['name']
		email = request.form['email']
		texto = request.form['content']
		post_id = request.form['post_id']
		comentario = Comment()
		comentario.name = nome
		comentario.email = email
		comentario.content = texto
		comentario.display = False
		comentario.date_created = datetime.today()
		comentario.post_id = post_id
		db.session.add(comentario)
		db.session.commit()
		msg = "Comentário enviado! Obrigado!"
	except:
		db.session.rollback()
		traceback.print_exc()
		#raise
	data = {}
	data['message'] = msg
	return jsonify(data)
开发者ID:berlotto,项目名称:asciiblog,代码行数:26,代码来源:__init__.py

示例4: _process_comments

# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import name [as 别名]
    def _process_comments(self, url, next_newest_id, data, after):
        """Threaded comment parser"""
        
        comments = data['data']['children']
        new_comments = 0
        pages_parsed = 0
        
        for i, c in enumerate(comments):
            comment = c['data']

            if comment['id'] <= next_newest_id: # comments ids are generated sequentially
                # so we can safely compare them like this without having to cache a timestamp
                # and without risking problems if a comment is deleted
                self.logger.debug("%s: comment['id'] <= next_newest_id" % current_process().name)
                break
            
            # Create new Comment, stick in it in the database.
            # I feel like we should be able to loop through the JSON object and avoid writing out all these assignments
            # Would that even be a good idea?
            comment_entry = Comment()
            comment_entry.subreddit_id           = comment['subreddit_id']
            comment_entry.link_title             = comment['link_title']
            comment_entry.subreddit              = comment['subreddit']
            comment_entry.link_author            = comment['link_author']
            comment_entry.id                     = comment['id']
            comment_entry.gilded                 = comment['gilded']
            comment_entry.author                 = comment['author']
            comment_entry.parent_id              = comment['parent_id']
            comment_entry.body                   = comment['body']
            comment_entry.edited                 = comment['edited']
            comment_entry.author_flair_css_class = comment['author_flair_css_class']
            comment_entry.downs                  = comment['downs']
            comment_entry.body_html              = comment['body_html']
            comment_entry.link_id                = comment['link_id']
            comment_entry.score_hidden           = comment['score_hidden']
            comment_entry.name                   = comment['name']
            comment_entry.created                = datetime.fromtimestamp(comment['created'])
            comment_entry.author_flair_text      = comment['author_flair_text']
            comment_entry.created_utc            = datetime.fromtimestamp(comment['created_utc'])
            comment_entry.ups                    = comment['ups']
            comment_entry.distinguished          = comment['distinguished']
            
            # Append to current session. We'll commit at the end.
            session.add(comment_entry)

            # update our counter
            # For informational purposes. Maybe I'll have it propagate a log in the database,
            #  that would make it really easy to graph comment rate over time           
            new_comments = new_comments + 1
        else:
            # we didn't break out of the loop, therefore we never encountered next_newest_id
            # so, get the next page and keep going
            data, newest_id, after = self._parse_json(url, after)
            
            if pages_parsed <= 3:
                # we should never have to go back further than two additional pages
                # if we have, something is probably wrong            
                self.logger.debug("Getting a second page.")
                pages_parsed = pages_parsed + 1
                self._process_comments(url, next_newest_id, data, after)
            else:
                self.logger.debug("Attempted to parse more than three pages.")

        # Push new objects to database
        session.commit()
        
        self.logger.debug( "%s: %s %s" % (current_process().name, datetime.now(), new_comments) )
开发者ID:Dakta,项目名称:reddit-scraper,代码行数:69,代码来源:scrape_comments.py


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