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


Python Comment.comment方法代码示例

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


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

示例1: post

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
def post(request):
    """Returns a serialized object
    :param obj_id: ID of comment object
    :type obj_id: int
    :returns: json
    """
    guid = request.POST.get('guid', None)
    res = Result()   

    if guid:
        obj = getObjectsFromGuids([guid,])[0]
        c = Comment()
        c.comment = request.POST.get('comment', 'No comment')
        c.user = request.user
        c.user_name = request.user.get_full_name()
        c.user_email = request.user.email
        c.content_object = obj
        c.site_id = 1
        c.save()
        obj.comment_count = obj.comment_count + 1
        obj.save()

        __email(c, obj)

        res.append({'id': c.id, 'comment': c.comment})
        res.isSuccess = True
    else:
        res.isError = True
        res.message = "No guid provided"

    return JsonResponse(res)
开发者ID:davideilering,项目名称:Frog,代码行数:33,代码来源:comment.py

示例2: approve

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
def approve(request, id):
    config = get_object_or_404(Config, pk=id)
    if config.locked:
        error = ("This configuration is locked. Only admins can unlock "
                 "it.")
        return details(request, config.id, error=error)
    old_status = config.status
    message = ''
    if request.method == 'POST':  # If the form has been submitted...
        data = request.POST
        if data.get('approved', False):
            # check if domains and domains requests are null
            if not config.domains.all() and not config.domainrequests.all():
                error = """Can't approve this configuration. There is no
                        correlated domain."""
                return details(request, id, error=error)
            # check if domain names already exist
            for domain in config.domainrequests.all():
                if Domain.objects.filter(name=domain).exclude(
                        Q(config__status='deleted') |
                        Q(config__status='invalid')):
                    error = """Can't approve this configuration. Domain is
                            already used by another approved configuration."""
                    return details(request, id, error=error)
            config.status = 'approved'
            for domain in config.domainrequests.all():
                exists = Domain.objects.filter(name=domain)
                if exists:
                    claimed = exists[0]
                    claimed.config = config
                else:
                    claimed = Domain(name=domain.name,
                                     config=config)
                claimed.save()
                domain.delete()
        elif data.get('denied', False):
            # Check mandatory comment when invalidating
            if data['comment'] == 'Other - invalid':
                if not data['commenttext']:
                    error = "Enter a comment."
                    return details(request, id, error=error)
                message = data['commenttext']
            else:
                message = data['comment']
            config.status = 'invalid'
        else:
            raise ValueError("shouldn't get here")
        config.save()
        comment = Comment(user_name='ISPDB System',
                          site_id=settings.SITE_ID)
        c = "<ul><li><b>Status</b> changed from <b><i>%s</i></b> to \
             <b><i>%s</i></b> by %s</li></ul>\n %s" % (old_status,
            config.status, request.user.email, message)
        comment.comment = c
        comment.content_type = ContentType.objects.get_for_model(Config)
        comment.object_pk = config.pk
        comment.save()

    return HttpResponseRedirect('/details/' + id)  # Redirect after POST
开发者ID:mozilla,项目名称:ispdb,代码行数:61,代码来源:views.py

示例3: test_comment_post_save

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
 def test_comment_post_save(self):
     content_type = ContentType.objects.get(model='issue')
     comment = Comment()
     comment.user_name = self.user.username
     comment.user_email = self.user.email
     comment.content_type = content_type
     comment.object_pk = 1
     comment.comment = "This is a test comment"
     comment.site = Site.objects.get(id=settings.SITE_ID)
     comment.save()
     print comment.comment
开发者ID:digi604,项目名称:djtracker,代码行数:13,代码来源:tests.py

示例4: do_comments

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
def do_comments(cursor,ID,entry):
    cursor.execute('select comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_content from wp_comments where comment_approved=1 and comment_post_ID=%s'%ID)
    comments=cursor.fetchall()
    for comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_content in comments:
        comm=Comment(content_object=entry,site=SITE,user_name=unic(comment_author)[:49],user_email=comment_author_email,user_url=comment_author_url,comment=unic(comment_content),ip_address='127.0.0.1',submit_date=comment_date,is_public=True,is_removed=False)
        try: comm.save(force_insert=True)
        except Exception, e:
            print comment_author,comment_author_email,comment_author_url,comment_author_IP,comment_date,comment_content
            print Exception, e
            if 'Incorrect string value' in e:
                comm.comment=comment_content.decode('latin1')
		comm.save(force_insert=True)
开发者ID:ivh,项目名称:TmyCMS,代码行数:14,代码来源:import_wp.py

