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


Python NodeLog.find方法代码示例

本文整理汇总了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...')
开发者ID:Alpani,项目名称:osf.io,代码行数:27,代码来源:migrate_registration_and_fork_log.py

示例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
开发者ID:mattspitzer,项目名称:osf.io,代码行数:10,代码来源:webinar_workshop_users.py

示例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
开发者ID:baylee-d,项目名称:osf.io,代码行数:10,代码来源:user_summary.py

示例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
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:ensure_log_dates.py

示例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
开发者ID:mattspitzer,项目名称:osf.io,代码行数:14,代码来源:depth_users.py

示例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.')
开发者ID:adlius,项目名称:osf.io,代码行数:25,代码来源:migrate_primary_institutions.py

示例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
开发者ID:adlius,项目名称:osf.io,代码行数:16,代码来源:migrate_regressed_registration_logs.py

示例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)
开发者ID:atelic,项目名称:osf.io,代码行数:51,代码来源:transform_01.py

示例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
开发者ID:adlius,项目名称:osf.io,代码行数:38,代码来源:migrate_preprint_logs.py

示例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
开发者ID:545zhou,项目名称:osf.io,代码行数:21,代码来源:migrate_registration_logs.py

示例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
开发者ID:adlius,项目名称:osf.io,代码行数:8,代码来源:migrate_retraction_dates.py

示例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)
    )
开发者ID:545zhou,项目名称:osf.io,代码行数:7,代码来源:annotate_rsvps.py

示例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))
开发者ID:545zhou,项目名称:osf.io,代码行数:4,代码来源:migrate_logs_fix.py

示例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:
#.........这里部分代码省略.........
开发者ID:wearpants,项目名称:osf_models,代码行数:103,代码来源:load_nodelogs.py

示例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)))
开发者ID:adlius,项目名称:osf.io,代码行数:5,代码来源:log_analytics.py


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