Exemplo n.º 1
0
def node_register_template_page(auth, node, metaschema_id, **kwargs):
    if node.is_registration and bool(node.registered_schema):
        try:
            meta_schema = MetaSchema.find_one(
                Q('_id', 'eq', metaschema_id)
            )
        except NoResultsFound:
            # backwards compatability for old urls, lookup by name
            try:
                meta_schema = MetaSchema.find(
                    Q('name', 'eq', _id_to_name(metaschema_id))
                ).sort('-schema_version')[0]
            except IndexError:
                raise HTTPError(http.NOT_FOUND, data={
                    'message_short': 'Invalid schema name',
                    'message_long': 'No registration schema with that name could be found.'
                })
        if meta_schema not in node.registered_schema:
            raise HTTPError(http.BAD_REQUEST, data={
                'message_short': 'Invalid schema',
                'message_long': 'This registration has no registration supplment with that name.'
            })

        ret = _view_project(node, auth, primary=True)
        ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
        return ret
    else:
        status.push_status_message(
            'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
            trust=False
        )
        return redirect(node.web_url_for('node_registrations', view=kwargs.get('template')))
Exemplo n.º 2
0
def node_register_template_page(auth, node, metaschema_id, **kwargs):
    if node.is_registration and bool(node.registered_schema):
        try:
            meta_schema = RegistrationSchema.objects.get(_id=metaschema_id)
        except RegistrationSchema.DoesNotExist:
            # backwards compatability for old urls, lookup by name
            meta_schema = RegistrationSchema.objects.filter(name=_id_to_name(metaschema_id)).order_by('-schema_version').first()
            if not meta_schema:
                raise HTTPError(http.NOT_FOUND, data={
                    'message_short': 'Invalid schema name',
                    'message_long': 'No registration schema with that name could be found.'
                })
        if not node.registered_schema.filter(id=meta_schema.id).exists():
            raise HTTPError(http.BAD_REQUEST, data={
                'message_short': 'Invalid schema',
                'message_long': 'This registration has no registration supplment with that name.'
            })

        ret = _view_project(node, auth, primary=True)
        my_meta = serialize_meta_schema(meta_schema)
        if has_anonymous_link(node, auth):
            for indx, schema_page in enumerate(my_meta['schema']['pages']):
                for idx, schema_question in enumerate(schema_page['questions']):
                    if schema_question['title'] in settings.ANONYMIZED_TITLES:
                        del my_meta['schema']['pages'][indx]['questions'][idx]
        ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
        return ret
    else:
        status.push_status_message(
            'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
            trust=False,
            id='redirected_to_registrations',
        )
        return redirect(node.web_url_for('node_registrations', view=kwargs.get('template'), _guid=True))
Exemplo n.º 3
0
def node_register_template_page(auth, node, metaschema_id, **kwargs):
    if node.is_registration and bool(node.registered_schema):
        try:
            meta_schema = MetaSchema.objects.get(_id=metaschema_id)
        except MetaSchema.DoesNotExist:
            # backwards compatability for old urls, lookup by name
            meta_schema = MetaSchema.objects.filter(name=_id_to_name(metaschema_id)).order_by('-schema_version').first()
            if not meta_schema:
                raise HTTPError(http.NOT_FOUND, data={
                    'message_short': 'Invalid schema name',
                    'message_long': 'No registration schema with that name could be found.'
                })
        if not node.registered_schema.filter(id=meta_schema.id).exists():
            raise HTTPError(http.BAD_REQUEST, data={
                'message_short': 'Invalid schema',
                'message_long': 'This registration has no registration supplment with that name.'
            })

        ret = _view_project(node, auth, primary=True)
        my_meta = serialize_meta_schema(meta_schema)
        if has_anonymous_link(node, auth):
            for indx, schema_page in enumerate(my_meta['schema']['pages']):
                for idx, schema_question in enumerate(schema_page['questions']):
                    if schema_question['title'] in settings.ANONYMIZED_TITLES:
                        del my_meta['schema']['pages'][indx]['questions'][idx]
        ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
        return ret
    else:
        status.push_status_message(
            'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
            trust=False
        )
        return redirect(node.web_url_for('node_registrations', view=kwargs.get('template')))
Exemplo n.º 4
0
def main(dev=False, _db=None):
    _db = _db or db
    init_app(routes=False)
    count = 0
    skipped = 0
    scripts_utils.add_file_logger(logger, __file__)
    logger.info("Iterating over all registrations")

    # convert registered_schema to list field
    prepare_nodes()
    ensure_schemas()

    node_documents = _db['node'].find({'is_registration': True})
    for node in node_documents:
        registered_schemas = []
        registered_meta = {}
        schemas = node['registered_meta']
        if not schemas:
            logger.info(
                'Node: {0} is registered but has no registered_meta'.format(
                    node['_id']))
            continue
        for schema_id, schema in schemas.iteritems():
            name = _id_to_name(from_mongo(schema_id))
            schema = from_json_or_fail(schema)
            # append matching schema to node.registered_schema
            try:
                meta_schema = MetaSchema.find(Q(
                    'name', 'eq', name)).sort('-schema_version')[0]
            except IndexError as e:
                logger.error(
                    'No MetaSchema matching name: {0} found for node: {1}.'.
                    format(name, node['_id']))
                # Skip over missing schemas
                skipped += 1
                if dev:
                    continue
                else:
                    raise e
            else:
                registered_meta[meta_schema._id] = {
                    key: {
                        'value': value
                    }
                    for key, value in schema.items()
                }
                registered_schemas.append(meta_schema._id)
        db['node'].update({'_id': node['_id']}, {
            '$set': {
                'registered_meta': registered_meta,
                'registered_schema': registered_schemas
            }
        })
        count = count + 1
    logger.info('Done with {0} nodes migrated and {1} nodes skipped.'.format(
        count, skipped))
