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


Python models.Comment类代码示例

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


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

示例1: _post_winning_submission

def _post_winning_submission(poll, submission_id):
    user = UserProfile.objects.get(username=poll.bot_name)
    submission = Submission.objects.get(id=submission_id)
    post = Post(user=user,
                category=poll.category,
                title="{}: {}".format(poll.stub, submission.title),
                url=submission.url,
                type='image',
                nsfw=True,
                crowd=submission.crowd)
    post.save()
    text = poll.winning_text.format(
        title=poll.title,
        stub=poll.stub,
        username=submission.user.username)

    comment = Comment(user=user,
                      post=post,
                      text=text,
                      crowd=submission.crowd)
    comment.save()
    winning_user = UserProfile.objects.get(id=submission.user.id)
    winning_user.poll_votes += 1
    winning_user.save()
    submission.delete()
    # Notify the winner they won
    notify_users(
        user_ids=[winning_user.id],
        from_user=UserProfile.objects.get(username=poll.bot_name),
        text="Your {} submission won!".format(poll.title),
        identifier=post.id,
        type='comment',
        level='info')
开发者ID:incrowdio,项目名称:incrowd,代码行数:33,代码来源:views.py

示例2: comment

def comment(request, screen_id):
    if request.method == 'POST':
        form = CommentForm(request.POST)
        if form.is_valid():
            screen = Screen.objects.get(id=screen_id)
            new_comment = Comment(screen=screen, comment=form.cleaned_data['comment'], created_by_user=request.user)
            new_comment.save()
            return redirect(request.META['HTTP_REFERER'])
    elif request.method == 'GET':
        raise Http404
开发者ID:gvsurenderreddy,项目名称:django-screens,代码行数:10,代码来源:views.py

示例3: update_folder_contents

def update_folder_contents(children, source_node, destination_node):
    for item in children:
        if not item.is_file:
            update_folder_contents(item.children, source_node, destination_node)
        else:
            Comment.update(Q('root_target', 'eq', item._id), data={'node': destination_node})
            # update node record of commented files
            if item._id in source_node.commented_files:
                destination_node.commented_files[item._id] = source_node.commented_files[item._id]
                del source_node.commented_files[item._id]
                source_node.save()
                destination_node.save()
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:12,代码来源:comment.py

示例4: update_file_guid_referent

