本文整理汇总了Python中website.models.Comment.find方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.find方法的具体用法?Python Comment.find怎么用?Python Comment.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.models.Comment
的用法示例。
在下文中一共展示了Comment.find方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_file_guid_referent
# 需要导入模块: from website.models import Comment [as 别名]
# 或者: from website.models.Comment import find [as 别名]
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()
示例2: n_unread_comments
# 需要导入模块: from website.models import Comment [as 别名]
# 或者: from website.models.Comment import find [as 别名]
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()
示例3: main
# 需要导入模块: from website.models import Comment [as 别名]
# 或者: from website.models.Comment import find [as 别名]
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))
示例4: update_comment_targets_to_guids
# 需要导入模块: from website.models import Comment [as 别名]
# 或者: from website.models.Comment import find [as 别名]
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))
示例5: _view_project
# 需要导入模块: from website.models import Comment [as 别名]
# 或者: from website.models.Comment import find [as 别名]
def _view_project(node, auth, primary=False):
"""Build a JSON object containing everything needed to render
project.view.mako.
"""
user = auth.user
parent = node.parent_node
if user:
bookmark_collection = find_bookmark_collection(user)
bookmark_collection_id = bookmark_collection._id
in_bookmark_collection = bookmark_collection.pointing_at(node._primary_key) is not None
else:
in_bookmark_collection = False
bookmark_collection_id = ''
view_only_link = auth.private_key or request.args.get('view_only', '').strip('/')
anonymous = has_anonymous_link(node, auth)
widgets, configs, js, css = _render_addon(node)
redirect_url = node.url + '?view_only=None'
disapproval_link = ''
if (node.is_pending_registration and node.has_permission(user, ADMIN)):
disapproval_link = node.root.registration_approval.stashed_urls.get(user._id, {}).get('reject', '')
# Before page load callback; skip if not primary call
if primary:
for addon in node.get_addons():
messages = addon.before_page_load(node, user) or []
for message in messages:
status.push_status_message(message, kind='info', dismissible=False, trust=True)
data = {
'node': {
'disapproval_link': disapproval_link,
'id': node._primary_key,
'title': node.title,
'category': node.category_display,
'category_short': node.category,
'node_type': node.project_or_component,
'description': node.description or '',
'license': serialize_node_license_record(node.license),
'url': node.url,
'api_url': node.api_url,
'absolute_url': node.absolute_url,
'redirect_url': redirect_url,
'display_absolute_url': node.display_absolute_url,
'update_url': node.api_url_for('update_node'),
'in_dashboard': in_bookmark_collection,
'is_public': node.is_public,
'is_archiving': node.archiving,
'date_created': iso8601format(node.date_created),
'date_modified': iso8601format(node.logs[-1].date) if node.logs else '',
'tags': [tag._primary_key for tag in node.tags],
'children': bool(node.nodes_active),
'is_registration': node.is_registration,
'is_pending_registration': node.is_pending_registration,
'is_retracted': node.is_retracted,
'is_pending_retraction': node.is_pending_retraction,
'retracted_justification': getattr(node.retraction, 'justification', None),
'embargo_end_date': node.embargo_end_date.strftime("%A, %b. %d, %Y") if node.embargo_end_date else False,
'is_pending_embargo': node.is_pending_embargo,
'is_embargoed': node.is_embargoed,
'is_pending_embargo_termination': node.is_embargoed and (
node.embargo_termination_approval and
node.embargo_termination_approval.is_pending_approval
),
'registered_from_url': node.registered_from.url if node.is_registration else '',
'registered_date': iso8601format(node.registered_date) if node.is_registration else '',
'root_id': node.root._id if node.root else None,
'registered_meta': node.registered_meta,
'registered_schemas': serialize_meta_schemas(node.registered_schema),
'registration_count': node.registrations_all.count(),
'is_fork': node.is_fork,
'forked_from_id': node.forked_from._primary_key if node.is_fork else '',
'forked_from_display_absolute_url': node.forked_from.display_absolute_url if node.is_fork else '',
'forked_date': iso8601format(node.forked_date) if node.is_fork else '',
'fork_count': node.forks.count(),
'templated_count': node.templated_list.count(),
'watched_count': node.watches.count(),
'private_links': [x.to_json() for x in node.private_links_active],
'link': view_only_link,
'anonymous': anonymous,
'points': len(node.get_points(deleted=False, folders=False)),
'piwik_site_id': node.piwik_site_id,
'comment_level': node.comment_level,
'has_comments': bool(Comment.find(Q('node', 'eq', node))),
'has_children': bool(Comment.find(Q('node', 'eq', node))),
'identifiers': {
'doi': node.get_identifier_value('doi'),
'ark': node.get_identifier_value('ark'),
},
'institution': {
'name': node.primary_institution.name if node.primary_institution else None,
'logo_path': node.primary_institution.logo_path if node.primary_institution else None,
'id': node.primary_institution._id if node.primary_institution else None
},
'alternative_citations': [citation.to_json() for citation in node.alternative_citations],
'has_draft_registrations': node.has_active_draft_registrations,
'contributors': [contributor._id for contributor in node.contributors]
},
'parent_node': {
'exists': parent is not None,
#.........这里部分代码省略.........
示例6: update_comments
# 需要导入模块: from website.models import Comment [as 别名]
# 或者: from website.models.Comment import find [as 别名]
def update_comments():
comments = Comment.find()
for comment in comments:
comment.root_target = comment.node
comment.page = Comment.OVERVIEW
comment.save()