示例5: test_notify_on_comment

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
 def test_notify_on_comment(self):
     # post some comment
     comment = Comment()
     content_type = ContentType.objects.get(model='issue')
     comment = Comment()
     comment.user_name = 'somebody'
     comment.user_email = '[email protected]'
     comment.content_type = content_type
     comment.object_pk = 1
     comment.comment = "This is a test comment"
     comment.site = Site.objects.get(id=settings.SITE_ID)
     comment.save()
     
     self.assertEquals(len(mail.outbox), 3)        
     self.check_outbox(self.recipient_list, "DjTracker: [unittest-project]: New Comment on Issue #1 by somebody", comment.comment)        
开发者ID:digi604,项目名称:djtracker,代码行数:17,代码来源:tests.py

示例6: newComment

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
def newComment(model, request, comment):
    user = request.user
    c = Comment()
    
    c.user = user
    c.user_name = user.username
    c.user_email = user.email
    c.ip_address = request.META.get('REMOTE_ADDR')
    c.comment = comment
    
    # c.site = Site.objects.get(id=settings.SITE_ID)
    c.site_id = settings.SITE_ID
    
    c.content_type = ContentType.objects.get_for_model(model)
    c.object_pk = model.id
    
    c.save()
开发者ID:rdrsh,项目名称:logoclone,代码行数:19,代码来源:models.py

示例7: create_comment

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

示例8: test_members_with_comment_by_same_user

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
    def test_members_with_comment_by_same_user(self):
        user = random_user()
        idea = models.Idea(creator=user, title='Transit subsidy to Mars',
                    text='Aliens need assistance.', state=self.state)
        idea.save()

        commenter = user

        comment = Comment()
        comment.user = commenter
        comment.content_object = idea
        comment.comment = 'Test'
        comment.is_public = True
        comment.is_removed = False
        comment.site_id = 1
        comment.save()

        self.assertEqual(len(idea.members), 1)
        self.assertIn(user, idea.members)
开发者ID:Zorig,项目名称:idea-box,代码行数:21,代码来源:model_tests.py

示例9: comment_reply_post_create_handler

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
def comment_reply_post_create_handler(sender, instance, action, model, pk_set,
    using, **kwargs):
    if action == 'post_add':
        for replied_to_comment in instance.replied_to_comments.all():
            moderator_settings = getattr(settings, 'MODERATOR', None)
            offset_timedelta = timedelta(seconds=1)
            if moderator_settings:
                if 'REPLY_BEFORE_COMMENT' in moderator_settings:
                    if moderator_settings['REPLY_BEFORE_COMMENT']:
                        offset_timedelta = timedelta(seconds=-1)

            created = False
            # We use try except DoesNotExist instead of get or create to
            # allow us to add a is_reply_comment to a newly created comment
            # which facilitates realtime_comment_classifier below to distinguish
            # between normal comments and reply comments.
            try:
                comment_obj = Comment.objects.get(
                    content_type=replied_to_comment.content_type,
                    object_pk=replied_to_comment.object_pk,
                    site=replied_to_comment.site,
                    submit_date=replied_to_comment.submit_date + offset_timedelta,
                    user=instance.user,
                )
            except Comment.DoesNotExist:
                comment_obj = Comment(
                    content_type=replied_to_comment.content_type,
                    object_pk=replied_to_comment.object_pk,
                    site=replied_to_comment.site,
                    submit_date=replied_to_comment.submit_date + offset_timedelta,
                    user=instance.user,
                    comment=instance.comment_text,
                )
                comment_obj.is_reply_comment = True
                comment_obj.save()
                created = True

            if not created:
                comment_obj.comment = instance.comment_text
                comment_obj.save()

            if comment_obj not in instance.reply_comments.all():
                instance.reply_comments.add(comment_obj)
开发者ID:praekelt,项目名称:django-moderator,代码行数:45,代码来源:models.py

示例10: process_comment

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

示例11: parse_repo

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
    def parse_repo(self, project):
        starting_commit = project.svn_repo_commit
        client = pysvn.Client()
        client.set_interactive(False)
        client.set_default_username(project.svn_repo_username)
        client.set_default_password(project.svn_repo_password)
        commits = client.log(project.svn_repo_url,
           revision_start=pysvn.Revision(pysvn.opt_revision_kind.number, int(starting_commit)),
           revision_end=pysvn.Revision(pysvn.opt_revision_kind.head))

        match_string = re.compile('Fixes #[\d]+')
        issue_matches = []
        for x in commits:
            for message in match_string.findall(x.data['message']):
                issue_matches.append(x)

        number_string = re.compile('\d+')
        closed_status = models.Status.objects.get(slug="closed")
        for x in issue_matches:
            for y in number_string.findall(x.data['message']):
                try:
                    issue = models.Issue.objects.get(id=y)
                    if issue.status is closed_status:
                        continue
                except ObjectDoesNotExist:
                    continue

                issue.status=closed_status
                issue.save()
                comment = Comment()
                comment.user_name = "vcs_bot"
                comment.user_email = "[email protected]"
                comment.content_type = self.content_type
                comment.object_pk = issue.id
                comment.comment = x.data['message']
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
                project.git_repo_commit = x.data['revision'].number
                project.save()