Exemplo n.º 5
0
def main(dev=False, _db=None):
    _db = _db or db
    init_app(routes=False)
    count = 0
    skipped = 0
    scripts_utils.add_file_logger(logger, __file__)
    logger.info("Iterating over all registrations")

    # convert registered_schema to list field
    prepare_nodes()
    ensure_schemas()

    node_documents = _db['node'].find({'is_registration': True})
    for node in node_documents:
        registered_schemas = []
        registered_meta = {}
        schemas = node['registered_meta']
        if not schemas:
            logger.info('Node: {0} is registered but has no registered_meta'.format(node['_id']))
            continue
        for schema_id, schema in schemas.iteritems():
            name = _id_to_name(from_mongo(schema_id))
            schema = from_json_or_fail(schema)
            # append matching schema to node.registered_schema
            try:
                meta_schema = MetaSchema.find(
                    Q('name', 'eq', name)
                ).sort('-schema_version')[0]
            except IndexError as e:
                logger.error('No MetaSchema matching name: {0} found for node: {1}.'.format(name, node['_id']))
                # Skip over missing schemas
                skipped += 1
                if dev:
                    continue
                else:
                    raise e
            else:
                registered_meta[meta_schema._id] = {
                    key: {
                        'value': value
                    }
                    for key, value in schema.items()
                }
                registered_schemas.append(meta_schema._id)
        db['node'].update(
            {'_id': node['_id']},
            {'$set': {
                'registered_meta': registered_meta,
                'registered_schema': registered_schemas
            }}
        )
        count = count + 1
    logger.info('Done with {0} nodes migrated and {1} nodes skipped.'.format(count, skipped))
Exemplo n.º 6
0
def node_register_template_page(auth, node, metaschema_id, **kwargs):
    if flag_is_active(request, features.EMBER_REGISTRIES_DETAIL_PAGE):
        # Registration meta page obviated during redesign
        return redirect(node.url)
    if node.is_registration and bool(node.registered_schema):
        try:
            meta_schema = RegistrationSchema.objects.get(_id=metaschema_id)
        except RegistrationSchema.DoesNotExist:
            # backwards compatability for old urls, lookup by name
            meta_schema = RegistrationSchema.objects.filter(name=_id_to_name(
                metaschema_id)).order_by('-schema_version').first()
            if not meta_schema:
                raise HTTPError(
                    http_status.HTTP_404_NOT_FOUND,
                    data={
                        'message_short':
                        'Invalid schema name',
                        'message_long':
                        'No registration schema with that name could be found.'
                    })

        ret = _view_project(node, auth, primary=True)
        my_meta = serialize_meta_schema(meta_schema)
        if has_anonymous_link(node, auth):
            for indx, schema_page in enumerate(my_meta['schema']['pages']):
                for idx, schema_question in enumerate(
                        schema_page['questions']):
                    if schema_question['title'] in settings.ANONYMIZED_TITLES:
                        del my_meta['schema']['pages'][indx]['questions'][idx]
        ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
        return ret
    else:
        status.push_status_message(
            'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
            trust=False,
            id='redirected_to_registrations',
        )
        return redirect(
            node.web_url_for('node_registrations',
                             view=kwargs.get('template'),
                             _guid=True))
Exemplo n.º 7
0
def node_register_template_page(auth, node, metaschema_id, **kwargs):
    if node.is_registration and bool(node.registered_schema):
        try:
            meta_schema = MetaSchema.find_one(Q('_id', 'eq', metaschema_id))
        except NoResultsFound:
            # backwards compatability for old urls, lookup by name
            try:
                meta_schema = MetaSchema.find(
                    Q('name', 'eq',
                      _id_to_name(metaschema_id))).sort('-schema_version')[0]
            except IndexError:
                raise HTTPError(
                    http.NOT_FOUND,
                    data={
                        'message_short':
                        'Invalid schema name',
                        'message_long':
                        'No registration schema with that name could be found.'
                    })
        if meta_schema not in node.registered_schema:
            raise HTTPError(
                http.BAD_REQUEST,
                data={
                    'message_short':
                    'Invalid schema',
                    'message_long':
                    'This registration has no registration supplment with that name.'
                })

        ret = _view_project(node, auth, primary=True)
        ret['node']['registered_schema'] = serialize_meta_schema(meta_schema)
        return ret
    else:
        status.push_status_message(
            'You have been redirected to the project\'s registrations page. From here you can initiate a new Draft Registration to complete the registration process',
            trust=False)
        return redirect(
            node.web_url_for('node_registrations',
                             view=kwargs.get('template')))