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


Python Comment.submit_date方法代码示例

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


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

示例1: create_comment

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import submit_date [as 别名]
def create_comment(oldcomment):
    current_site = Site.objects.get(id=settings.SITE_ID)
    content_type = ContentType.objects.get(app_label='blog', model='post')
    fields = oldcomment['fields']
    comment = Comment()
    comment.comment  = fields['comment']
    comment.ip_address  = fields['ip_address']
    comment.is_public  = fields['is_public']
    comment.is_removed  = fields['is_removed']
    comment.object_pk  = fields['object_pk']
    comment.submit_date  = fields['submit_date']
    comment.user  = None
    comment.user_email  = fields['user_email']
    comment.user_name  = fields['user_name']
    comment.user_url  = fields['user_url']
    comment.content_type  = content_type
    comment.site  = current_site
    comment.save()
开发者ID:miniatureape,项目名称:justindonato.com,代码行数:20,代码来源:transfer.py

示例2: process_comment

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import submit_date [as 别名]
def process_comment(request, commentform, post):
    try:
        comment = Comment.objects.get(id=commentform.cleaned_data.get('id', None))
    except Comment.DoesNotExist:
        comment = Comment()
    comment.content_object = post
    comment.site = Site.objects.get_current()
    comment.user = request.user
    try:
        profile = UserProfile.objects.get(user = request.user)
        comment.user_url = profile.get_absolute_url()
    except UserProfile.DoesNotExist:
        pass
    comment.comment = strip_tags(commentform.cleaned_data['comment'])
    comment.submit_date = datetime.datetime.now()
    comment.ip_address = request.META['REMOTE_ADDR']
    comment.is_public = True
    comment.is_removed = False
    comment.save()
    return comment
开发者ID:calvin,项目名称:seabirds.net,代码行数:22,代码来源:views.py

示例3: handle

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import submit_date [as 别名]

#.........这里部分代码省略.........
            # Unpublished posts will not have anything in their name tag (which
            # is used to hold the slug), so we have to create the slug from the
            # title.
            if slug is None:
                slug = slugify(item.find('title').text)

            print 'Importing post "%s"...' % slug

            # If the post is already in the database, get it. Otherwise create
            # it.
            try:
                post = Post.objects.get(slug=slug)
            except:
                post = Post()
                post.title = item.find('title').text
                post.slug = slug
                post.body = item.find('{http://purl.org/rss/1.0/modules/content/}encoded').text
                post.created = item.find('{%s}post_date' % wp).text

                # If the post was published, set its status to public.
                # Otherwise make it a draft.
                if item.find('{%s}status' % wp).text == 'publish':
                    post.status = 2
                else:
                    post.status = 1
                    # Unpublished posts will not have a timestamp associated
                    # with them. We'll set the creation date to now.
                    post.created = datetime.now()

                # Set publish time to the creation time.
                post.publish = post.created

                # If the excerpt flag was set, do some auto excerpting magic.
                if options['excerpt']:
                    # Partition the string at the Wordpress more quicktag.
                    partition = post.body.partition('<!--more-->')

                    # If the `more` tag was not found, Python will have
                    # returned a tuple with the full post body in the first
                    # item followed by two empty items. To make sure that the
                    # excerpt is only set if the post does actually contain a
                    # `morie` quicktag, we'll check to see if the third tuple
                    # item is an empty string.
                    if partition[2]:
                        post.tease = partition[0]

                # Post must be saved before we apply tags or comments.
                post.save()

            # Get all tags and categories. They look like this, respectively:
            # <category domain="post_tag" nicename="a tag">a tag</category>
            # <category domain="category" nicename="general">general</category>
            descriptors = item.findall('category')
            categories = []
            for descriptor in descriptors:
                if descriptor.attrib['domain'] == 'post_tag':
                    # Add the tag to the post
                    post.tags.add(descriptor.text)
                if descriptor.attrib['domain'] == 'category':
                    category = descriptor.text
                    # If the category exists, add it to the model. Otherwise,
                    # create the category, then add it.
                    try:
                        cat = Category.objects.get(slug=slugify(category))
                    except:
                        cat = Category(title=category, slug=slugify(category))
                        cat.save()
                    post.categories.add(cat)

            # Save the post again, this time with tags and categories.
            post.save()

            # Get and save the comments.
            comments = item.findall('{%s}comment' % (wp))
            for comment in comments:
                # When I was importing my posts, I stumbled upon a comment that
                # somehow had no author email associated with it. If that is
                # the case, don't bother importing the comment.
                email = comment.find('{%s}comment_author_email' % (wp)).text
                if email is None:
                    continue

                c = Comment()
                c.user_name = comment.find('{%s}comment_author' % wp).text
                c.user_email = comment.find('{%s}comment_author_email'
                                            % wp).text
                c.comment = comment.find('{%s}comment_content' % wp).text
                c.submit_date = comment.find('{%s}comment_date' % wp).text
                c.content_type = ContentType.objects.get(app_label='blog',
                                                         model='post')
                c.object_pk = post.id
                c.site_id = Site.objects.get_current().id

                # Only attempt to assign a user URL to the new comment if the
                # old comment has one.
                user_url = comment.find('{%s}comment_author_url' % wp).text
                if user_url:
                    c.user_url = user_url

                c.save()
开发者ID:AndreMiras,项目名称:django-vellum,代码行数:104,代码来源:wordpress_import.py


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