本文整理汇总了Python中website.models.NodeLog.find方法的典型用法代码示例。如果您正苦于以下问题:Python NodeLog.find方法的具体用法?Python NodeLog.find怎么用?Python NodeLog.find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类website.models.NodeLog
的用法示例。
在下文中一共展示了NodeLog.find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_migration
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def do_migration(records, dry=False):
for node in records:
logs = list(NodeLog.find(Q('was_connected_to', 'contains', node)))
existing_logs = node.logs
for log in logs:
if not log.node__logged:
continue
log_node = log.node__logged[0]
# if the log_node is not contained in the node parent list then it doesn't belong to this node
if log_node not in get_all_parents(node):
logger.info('Excluding log {} from list because it is not associated with node {}'.format(log, node))
logs.remove(log)
with TokuTransaction():
node.logs = logs + existing_logs
node.system_tags.append(SYSTEM_TAG)
node_type = 'registration' if node.is_registration else 'fork'
logger.info('Adding {} logs to {} {}'.format(len(logs), node_type, node))
if not dry:
try:
node.save()
except Exception as err:
logger.error('Could not update logs for node {} due to error'.format(node._id))
logger.exception(err)
logger.error('Skipping...')
示例2: user_last_log
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def user_last_log(user, query=None):
if query:
query &= Q('user', 'eq', user._id)
else:
query = Q('user', 'eq', user._id)
node_logs = NodeLog.find(query)
return node_logs[node_logs.count()-1].date
示例3: count_user_logs
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def count_user_logs(user):
logs = NodeLog.find(Q('user', 'eq', user._id))
length = logs.count()
if length == LOG_THRESHOLD:
item = logs[0]
if item.action == 'project_created' and item.node.is_bookmark_collection:
length -= 1
return length
示例4: find_invalid_logs
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def find_invalid_logs():
for log in NodeLog.find(Q('action', 'eq', NodeLog.WIKI_DELETED)):
# Derive UTC datetime object from ObjectId
id_date = ObjectId(log._id).generation_time
id_date = id_date.replace(tzinfo=None) - id_date.utcoffset()
if id_date > log.date:
yield log
示例5: count_user_logs
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def count_user_logs(user, query=None):
if query:
query &= Q('user', 'eq', user._id)
else:
query = Q('user', 'eq', user._id)
logs = NodeLog.find(query)
length = logs.count()
if length > 0:
item = logs[0]
if item.action == 'project_created' and item.node.is_dashboard:
length -= 1
return length
示例6: migrate
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def migrate(dry_run=True):
added_logs = NodeLog.find(Q('action', 'eq', PRIMARY_INSTITUTION_CHANGED))
for log in added_logs:
logger.info('Log with id <{}> being updated for affiliation added'.format(log._id))
log.action = NodeLog.AFFILIATED_INSTITUTION_ADDED
log.save()
removed_logs = NodeLog.find(Q('action', 'eq', PRIMARY_INSTITUTION_REMOVED))
for log in removed_logs:
logger.info('Log with id <{}> being updated for affiliation removed'.format(log._id))
log.action = NodeLog.AFFILIATED_INSTITUTION_REMOVED
log.save()
nodes = Node.find(Q('primary_institution', 'ne', None))
for node in nodes:
logger.info('Node with id <{}> and title <{}> being updated'.format(node._id, node.title))
inst = node.primary_institution
if inst not in node.affiliated_institutions:
node.affiliated_institutions.append(inst)
node.primary_institution = None
node.save()
if dry_run:
raise RuntimeError('Dry run, transaction rolled back.')
示例7: get_targets
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def get_targets():
"""
These logs are potentially missing params['registration'] fields. Params['node'] and original_node fields may incorrectly
be pointing to the registration instead of the node.
"""
logs = NodeLog.find(
Q('action', 'eq', 'registration_cancelled') |
Q('action', 'eq', 'retraction_approved') |
Q('action', 'eq', 'retraction_cancelled') |
Q('action', 'eq', 'embargo_approved') |
Q('action', 'eq', 'embargo_cancelled') |
Q('action', 'eq', 'embargo_terminated')
)
return logs
示例8: get_or_create_node
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def get_or_create_node(node_id, sqlite_db):
"""Gets an OSF node from the sqlite cache. If not found, pulls the node info from mongo and
saves it.
:param node_id: OSF node id (e.g. 'mst3k')
:param sqlite_db: SQLite3 database handle
:return: node dict
"""
if node_id is None:
return None
cursor = sqlite_db.cursor()
query = "SELECT * FROM nodes WHERE id='{}'".format(node_id)
cursor.execute(query)
nodes = cursor.fetchall()
if len(nodes) > 1:
raise Exception("Multiple nodes found for single node ID")
if nodes:
return nodes[0]
node = Node.load(node_id)
if node is None:
return None
node_public_date = None
privacy_actions = NodeLog.find(
Q('node', 'eq', node_id)
& Q('action', 'in', [NodeLog.MADE_PUBLIC, NodeLog.MADE_PRIVATE])
).sort('-date')
try:
privacy_action = privacy_actions[0]
except IndexError as e:
pass
else:
if privacy_action.action == NodeLog.MADE_PUBLIC:
node_public_date = privacy_action.date.isoformat()
node_public_date = node_public_date[:-3] + 'Z'
cursor.execute(
u'INSERT INTO nodes (id, title, category, made_public_date) VALUES (?, ?, ?, ?)',
(node_id, getattr(node, 'title'), getattr(node, 'category'), node_public_date)
)
sqlite_db.commit()
return get_or_create_node(node_id, sqlite_db)
示例9: main
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def main(dry):
if dry:
logging.warn('DRY mode running')
now = datetime.utcnow()
initiated_logs = NodeLog.find(Q('action', 'eq', NodeLog.PREPRINT_INITIATED) & Q('date', 'lt', now))
for log in initiated_logs:
try:
preprint = PreprintService.find_one(Q('node', 'eq', log.node))
log.params.update({
'preprint': {
'id': preprint._id
},
'service': {
'name': preprint.provider.name
}
})
logging.info('Updating log {} from node {}, with preprint id: {}'.format(log._id, log.node.title, preprint._id))
if not dry:
log.save()
except NoResultsFound:
pass
updated_logs = NodeLog.find(Q('action', 'eq', NodeLog.PREPRINT_FILE_UPDATED) & Q('date', 'lt', now))
for log in updated_logs:
try:
preprint = PreprintService.find_one(Q('node', 'eq', log.node))
log.params.update({
'preprint': {
'id': preprint._id
}
})
logging.info('Updating log {} from node {}, with preprint id: {}'.format(log._id, log.node.title, preprint._id))
if not dry:
log.save()
except NoResultsFound:
pass
示例10: get_targets
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def get_targets():
"""
Fetches all registration-related logs except for project_registered.
project_registered log is not included because params already correct.
"""
logs = NodeLog.find(
Q('action', 'eq', 'registration_initiated') |
Q('action', 'eq', 'registration_approved') |
Q('action', 'eq', 'registration_cancelled') | # On staging, there are a few inconsistencies with these. Majority of params['node'] are registrations, but a handful are nodes.
Q('action', 'eq', 'retraction_initiated') |
Q('action', 'eq', 'retraction_approved') | # params['node'] is already equal to node. Adds registration_field below. Will be slow.
Q('action', 'eq', 'retraction_cancelled') |
Q('action', 'eq', 'embargo_initiated') |
Q('action', 'eq', 'embargo_approved') |
Q('action', 'eq', 'embargo_completed') |
Q('action', 'eq', 'embargo_cancelled')
)
return logs
示例11: get_targets
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def get_targets():
# ... return the list of logs whose registrations we want to migrate ...
targets = NodeLog.find(Q('action', 'eq', 'retraction_approved'))
logger.info('Retractions found: {}'.format(len(targets)))
return targets
示例12: logs_since
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def logs_since(user, date):
return NodeLog.find(
Q('user', 'eq', user._id) &
Q('date', 'gt', date)
)
示例13: get_targets
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def get_targets():
return NodeLog.find(Q('should_hide', 'eq', True))
示例14: main
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def main():
total = MODMNodeLog.find().count()
# total = len(modm_nodelogs)
count = 0
page_size = 100000
django_nodelogs = []
django_nodelogs_ids = []
django_nodelogs_was_connected_to = {}
print 'Migrating {} logs...'.format(total)
while count < total:
modm_nodelogs = None
modm_nodelogs = MODMNodeLog.find().sort('-date')[count:count + page_size]
with transaction.atomic():
print 'Migrating {} through {} which is {}'.format(
count, count + page_size, len(modm_nodelogs))
for modm_nodelog in modm_nodelogs:
# don't recreate the log if it exists
if NodeLog.objects.filter(guid=modm_nodelog._id).exists():
pass
else:
if modm_nodelog.user is not None:
# try to get the pk out of the lookup table
user_pk = modm_to_django.get(modm_nodelog.user._id,
None)
# it wasn't there
if user_pk is None:
# create a new user
print 'Creating User {}'.format(modm_nodelog.user._id)
user = get_or_create_user(modm_nodelog.user)
user_pk = user.pk
# put the user in the lookup table for next time
modm_to_django[modm_nodelog.user._id] = user_pk
else:
# log doesn't have user
user_pk = None
# get the node (either a MODMNode instance or a node guid)
node_id = modm_nodelog.params.get(
'node', modm_nodelog.params.get('project'))
node_pk = None
if node_id is not None:
if isinstance(node_id, basestring):
# it's a guid, look it up in the table
node_pk = modm_to_django.get(node_id, None)
elif isinstance(node_id, MODMNode):
# it's an instance, look it up in the table
node_pk = modm_to_django.get(node_id._id, None)
if node_pk is None:
print 'Creating Node {}'.format(node_id)
# it wasn't in the table
if isinstance(node_id, basestring):
# it's a guid, get an instance and create a PG version
modm_node = MODMNode.load(node_id)
django_node = get_or_create_node(modm_node)
if django_node is None:
print 'Node {} does not exist.'.format(
node_id)
continue
node_pk = get_or_create_node(modm_node).pk
# put it in the table for later
modm_to_django[modm_node._id] = node_pk
elif isinstance(node_id, MODMNode):
# it's an instance, create a PG version
node_pk = get_or_create_node(node_id).pk
# put it in the table for later
modm_to_django[node_id._id] = node_pk
if node_pk is not None:
was_connected_to = []
for wct in modm_nodelog.was_connected_to:
wct_pk = modm_to_django.get(wct._id, None)
if wct_pk is None:
wct_pk = get_or_create_node(wct).pk
modm_to_django[wct._id] = wct_pk
was_connected_to.append(wct_pk)
if modm_nodelog.date is None:
nodelog_date = None
else:
nodelog_date = pytz.utc.localize(modm_nodelog.date)
if modm_nodelog._id not in django_nodelogs_ids:
django_nodelogs.append(NodeLog(
guid=modm_nodelog._id,
date=nodelog_date,
action=modm_nodelog.action,
params=modm_nodelog.params,
should_hide=modm_nodelog.should_hide,
user_id=user_pk,
foreign_user=modm_nodelog.foreign_user or '',
node_id=node_pk))
django_nodelogs_was_connected_to[
modm_nodelog._id] = was_connected_to
django_nodelogs_ids.append(modm_nodelog._id)
else:
print 'NodeLog with id {} and data {} was already in the bulk_create'.format(
modm_nodelog._id, modm_nodelog.to_storage())
else:
#.........这里部分代码省略.........
示例15: get_aggregate_logs
# 需要导入模块: from website.models import NodeLog [as 别名]
# 或者: from website.models.NodeLog import find [as 别名]
def get_aggregate_logs(ids, user, count=100):
query = Q('params.node', 'in', ids)
return list(NodeLog.find(query).sort('date').limit(int(count)))