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


Python Comment.save方法代码示例

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


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

示例1: handle

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
    def handle(self, *args, **options):
        users = list(User.objects.all())

        for i in range(10):
            t = Topic()
            t.name = u'Topic Name {}'.format(i)
            t.description = u'Topic Description {}'.format(i)
            t.save()
        topics = list(Topic.objects.all())

        for j in range(100):
            q = Question()
            q.author = random.choice(users)
            q.title = u'title {}'.format(j)
            q.text = u'text {}'.format(j)
            q.pub_date = datetime.datetime.now()
            q.is_published = True
            q.save()
            q.topics = random.sample(topics, random.randint(1, 6))
        questions = list(Question.objects.all())

        for k in range(100):
            c = Comment()
            c.author = random.choice(users)
            c.question = random.choice(questions)
            c.text = u'text {}'.format(k)
            c.pub_date = datetime.datetime.now()
            c.save()
开发者ID:PhilSk,项目名称:src,代码行数:30,代码来源:data_filling.py

示例2: migrate_comments

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
    def migrate_comments(self):

        for legacy_comment in LegacyComment.objects.all():
            assert isinstance(legacy_comment, LegacyComment)

            date_naive = datetime.utcfromtimestamp(legacy_comment.timestamp)
            date = timezone.make_aware(date_naive, timezone.utc)

            comment = Comment()
            comment.body = legacy_comment.comment
            comment.created = date
            comment.public = not legacy_comment.officer

            comment.user_id = legacy_comment.poster_id  # this is erroring

            if legacy_comment.section == 0:
                continue
            if legacy_comment.section == 1:
                continue
            if legacy_comment.section == 2:
                continue
            if legacy_comment.section == 5:
                continue

            comment.content_type_id = {  # i dont know what the keys are for the different content types
                0: 1,  # user manager
                1: 2,  # application
                2: 3,  # fodder vote
                3: 4,  # quote
                4: 5,  # screenshot
                5: 6   # leadership application
            }.get(legacy_comment.section)

            comment.object_id = legacy_comment.reference
            comment.save()
开发者ID:pombredanne,项目名称:django-adt,代码行数:37,代码来源:migratecomments.py

示例3: create

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
    def create(self, validated_data):
        """
        Create and return a new 'Comment' instance, given the validated data
        This is like the form class's save method.
        
        Serializers have a save method, which will in turn invoke these 
        functions
        """
        print "CommentSerializer: In Create"
        comment = Comment()
        
        comment.author = validated_data.get('author', None)

        if comment.author is None:
            comment.author_name = validated_data.get('author_name', None)
            comment.author_email = validated_data.get('author_email', None)
            comment.author_url = validated_data.get('author_url', None)
            
            if comment.author_name is None and comment.author_email is None:
                return None 
        
        comment.body = validated_data.get('body')
        comment.post = validated_data.get('post')
        comment.published = False
        if comment.author is not None and settings.COMMENT_MODERATION_ENABLED is not True:
            comment.published = True
        elif comment.author is not None and comment.author.is_staff:
            comment.published = True 

        comment.save()
        return comment
开发者ID:aestheticblasphemy,项目名称:aestheticBlasphemy,代码行数:33,代码来源:serializers.py

示例4: update_comment

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
 def update_comment(self):
     """
     Creates the shadow comment object to hold this document's place in a
     commment thread, if this document is a reply to comments.
     """
     # Create comment objects only when the doc is public.  That way,
     # subscription signals are fired at the right moment -- the comment is
     # public and viewable.
     parent = None
     if self.in_reply_to:
         try:
             parent = self.in_reply_to.document
         except Document.DoesNotExist:
             pass
     if parent and self.is_public():
         # Only create a comment object if we are public.
         try:
             comment = self.comment
         except Comment.DoesNotExist:
             comment = Comment()
         comment.user = self.author
         comment.removed = False
         comment.document = parent
         comment.comment_doc = self
         comment.save()
     else:
         # If we've gone non-public, mark the comment removed rather
         # than deleting.  That way, we don't re-fire subscriptions if
         # the doc is only temporarily un-published.
         try:
             self.comment.removed = True
             self.comment.save()
         except Comment.DoesNotExist:
             pass
开发者ID:yourcelf,项目名称:btb,代码行数:36,代码来源:models.py

示例5: handle

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
    def handle(self, *args, **kwargs):
    	"""
        users = list(User.objects.all())
        for i in range(100):
            q = Event()
            q.author = random.choice(users)
            q.title = u'title {}'.format(i)
            q.text = u'text {}'.format(i)
            q.is_published = True
            q.save()

        print "completed"
        """
        users = list(User.objects.all())
        b = []
        p = []
        c = []
        for _ in range(10):
            b.append(Blog.objects.create())
        for i in range(100):
            t = Event(author=random.choice(users), title = u'title {}'.format(i),
                     text = u'text {}'.format(i), is_published = True,
                     blog=random.choice(b))
            p.append(t)
            t.save()
            Tag.objects.create(name='tag{}'.format(i))
            # TODO tags.add(tag)
        for i in range(1000):
            com = Comment(author = random.choice(users), event = random.choice(p),
                           text=u'text {}'.format(i))
            c.append(com)
            com.save()
        print "completed"
