本文整理汇总了Python中website.models.NodeLog类的典型用法代码示例。如果您正苦于以下问题:Python NodeLog类的具体用法?Python NodeLog怎么用?Python NodeLog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeLog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, request, *args, **kwargs):
try:
node, user = self.get_object()
if node.remove_contributor(user, None, log=False):
update_admin_log(
user_id=self.request.user.id,
object_id=node.pk,
object_repr="Contributor",
message="User {} removed from node {}.".format(user.pk, node.pk),
action_flag=CONTRIBUTOR_REMOVED,
)
# Log invisibly on the OSF.
osf_log = NodeLog(
action=NodeLog.CONTRIB_REMOVED,
user=None,
params={"project": node.parent_id, "node": node.pk, "contributors": user.pk},
date=datetime.utcnow(),
should_hide=True,
)
osf_log.save()
except AttributeError:
return page_not_found(
request,
AttributeError(
'{} with id "{}" not found.'.format(self.context_object_name.title(), kwargs.get("node_id"))
),
)
return redirect(reverse_node(self.kwargs.get("node_id")))
示例2: delete
def delete(self, request, *args, **kwargs):
try:
node = self.get_object()
flag = None
osf_flag = None
message = None
if node.is_deleted:
node.is_deleted = False
node.deleted_date = None
flag = NODE_RESTORED
message = 'Node {} restored.'.format(node.pk)
osf_flag = NodeLog.NODE_CREATED
elif not node.is_registration:
node.is_deleted = True
node.deleted_date = datetime.utcnow()
flag = NODE_REMOVED
message = 'Node {} removed.'.format(node.pk)
osf_flag = NodeLog.NODE_REMOVED
node.save()
if flag is not None:
update_admin_log(
user_id=self.request.user.id,
object_id=node.pk,
object_repr='Node',
message=message,
action_flag=flag
)
if osf_flag is not None:
# Log invisibly on the OSF.
osf_log = NodeLog(
action=osf_flag,
user=None,
params={
'project': node.parent_id,
},
date=datetime.utcnow(),
should_hide=True,
)
osf_log.save()
except AttributeError:
return page_not_found(
request,
AttributeError(
'{} with id "{}" not found.'.format(
self.context_object_name.title(),
kwargs.get('guid')
)
)
)
return redirect(reverse_node(self.kwargs.get('guid')))
示例3: do_migration
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...')
示例4: user_last_log
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
示例5: count_user_logs
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
示例6: find_invalid_logs
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
示例7: get_log
def get_log(self):
log = NodeLog.load(self.kwargs.get('log_id'))
if not log:
raise NotFound(
detail='No log matching that log_id could be found.'
)
self.check_object_permissions(self.request, log)
return log
示例8: get_registered_from
def get_registered_from(registration):
"""
Gets node registration was registered from. Handles deleted registrations where registered_from is null.
"""
if registration.registered_from:
return registration.registered_from_id
else:
first_log_id = db['node'].find_one({'_id': registration._id})['logs'][0]
log = NodeLog.load(first_log_id)
return log.params.get('node') or log.params.get('project')
示例9: get_queryset
def get_queryset(self):
log = NodeLog.load(self.kwargs.get('log_id'))
if not log:
raise NotFound(
detail='No log matching that log_id could be found.'
)
else:
auth_user = get_user_auth(self.request)
return [
node for node in log.node__logged
if node.can_view(auth_user)
]
示例10: count_user_logs
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
示例11: migrate
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.')
示例12: get_targets
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
示例13: get_or_create_node
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)
示例14: main
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
示例15: get_targets
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