コード例 #1
0
ファイル: base.py プロジェクト: jfojfo/foblog
def new_comment(postid, content, author, nick, site, ip):
    post = Post.get_by_id(int(postid))

    try:
        comment = Comment(post = post, content = content, author = author, ip = ip)
        comment.put()
        post.comment_count += 1
        post.put()
        change_user_info(author, nick, site)
        memcache.notify_update('comment')

        if config.comment_notify_email:
            try:
                msg = mail.EmailMessage(
                        sender = post.author.email(),
                        subject = (u'New Comment From %s(%s)' % (nick, self.login_user.email())).encode('utf-8')
                        )
                msg.to = post.author.email()
                msg.body = (u'Comment on [%s] by %s(%s) at %s:\n %s\n\n%s'
                        % (post.title, nick, self.login_user.email(), datetime.datetime.utcnow(), content,
                        config.default_host + '%s/post/' % settings.app_root + str(post.key().id()))).encode('utf-8')
                msg.send()
            except Exception, e:
                logging.error(e)

    except db.BadValueError, e:
        raise
コード例 #2
0
ファイル: base.py プロジェクト: jfojfo/foblog
def edit_article(postid, title = None, content = None, author = users.get_current_user(), tags = None, date = None, filter = default_filter, slug = None, type = 'post', pub_type = 'public'):
    if filter:
        content = filter(content)

    post = Post.get_by_id(int(postid))
    if title:
        post.title = title
    if content:
        post.content = content
    if author:
        post.last_modify_by = author
    if date:
        post.last_modify_date = date
    if tags != None:
        old_tags = post.tags
        post.tags = tags
    if slug:
        post.slug = slug
    
    post.type = type
    post.pub_type = pub_type

    post.put()

    if type == 'post' and tags != None:
        update_tag_count(old_tags = old_tags, new_tags = tags)

    memcache.notify_update('post')
コード例 #3
0
ファイル: base.py プロジェクト: srijib/gae
def new_article(title, content, author = users.get_current_user(), tags = [], date = None, filter = default_filter, slug = None, type = 'post'):
	if filter:
		content = filter(content)

	if date == None:
		post = Post(
				title = title,
				content = content,
				author = author,
				tags = tags,
				type = type,
				slug = slug
				)
	else:
		post = Post(
				title = title,
				content = content,
				author = author,
				tags = tags,
				date = date,
				type = type,
				slug = slug
				)
	key = post.put()

	if type == 'post':
		update_tag_count(old_tags = [], new_tags = tags)

	all_post_tag = Tag.get_by_key_name('all_post_tag')
	all_post_tag.count += 1
	all_post_tag.put()

	memcache.notify_update('post')
	return key.id()
コード例 #4
0
ファイル: base.py プロジェクト: jfojfo/foblog
def delete_comment(commentid, user, is_admin):
    comment = Comment.get_by_id(int(commentid))
    if is_admin or user == commentid.author:
        postid = comment.post.key().id()
        comment.post.comment_count -= 1
        comment.post.put()
        comment.delete()
        memcache.notify_update('comment')
        return postid
    else:
        return 0
コード例 #5
0
ファイル: base.py プロジェクト: jfojfo/foblog
def delete_post(postid):
    # TODO we may need a logical delete here
    post = Post.get_by_id(int(postid))
    if not post : return

    comments = Comment.all().filter('post = ', post)
    for comment in comments:
        comment.delete()

    old_tags = post.tags
    type = post.type
    post.delete()

    if type == 'post':
        update_tag_count(old_tags = old_tags, new_tags = [])

    all_post_tag = Tag.get_by_key_name('all_post_tag')
    all_post_tag.count -= 1
    all_post_tag.put()

    memcache.notify_update('post')