开发者ID:PotapovaSofia,项目名称:stackoverflow,代码行数:35,代码来源:db_fill.py

示例6: sync_comment

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
	def sync_comment(self):
		comments_map = {}
		root_header = None
		root_comment = None

		for comment in self.comments():
			dot()
			if root_header is None or root_header.object_id != comment.nid:
				root_comment = Comment.objects.get_or_create_root_comment(self.node_ctype, comment.nid)[0]
			update_comments_header(Comment, instance=root_comment)
			filters = self.formats_filtering.get(comment.format, self.formats_filtering[1])
			filtered_comment = self.call_filters(comment.comment, filters)
			time_created = timestamp_to_time(comment.timestamp)
			comment_instance = Comment(
				parent_id=comments_map[comment.pid] if comment.pid else root_comment.id,
				object_id=comment.nid,
				content_type=self.node_ctype,
				subject=comment.subject,
				created=time_created,
				updated=time_created,
				user_id=self.users_map.get(comment.uid),
				user_name=comment.name,
				is_public=True,
				is_locked=root_comment.is_locked,
				original_comment=TextVal(self.filter_formats.get(comment.format, 'raw') + ':' + comment.comment),
			)
			comment_instance.save()
			Comment.objects.filter(pk=comment_instance.pk).update(filtered_comment=filtered_comment)
			comments_map[comment.cid] = comment_instance.pk
开发者ID:LinuxOSsk,项目名称:Shakal-NG,代码行数:31,代码来源:import_blackhole.py

示例7: show

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
def show(request, id, slug='a'):
    recipe = get_object_or_404(Recipe, id=id)
    categories = Category.objects.all()
    ingredients = recipe.ingredients.splitlines()
    comments = Comment.objects.filter(recipe=recipe).order_by('-date')

    if request.method == 'POST':
        form = AddCommentForm(request.POST)

        if form.is_valid():
            comment = Comment()
            comment.text = form.cleaned_data['text']
            comment.author = request.user
            comment.recipe = recipe
            comment.date = datetime.now()
            comment.save()
    else:
        form = AddCommentForm()

    return render(request, 'recipe/show.html', {'form': form,
                                                'recipe': recipe,
                                                'categories': categories,
                                                'currentCat': recipe.category,
                                                'ingredients': ingredients,
                                                'comments': comments
                                                })
开发者ID:gitter-badger,项目名称:Cuis-In,代码行数:28,代码来源:views.py

示例8: add

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

示例9: tutorial_api

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
def tutorial_api(request):
    if request.method == "POST":
        print(request.body)
        _body = json.loads(request.body)
        try:
            new_comment = Comment(author=_body["author"], comment=_body["comment"])
            new_comment.save()
        except Exception as e:
            print(e)
    rtn_list = json_encoder.serialize_to_json(Comment.objects.all().values())
    return HttpResponse(rtn_list, content_type="application/json")
开发者ID:tekton,项目名称:django_react,代码行数:13,代码来源:views.py

示例10: newcomment

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
def newcomment(request):
    print "start process"
    if request.GET:
        print 'get'
        if request.GET.get('parent_comment',None)!=None:
            songid= request.GET['parentid']
            name=request.GET['name']
            contents=request.GET['contents']
            replayobj=request.GET['parent_comment']
            # print 'replay'
            # print songid
            # print 'name:'+name
            # print 'comments:'+contents

            if len(name)<1 or len(contents)<3:
                return HttpResponse('error1')
            elif len(name)>50 or len(contents)>400:
                return HttpResponse("error2")
            m=Comment(parent_song_id=songid,name=name,contents=contents,parent_comment=replayobj)
            m.save()
            if request.session.get("comsonglist"):
                comsonglist = request.session.get("comsonglist")
                comsonglist.append(songid)
                request.session['comsonglist']=comsonglist
            else:
                 request.session['comsonglist']=[songid]
            print "success add replay commment "
            return HttpResponse("success")
        else:
            songid= request.GET['parentid']
            name=request.GET['name']
            contents=request.GET['contents']
            # print songid
            # print 'name:'+name
            # print 'comments:'+contents

            if len(name)<1 or len(contents)<5:
                return HttpResponse('error1')
            elif len(name)>50 or len(contents)>400:
                return HttpResponse("error2")
            m=Comment(parent_song_id=songid,name=name,contents=contents)
            m.save()
            if request.session.get("comsonglist"):
                comsonglist = request.session.get("comsonglist")
                comsonglist.append(songid)
                request.session['comsonglist']=comsonglist
            else:
                 request.session['comsonglist']=[songid]
            print "success by direct add comment "
            return HttpResponse("success")
    else:
        return HttpResponse('error0')