def update_file_guid_referent(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved' or event_type == 'addon_file_renamed':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node
        file_guids = FileNode.resolve_class(source['provider'], FileNode.ANY).get_file_guids(
            materialized_path=source['materialized'] if source['provider'] != 'osfstorage' else source['path'],
            provider=source['provider'],
            node=source_node)

        if event_type == 'addon_file_renamed' and source['provider'] in settings.ADDONS_BASED_ON_IDS:
            return
        if event_type == 'addon_file_moved' and (source['provider'] == destination['provider'] and
                                                 source['provider'] in settings.ADDONS_BASED_ON_IDS) and source_node == destination_node:
            return

        for guid in file_guids:
            obj = Guid.load(guid)
            if source_node != destination_node and Comment.find(Q('root_target', 'eq', guid)).count() != 0:
                update_comment_node(guid, source_node, destination_node)

            if source['provider'] != destination['provider'] or source['provider'] != 'osfstorage':
                old_file = FileNode.load(obj.referent._id)
                obj.referent = create_new_file(obj, source, destination, destination_node)
                obj.save()
                if old_file and not TrashedFileNode.load(old_file._id):
                    old_file.delete()
开发者ID:caspinelli,项目名称:osf.io,代码行数:28,代码来源:comment.py

示例5: get_unread_comments_count

    def get_unread_comments_count(self, obj):
        user = get_user_auth(self.context['request']).user
        node_comments = Comment.find_n_unread(user=user, node=obj, page='node')

        return {
            'node': node_comments
        }
开发者ID:DanielSBrown,项目名称:osf.io,代码行数:7,代码来源:serializers.py

示例6: add_comment

def add_comment(**kwargs):

    auth = kwargs['auth']
    node = kwargs['node'] or kwargs['project']

    if not node.comment_level:
        raise HTTPError(http.BAD_REQUEST)

    if not node.can_comment(auth):
        raise HTTPError(http.FORBIDDEN)

    guid = request.json.get('target')
    target = resolve_target(node, guid)

    content = request.json.get('content').strip()
    content = sanitize(content)
    if not content:
        raise HTTPError(http.BAD_REQUEST)
    if len(content) > settings.COMMENT_MAXLENGTH:
        raise HTTPError(http.BAD_REQUEST)

    comment = Comment.create(
        auth=auth,
        node=node,
        target=target,
        user=auth.user,
        content=content,
    )
    comment.save()

    return {
        'comment': serialize_comment(comment, auth)
    }, http.CREATED
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:33,代码来源:comment.py

示例7: get_comment

def get_comment(cid, auth, owner=False):
    comment = Comment.load(cid)
    if comment is None:
        raise HTTPError(http.NOT_FOUND)
    if owner:
        if auth.user != comment.user:
            raise HTTPError(http.FORBIDDEN)
    return comment
开发者ID:sbt9uc,项目名称:osf.io,代码行数:8,代码来源:comment.py

示例8: n_unread_comments

def n_unread_comments(node, user):
    """Return the number of unread comments on a node for a user."""
    default_timestamp = datetime(1970, 1, 1, 12, 0, 0)
    view_timestamp = user.comments_viewed_timestamp.get(node._id, default_timestamp)
    return Comment.find(Q('node', 'eq', node) &
                        Q('user', 'ne', user) &
                        Q('date_created', 'gt', view_timestamp) &
                        Q('date_modified', 'gt', view_timestamp)).count()
开发者ID:sbt9uc,项目名称:osf.io,代码行数:8,代码来源:comment.py

示例9: add_comment

def add_comment(auth, node, **kwargs):

    if not node.comment_level:
        raise HTTPError(http.BAD_REQUEST)

    if not node.can_comment(auth):
        raise HTTPError(http.FORBIDDEN)

    guid = request.json.get('target')
    target = resolve_target(node, guid)

    content = request.json.get('content').strip()
    content = sanitize(content)
    if not content:
        raise HTTPError(http.BAD_REQUEST)
    if len(content) > settings.COMMENT_MAXLENGTH:
        raise HTTPError(http.BAD_REQUEST)

    comment = Comment.create(
        auth=auth,
        node=node,
        target=target,
        user=auth.user,
        content=content,
    )
    comment.save()

    context = dict(
        gravatar_url=auth.user.gravatar_url,
        content=content,
        target_user=target.user if is_reply(target) else None,
        parent_comment=target.content if is_reply(target) else "",
        url=node.absolute_url
    )
    time_now = datetime.utcnow().replace(tzinfo=pytz.utc)
    sent_subscribers = notify(
        uid=node._id,
        event="comments",
        user=auth.user,
        node=node,
        timestamp=time_now,
        **context
    )

    if is_reply(target):
        if target.user and target.user not in sent_subscribers:
            notify(
                uid=target.user._id,
                event='comment_replies',
                user=auth.user,
                node=node,
                timestamp=time_now,
                **context
            )

    return {
        'comment': serialize_comment(comment, auth)
    }, http.CREATED
开发者ID:GageGaskins,项目名称:osf.io,代码行数:58,代码来源:comment.py

示例10: update_comment_root_target_file

def update_comment_root_target_file(self, node, event_type, payload, user=None):
    if event_type == 'addon_file_moved':
        source = payload['source']
        destination = payload['destination']
        source_node = Node.load(source['node']['_id'])
        destination_node = node

        if (source.get('provider') == destination.get('provider') == 'osfstorage') and source_node._id != destination_node._id:
            old_file = FileNode.load(source.get('path').strip('/'))
            new_file = FileNode.resolve_class(destination.get('provider'), FileNode.FILE).get_or_create(destination_node, destination.get('path'))

            Comment.update(Q('root_target', 'eq', old_file._id), data={'node': destination_node})

            # update node record of commented files
            if old_file._id in source_node.commented_files:
                destination_node.commented_files[new_file._id] = source_node.commented_files[old_file._id]
                del source_node.commented_files[old_file._id]
                source_node.save()
                destination_node.save()
开发者ID:mchelen,项目名称:osf.io,代码行数:19,代码来源:comment.py

示例11: get_unread_comments_count

    def get_unread_comments_count(self, obj):
        user = self.get_user_auth(self.context['request']).user
        node_comments = Comment.find_n_unread(user=user, node=obj, page='node')
        file_comments = self.get_unread_file_comments(obj)

        return {
            'total': node_comments + file_comments,
            'node': node_comments,
            'files': file_comments
        }
开发者ID:mchelen,项目名称:osf.io,代码行数:10,代码来源:serializers.py

示例12: get_unread_file_comments

 def get_unread_file_comments(self, obj):
     user = self.get_user_auth(self.context['request']).user
     n_unread = 0
     commented_files = File.find(Q('_id', 'in', obj.commented_files.keys()))
     for file_obj in commented_files:
         if obj.get_addon(file_obj.provider):
             try:
                 self.context['view'].get_file_object(obj, file_obj.path, file_obj.provider, check_object_permissions=False)
             except (exceptions.NotFound, exceptions.PermissionDenied):
                 continue
             n_unread += Comment.find_n_unread(user, obj, page='files', root_id=file_obj._id)
     return n_unread
开发者ID:mchelen,项目名称:osf.io,代码行数:12,代码来源:serializers.py

示例13: kwargs_to_comment

def kwargs_to_comment(kwargs, owner=False):

    comment = Comment.load(kwargs.get('cid'))
    if comment is None:
        raise HTTPError(http.BAD_REQUEST)

    if owner:
        auth = kwargs['auth']
        if auth.user != comment.user:
            raise HTTPError(http.FORBIDDEN)

    return comment
开发者ID:akrit19,项目名称:osf.io,代码行数:12,代码来源:comment.py

示例14: main

def main():
    query = Comment.find(Q('root_target.1', 'ne', 'guid'))
    logger.info('Found {} comments whose root target is not a guid'.format(query.count()))
    migrated = 0
    for comment in query:
        root_target = comment.to_storage()['root_target']
        if root_target:
            logger.info('Root target for comment {}: {}'.format(comment._id, root_target))
            _id, collection = root_target
            if collection == 'storedfilenode':
                filenode = get_file_node(_id)
                if filenode:
                    guid = get_guid(filenode)
                    if guid:
                        logger.info('Setting root_target to Guid {}'.format(guid._id))
                        comment.root_target = guid
                        comment.save()
                        migrated += 1
            else:
                logger.error('Unexpected root target: {}'.format(root_target))
        # If root_target is unset, look at the target field
        elif root_target is None:
            logger.info('Root target for comment {} is None'.format(comment._id))
            guid = comment.target
            if isinstance(guid.referent, (TrashedFileNode, StoredFileNode)):
                logger.info('Setting root_target to Guid {}'.format(guid._id))
                comment.root_target = guid
                comment.save()
                migrated += 1
            elif isinstance(guid.referent, Comment):
                logger.info('Comment {} has a comment target. It is a reply.'.format(comment._id))
                found_root = False
                parent = guid.referent
                while not found_root:
                    if not isinstance(parent.target.referent, Comment):
                        found_root = True
                    else:
                        parent = parent.target.referent
                guid = parent.target
                logger.info('Setting root_target to Guid {}'.format(guid._id))
                comment.root_target = guid
                comment.save()
                migrated += 1

    logger.info('Successfully migrated {} comments'.format(migrated))
开发者ID:adlius,项目名称:osf.io,代码行数:45,代码来源:migrate_comment_root_target.py

示例15: update_comment_targets_to_guids

def update_comment_targets_to_guids():
    comments = Comment.find()
    for comment in comments:
        # Skip comments on deleted files
        if not comment.target:
            continue
        if isinstance(comment.root_target, StoredFileNode):
            comment.root_target = comment.root_target.get_guid()
        elif comment.root_target:
            comment.root_target = Guid.load(comment.root_target._id)

        if isinstance(comment.target, StoredFileNode):
            comment.target = comment.target.get_guid()
        else:
            comment.target = Guid.load(comment.target._id)

        comment.save()
        logger.info("Migrated root_target and target for comment {0}".format(comment._id))
开发者ID:kch8qx,项目名称:osf.io,代码行数:18,代码来源:migrate_comment_targets.py


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