开发者ID:GunioRobot,项目名称:djtracker,代码行数:41,代码来源:svn_poller.py

示例12: parse_repo

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
    def parse_repo(self, project):
        repo = git.Repo(project.git_repo_path)
        starting_commit = project.git_repo_commit
        commits = repo.commits()
        for x in commits:
            if starting_commit == x.id:
                starting_commit = x
        index = commits.index(starting_commit)
        commits = commits[:index]
        match_string = re.compile('Fixes #[\d]+')
        issue_matches = []
        for x in commits:
            for message in match_string.findall(x.message):
                issue_matches.append(x)

        number_string = re.compile('\d+')
        closed_status = models.Status.objects.get(slug="closed")
        for x in issue_matches:
            for y in number_string.findall(x.message):
                try:
                    issue = models.Issue.objects.get(id=y)
                    if issue.status is closed_status:
                        continue
                except ObjectDoesNotExist:
                    continue

                issue.status=closed_status
                issue.save()
                comment = Comment()
                comment.user_name = "vcs_bot"
                comment.user_email = "[email protected]"
                comment.content_type = self.content_type
                comment.object_pk = issue.id
                comment.comment = x.message
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
                project.git_repo_commit = x.id
                project.save()
开发者ID:GunioRobot,项目名称:djtracker,代码行数:40,代码来源:git_poller.py

示例13: parse_message

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
    def parse_message(self, message, raw_data):
        ## Get project slug
        match = re.search("\[[\w-]+\]", message['subject'])
        project_slug = match.group().lstrip('[').rstrip(']')

        ## Get email address
        #print message['from']
        match = re.search(r'[a-zA-Z0-9+_\-\.][email protected][0-9a-zA-Z]*.[a-zA-Z]+',
                               message['from'])
        #print match.group()
        email_addy = match.group()
        ## Get Issue Number (if exists)
        match = re.search("Issue #[\d]+", message['subject'])
        if match:
            issue_string = match.group()
            issue_num = issue_string.lstrip("Issue #")
            issue_title = message['subject'][match.end():].lstrip(" - ")
        else:
            issue_num = None
            match = re.search("\[[\w-]+\]", message['subject'])
            issue_title = message['subject'][match.end():]
            issue_title =  issue_title.lstrip(": ")

        ## Get our django objects
        try:
            project = models.Project.objects.get(slug=project_slug)
        except ObjectDoesNotExist:
            return

        try:
            user = User.objects.get(email=email_addy)
            can_comment = utils.check_permissions('comment', user, project)
        except ObjectDoesNotExist:
            can_comment = project.allow_anon_comment
            user = None

        try:
            issue = models.Issue.objects.get(id=issue_num)
        except ObjectDoesNotExist:
            issue = None

        body = raw_data[message.startofbody:]
        content_type = ContentType.objects.get(model='issue')

        #print can_comment
        if can_comment:
            if issue is not None:
                comment = Comment()
                if user is not None:
                    comment.user_name = user.username
                    comment.user_email = user.email
                else:
                    comment.user_name = email_addy
                    comment.user_email = email_addy

                comment.content_type = content_type
                comment.object_pk = issue.id
                comment.comment = body
                comment.site = Site.objects.get(id=settings.SITE_ID)
                comment.save()
            else:
                issue = models.Issue()
                issue.name = issue_title
                issue.project = project
                issue.description = body
                status = models.Status.objects.get(id=1)
                priority = models.Priority.objects.get(id=1)
                issue_type = models.IssueType.objects.get(id=1)
                issue.status = status
                issue.priority = priority
                issue.issue_type = issue_type
                issue.save()
开发者ID:GunioRobot,项目名称:djtracker,代码行数:74,代码来源:imap_poller.py

示例14: handle

# 需要导入模块: from django.contrib.comments.models import Comment [as 别名]
# 或者: from django.contrib.comments.models.Comment import comment [as 别名]
    def handle(self, *args, **options):
        try:
            file = args[0]
        except IndexError:
            raise CommandError('No file was specified')

        try:
            tree = ET.parse(file)
        except IOError:
            raise CommandError("%s could not be found" % file)

        wp = 'http://wordpress.org/export/1.1/'

        for item in tree.findall('channel/item'):
            # Get the post's slug
            slug = item.find('{%s}post_name' % wp).text

            # 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()
#.........这里部分代码省略.........
开发者ID:AndreMiras,项目名称:django-vellum,代码行数:103,代码来源:wordpress_import.py


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