开发者ID:outshineamaze,项目名称:music_wish,代码行数:54,代码来源:views.py

示例11: handle

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
 def handle(self, *args, **options):
     posts = list(Post.objects.all())
     users = list(get_user_model().objects.all())
     for i in range(1000):
         c = Comment()
         c.text = u"Комментарий {}".format(i)
         parent_post = random.choice(posts)
         c.parent_post = parent_post
         parent_comments = list(parent_post.comments.all())
         if parent_comments:
             c.parent_comment = random.choice(parent_comments)
         c.author = random.choice(users)
         c.save()
开发者ID:gafusss,项目名称:tehnotrek-webproject,代码行数:15,代码来源:fill_comments.py

示例12: new_comment

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
def new_comment(request):
    # saving the poted comment
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = Comment()
            comment.book = form.cleaned_data.get("book")
            comment.chapter = form.cleaned_data.get("chapter")
            comment.example = form.cleaned_data.get("example")
            comment.page = form.cleaned_data.get("page")
            comment.title = form.cleaned_data.get("title")
            comment.body = form.cleaned_data.get("body")
            comment.email = form.cleaned_data.get("email", "Anonymous")
            comment.save()
            return HttpResponseRedirect(
                '/comments/get/?book={0}&chapter={1}&example={2}&page={3}'.format(
                    comment.book, comment.chapter, comment.example, comment.page
                )
            )
        else:
            book = request.POST.get('book', '')
            chapter = request.POST.get('chapter', '')
            example = request.POST.get('example', '')
            page = request.POST.get('page', '')
            return HttpResponseRedirect(
                '/comments/new/?book={0}&chapter={1}&example={2}&page={3}'.format(
                    book, chapter, example, page
                )
            )

    # retriving comment parameters
    book = request.GET.get('book', '')
    chapter = request.GET.get('chapter', '')
    example = request.GET.get('example', '')
    page = request.GET.get('page', '')
    initial_values = {
        'book': book,
        'chapter': chapter,
        'example': example,
        'page': page
    }
    form = CommentForm(initial = initial_values)
    context = {
        'form': form,
        'book': book,
        'chapter': chapter,
        'example': example,
        'page': page
    }
    context.update(csrf(request))
    return render(request, 'comments/new_comment.html', context)
开发者ID:FOSSEE,项目名称:Python-TBC-Interface,代码行数:53,代码来源:views.py

示例13: comment_app

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
def comment_app(request):
    if request.method == 'POST':
        c_author = request.POST['author']
        c_email = request.POST['email']
        c_url = request.POST['url']
        c_content = request.POST['content']
        c_obj_class = request.POST['obj_class']
        try:
            c_obj_id = int(request.POST['obj_id'])
        except ValueError:
            raise Http404()
        p = Comment(author=c_author, email=c_email, url=c_url, content=c_content, objclass=c_obj_class, objid=c_obj_id)
        p.save()
    return HttpResponse("评论成功,请返回并刷新页面。")
开发者ID:Tian-Yu,项目名称:Django-myblog,代码行数:16,代码来源:views.py

示例14: test_user_can_delete_comments

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
 def test_user_can_delete_comments(self):
     self.assertTrue(self.login)
     resource = self.create_resources()
     comment = Comment(
         id=200,
         author=self.user,
         resource=resource,
         content="Test comment"
     )
     comment.save()
     response = self.client.delete(
         '/comment/200',
         HTTP_X_REQUESTED_WITH='XMLHttpRequest')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "success")
开发者ID:andela-ooshodi,项目名称:codango-debug,代码行数:17,代码来源:test_views.py

示例15: test_user_can_edit_comments

# 需要导入模块: from comments.models import Comment [as 别名]
# 或者: from comments.models.Comment import save [as 别名]
 def test_user_can_edit_comments(self):
     self.assertTrue(self.login)
     resource = self.create_resources()
     comment = Comment(
         id=200,
         author=self.user,
         resource=resource,
         content="Test comment"
     )
     comment.save()
     json_data = json.dumps({'content': 'Another Content', })
     response = self.client.put(
         '/comment/200', json_data, content_type='application/json',
         HTTP_X_REQUESTED_WITH='XMLHttpRequest')
     self.assertEqual(response.status_code, 200)
     self.assertContains(response, "success")
开发者ID:andela-ooshodi,项目名称:codango-debug,代码行数:18,代码来源:test_views.py


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