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


Python Comment.parent方法代码示例

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


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

示例1: generate_comments

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import parent [as 别名]
def generate_comments(n=NUMBER_OF_COMMENTS):
    c = Comment(content=CONTENT[0])
    c.save()
    c.path = str(c.id)
    c.save()
    result = [c]
    for i in xrange(1, n):
        #  choice - decides whether to add new comment with depth = 0 or reply to another comment
        choice = randint(0, 1)
        content_choice = randint(0, len(CONTENT) - 1)
        lb = round(random(), 2)
        #  some of the comments should be hidden
        c = Comment(_lower_bound=lb, visible=random() > 0.2, content=CONTENT[content_choice])
        if choice == 0:
            idx = randint(0, len(result) - 1)
            c.depth = result[idx].depth + 1
            c.parent = result[idx].id
            c.save()
            c.path = result[idx].path + ' ' + str(c.id)
            c.save()
        else:
            c.depth = 0
            c.save()
            c.path = str(c.id)
            c.save()
        result.append(c)
开发者ID:zofy,项目名称:CommentingSystem,代码行数:28,代码来源:comment_generator.py

示例2: add

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import parent [as 别名]
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)
开发者ID:hungrygeek,项目名称:django_python,代码行数:57,代码来源:views.py

示例3: test_generate_comments

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import parent [as 别名]
 def test_generate_comments(self):
     c = Comment(depth=0, _lower_bound=0)
     c.path = '0'
     c.save()
     result = [c]
     for i in xrange(1, 1000):
         ch = randint(0, 1)
         lb = round(random(), 2)
         c = Comment(_lower_bound=lb, visible=random() > 0.2)
         if ch > 0.35:
             idx = randint(0, len(result) - 1)
             c.path = result[idx].path + ' ' + str(i)
             c.depth = result[idx].depth + 1
             c.parent = result[idx].id
             c.save()
         else:
             c.depth = 0
             c.path = str(i)
             c.save()
         result.append(c)
开发者ID:zofy,项目名称:CommentingSystem,代码行数:22,代码来源:tests.py


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