Beispiel #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.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')))
Beispiel #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))
Beispiel #3
0
def serialize_draft_registration(draft, auth=None):

    import sys
    sys.path.insert(0, submodule_path('utils.py'))
    from website.profile.utils import serialize_user  # noqa

    node = draft.branched_from

    return {
        'pk': draft._id,
        'branched_from': serialize_node(draft.branched_from, auth),
        'initiator': serialize_user(draft.initiator, full=True),
        'registration_metadata': draft.registration_metadata,
        'registration_schema':
        serialize_meta_schema(draft.registration_schema),
        'initiated': str(draft.datetime_initiated),
        'updated': str(draft.datetime_updated),
        'flags': draft.flags,
        'requires_approval': draft.requires_approval,
        #'is_pending_approval': draft.is_pending_review,
        #'is_approved': draft.is_approved,
        'approval': serialize_draft_registration_approval(draft.approval)
        # 'urls': {
        #     'edit': node.web_url_for('edit_draft_registration_page', draft_id=draft._id),
        #     'before_register': node.api_url_for('project_before_register'),
        #     'register': node.api_url_for('register_draft_registration', draft_id=draft._id),
        #     'register_page': node.web_url_for('draft_before_register_page', draft_id=draft._id),
        #     'registrations': node.web_url_for('node_registrations')
        # }
    }
def serialize_draft_registration(draft, auth=None):
    
    import sys
    sys.path.insert(0, submodule_path('utils.py'))
    from website.profile.utils import serialize_user  # noqa
    #import ipdb; ipdb.set_trace()
    node = draft.branched_from
    
    return {
        'pk': draft._id,
        'branched_from': serialize_node(draft.branched_from, auth),
        'initiator': serialize_user(draft.initiator, full=True),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': str(draft.datetime_initiated),
        'updated': str(draft.datetime_updated),
        'config': draft.config or {},
        'flags': draft.flags,
        # 'urls': {
        #     'edit': node.web_url_for('edit_draft_registration_page', draft_id=draft._id),
        #     'before_register': node.api_url_for('project_before_register'),
        #     'register': node.api_url_for('register_draft_registration', draft_id=draft._id),
        #     'register_page': node.web_url_for('draft_before_register_page', draft_id=draft._id),
        #     'registrations': node.web_url_for('node_registrations')
        # }
    }
Beispiel #5
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')))
Beispiel #6
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schemas = []
    if include == 'latest':
        schema_names = list(MetaSchema.objects.all().values_list('name', flat=True).distinct())
        for name in schema_names:
            meta_schema_set = MetaSchema.find(
                Q('name', 'eq', name) &
                Q('schema_version', 'eq', 2)
            )
            meta_schemas = meta_schemas + [s for s in meta_schema_set]
    else:
        meta_schemas = MetaSchema.find()
    meta_schemas = [
        schema
        for schema in meta_schemas
        if schema.active
    ]
    meta_schemas.sort(key=lambda a: METASCHEMA_ORDERING.index(a.name))
    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
Beispiel #7
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schema_collection = database['metaschema']

    meta_schemas = []
    if include == 'latest':
        schema_names = meta_schema_collection.distinct('name')
        for name in schema_names:
            meta_schema_set = MetaSchema.find(
                Q('name', 'eq', name) & Q('schema_version', 'eq', 2))
            meta_schemas = meta_schemas + [s for s in meta_schema_set]
    else:
        meta_schemas = MetaSchema.find()
    meta_schemas = [
        schema for schema in meta_schemas if schema.name in ACTIVE_META_SCHEMAS
    ]
    meta_schemas.sort(key=lambda a: ACTIVE_META_SCHEMAS.index(a.name))
    return {
        'meta_schemas':
        [serialize_meta_schema(ms) for ms in meta_schemas[:count]]
    }, http.OK
Beispiel #8
0
def serialize_draft_registration(draft, json_safe=True):
    if draft.branched_from is not None:
        url = furl(OSF_DOMAIN)
        url.path.add(draft.branched_from.url)
        node_url = url.url
    else:
        node_url = None
    registration_choice = draft.approval.meta.get('registration_choice', None)
    if registration_choice == EMBARGO:
        time = parser.parse(draft.approval.meta['embargo_end_date'])
        embargo = iso8601format(time) if json_safe else time
    else:
        embargo = IMMEDIATE

    return {
        'pk': draft._id,
        'initiator': serialize_user(draft.initiator),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': iso8601format(draft.datetime_initiated) if json_safe else draft.datetime_initiated,
        'updated': iso8601format(draft.datetime_updated) if json_safe else draft.datetime_updated,
        'submitted': iso8601format(draft.approval.initiation_date) if json_safe else draft.approval.initiation_date,
        'requires_approval': draft.requires_approval,
        'is_pending_approval': draft.is_pending_review,
        'is_approved': draft.is_approved,
        'is_rejected': draft.is_rejected,
        'notes': draft.notes,
        'proof_of_publication': draft.flags.get('proof_of_publication'),
        'payment_sent': draft.flags.get('payment_sent'),
        'assignee': draft.flags.get('assignee'),
        'title': draft.registration_metadata['q1']['value'],
        'embargo': embargo,
        'registered_node': node_url,
    }
Beispiel #9
0
def serialize_draft_registration(draft, json_safe=True):
    node_url = get_url(draft)

    embargo = get_embargo(draft, json_safe)

    submitted = None
    if draft.approval is not None:
        if json_safe:
            submitted = iso8601format(draft.approval.initiation_date)
        else:
            submitted = draft.approval.initiation_date

    return {
        'pk': draft._id,
        'initiator': serialize_user(draft.initiator),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': iso8601format(draft.datetime_initiated) if json_safe else draft.datetime_initiated,
        'updated': iso8601format(draft.datetime_updated) if json_safe else draft.datetime_updated,
        'submitted': submitted,
        'requires_approval': draft.requires_approval,
        'is_pending_approval': draft.is_pending_review,
        'is_approved': draft.is_approved,
        'is_rejected': draft.is_rejected,
        'notes': draft.notes,
        'proof_of_publication': draft.flags.get('proof_of_publication'),
        'payment_sent': draft.flags.get('payment_sent'),
        'assignee': draft.flags.get('assignee'),
        'title': draft.registration_metadata['q1']['value'],
        'embargo': embargo,
        'registered_node': node_url,
        'status': get_approval_status(draft),
        'logs': map(serialize_draft_logs, draft.status_logs),
    }
Beispiel #10
0
def serialize_draft_registration(draft, json_safe=True):
    node_url = get_url(draft)

    embargo = get_embargo(draft, json_safe)

    submitted = None
    if draft.approval is not None:
        if json_safe:
            submitted = iso8601format(draft.approval.initiation_date)
        else:
            submitted = draft.approval.initiation_date

    return {
        'pk': draft._id,
        'initiator': serialize_user(draft.initiator),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': iso8601format(draft.datetime_initiated) if json_safe else draft.datetime_initiated,
        'updated': iso8601format(draft.datetime_updated) if json_safe else draft.datetime_updated,
        'submitted': submitted,
        'requires_approval': draft.requires_approval,
        'is_pending_approval': draft.is_pending_review,
        'is_approved': draft.is_approved,
        'is_rejected': draft.is_rejected,
        'notes': draft.notes,
        'proof_of_publication': draft.flags.get('proof_of_publication'),
        'payment_sent': draft.flags.get('payment_sent'),
        'assignee': draft.flags.get('assignee'),
        'title': draft.registration_metadata['q1']['value'],
        'embargo': embargo,
        'registered_node': node_url,
        'status': get_approval_status(draft),
        'logs': list(map(serialize_draft_logs, draft.status_logs)),
    }
Beispiel #11
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schemas = []
    if include == 'latest':
        schema_names = list(MetaSchema.objects.all().values_list('name', flat=True).distinct())
        for name in schema_names:
            meta_schema_set = MetaSchema.find(
                Q('name', 'eq', name) &
                Q('schema_version', 'eq', 2)
            )
            meta_schemas = meta_schemas + [s for s in meta_schema_set]
    else:
        meta_schemas = MetaSchema.find()
    meta_schemas = [
        schema
        for schema in meta_schemas
        if schema.active
    ]
    meta_schemas.sort(key=lambda a: METASCHEMA_ORDERING.index(a.name))
    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
Beispiel #12
0
def serialize_draft_registration(draft, auth=None):
    
    import sys
    sys.path.insert(0, submodule_path('utils.py'))
    from website.profile.utils import serialize_user  # noqa

    node = draft.branched_from
    
    return {
        'pk': draft._id,
        'branched_from': serialize_node(draft.branched_from, auth),
        'initiator': serialize_user(draft.initiator, full=True),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': str(draft.datetime_initiated),
        'updated': str(draft.datetime_updated),
        'flags': draft.flags,
        'requires_approval': draft.requires_approval,
        #'is_pending_approval': draft.is_pending_review,
        #'is_approved': draft.is_approved,
        'approval': serialize_draft_registration_approval(draft.approval)
        # 'urls': {
        #     'edit': node.web_url_for('edit_draft_registration_page', draft_id=draft._id),
        #     'before_register': node.api_url_for('project_before_register'),
        #     'register': node.api_url_for('register_draft_registration', draft_id=draft._id),
        #     'register_page': node.web_url_for('draft_before_register_page', draft_id=draft._id),
        #     'registrations': node.web_url_for('node_registrations')
        # }
    }
Beispiel #13
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schema_collection = database['metaschema']

    meta_schemas = []
    if include == 'latest':
        schema_names = meta_schema_collection.distinct('name')
        for name in schema_names:
            meta_schema_set = MetaSchema.find(
                Q('name', 'eq', name) &
                Q('schema_version', 'eq', 2)
            )
            meta_schemas = meta_schemas + [s for s in meta_schema_set]
    else:
        meta_schemas = MetaSchema.find()
    meta_schemas = [
        schema
        for schema in meta_schemas
        if schema.name in ACTIVE_META_SCHEMAS
    ]
    meta_schemas.sort(key=lambda a: ACTIVE_META_SCHEMAS.index(a.name))
    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
Beispiel #14
0
def serialize_draft_registration(draft, json_safe=True):
    if draft.branched_from is not None:
        url = furl(OSF_DOMAIN)
        url.path.add(draft.branched_from.url)
        node_url = url.url
    else:
        node_url = None
    registration_choice = draft.approval.meta.get('registration_choice', None)
    if registration_choice == EMBARGO:
        time = parser.parse(draft.approval.meta['embargo_end_date'])
        embargo = iso8601format(time) if json_safe else time
    else:
        embargo = IMMEDIATE

    return {
        'pk':
        draft._id,
        'initiator':
        serialize_user(draft.initiator),
        'registration_metadata':
        draft.registration_metadata,
        'registration_schema':
        serialize_meta_schema(draft.registration_schema),
        'initiated':
        iso8601format(draft.datetime_initiated)
        if json_safe else draft.datetime_initiated,
        'updated':
        iso8601format(draft.datetime_updated)
        if json_safe else draft.datetime_updated,
        'submitted':
        iso8601format(draft.approval.initiation_date)
        if json_safe else draft.approval.initiation_date,
        'requires_approval':
        draft.requires_approval,
        'is_pending_approval':
        draft.is_pending_review,
        'is_approved':
        draft.is_approved,
        'is_rejected':
        draft.is_rejected,
        'notes':
        draft.notes,
        'proof_of_publication':
        draft.flags.get('proof_of_publication'),
        'payment_sent':
        draft.flags.get('payment_sent'),
        'assignee':
        draft.flags.get('assignee'),
        'title':
        draft.registration_metadata['q1']['value'],
        'embargo':
        embargo,
        'registered_node':
        node_url,
    }
Beispiel #15
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))
Beispiel #16
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schemas = RegistrationSchema.objects.filter(active=True)
    if include == 'latest':
        meta_schemas = RegistrationSchema.objects.get_latest_versions()

    meta_schemas = sorted(meta_schemas, key=order_schemas)

    return {
        'meta_schemas':
        [serialize_meta_schema(ms) for ms in meta_schemas[:count]]
    }, http_status.HTTP_200_OK
Beispiel #17
0
def serialize_draft_registration(draft, json_safe=True):

    return {
        'pk': draft._id,
        'initiator': serialize_user(draft.initiator),
        'registration_metadata': draft.registration_metadata,
        'registration_schema': serialize_meta_schema(draft.registration_schema),
        'initiated': iso8601format(draft.datetime_initiated) if json_safe else draft.datetime_initiated,
        'updated': iso8601format(draft.datetime_updated) if json_safe else draft.datetime_updated,
        'submitted': iso8601format(draft.approval.initiation_date) if json_safe else draft.approval.initiation_date,
        'requires_approval': draft.requires_approval,
        'is_pending_approval': draft.is_pending_review,
        'is_approved': draft.is_approved,
        'is_rejected': draft.is_rejected,
        'notes': draft.notes,
        'proof_of_publication': draft.flags.get('proof_of_publication'),
        'payment_sent': draft.flags.get('payment_sent'),
        'assignee': draft.flags.get('assignee'),
        'title': draft.registration_metadata['q1']['value'],
    }
Beispiel #18
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schemas = MetaSchema.objects.filter(active=True)
    if include == 'latest':
        meta_schemas.filter(schema_version=LATEST_SCHEMA_VERSION)

    meta_schemas = sorted(meta_schemas, key=lambda x: METASCHEMA_ORDERING.index(x.name))

    return {
        'meta_schemas': [
            serialize_meta_schema(ms) for ms in meta_schemas[:count]
        ]
    }, http.OK
Beispiel #19
0
def get_metaschemas(*args, **kwargs):
    """
    List metaschemas with which a draft registration may be created. Only fetch the newest version for each schema.

    :return: serialized metaschemas
    :rtype: dict
    """
    count = request.args.get('count', 100)
    include = request.args.get('include', 'latest')

    meta_schemas = RegistrationSchema.objects.filter(active=True)
    if include == 'latest':
        meta_schemas.filter(schema_version=LATEST_SCHEMA_VERSION)

    meta_schemas = sorted(meta_schemas,
                          key=lambda x: METASCHEMA_ORDERING.index(x.name))

    return {
        'meta_schemas':
        [serialize_meta_schema(ms) for ms in meta_schemas[:count]]
    }, http.OK
Beispiel #20
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')))
Beispiel #21
0
def serialize_node(node, auth, primary=False):
    """Build a JSON object containing everything needed to render
    project.view.mako.
    """
    user = auth.user

    parent = node.parent_node

    data = {
        'node': {
            '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 '',
            'url':
            node.url,
            'api_url':
            node.api_url,
            'absolute_url':
            node.absolute_url,
            'display_absolute_url':
            node.display_absolute_url,
            '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),
            'is_registration':
            node.is_registration,
            'is_retracted':
            node.is_retracted,
            'pending_retraction':
            node.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,
            'pending_embargo':
            node.pending_embargo,
            '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,
            'registered_meta':
            node.registered_meta,
            'registered_schema':
            serialize_meta_schema(node.registered_schema),
            'registration_count':
            len(node.node__registrations),
            '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':
            len(node.forks),
            'templated_count':
            len(node.templated_list),
            'watched_count':
            len(node.watchconfig__watched),
            'private_links': [x.to_json() for x in node.private_links_active],
            'points':
            len(node.get_points(deleted=False, folders=False)),
            'piwik_site_id':
            node.piwik_site_id,
            'comment_level':
            node.comment_level,
            'has_comments':
            bool(getattr(node, 'commented', [])),
            'has_children':
            bool(getattr(node, 'commented', False)),
            'identifiers': {
                'doi': node.get_identifier_value('doi'),
                'ark': node.get_identifier_value('ark'),
            },
        },
        'parent_node': {
            'exists':
            parent is not None,
            'id':
            parent._primary_key if parent else '',
            'title':
            parent.title if parent else '',
            'category':
            parent.category_display if parent else '',
            'url':
            parent.url if parent else '',
            'api_url':
            parent.api_url if parent else '',
            'absolute_url':
            parent.absolute_url if parent else '',
            'registrations_url':
            parent.web_url_for('node_registrations') if parent else '',
            'is_public':
            parent.is_public if parent else '',
            'is_contributor':
            parent.is_contributor(user) if parent else '',
            'can_view':
            parent.can_view(auth) if parent else False
        },
        'user': {
            'is_contributor': node.is_contributor(user),
            'is_admin_parent':
            parent.is_admin_parent(user) if parent else False,
            'can_edit': (node.can_edit(auth) and not node.is_registration),
            'has_read_permissions': node.has_permission(user, 'read'),
            'permissions': node.get_permissions(user) if user else [],
            'is_watching': user.is_watching(node) if user else False,
            'piwik_token': user.piwik_token if user else '',
            'id': user._id if user else None,
            'username': user.username if user else None,
            'fullname': user.fullname if user else '',
            'can_comment': node.can_comment(auth),
        },
        # TODO: Namespace with nested dicts
        'addons_enabled': node.get_addon_names(),
        'node_categories': Node.CATEGORY_MAP,
    }
    return data
def get_metaschema(schema_name, schema_version=1):
    meta_schema = get_schema_or_fail(
        Q('name', 'eq', schema_name) &
        Q('schema_version', 'eq', schema_version)
    )
    return serialize_meta_schema(meta_schema), http.OK
Beispiel #23
0
def serialize_node(node, auth, primary=False):
    """Build a JSON object containing everything needed to render
    project.view.mako.
    """
    user = auth.user

    parent = node.parent_node

    data = {
        'node': {
            '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 '',
            'url': node.url,
            'api_url': node.api_url,
            'absolute_url': node.absolute_url,
            'display_absolute_url': node.display_absolute_url,
            '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),
            'is_registration': node.is_registration,
            'is_retracted': node.is_retracted,
            'pending_retraction': node.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,
            'pending_embargo': node.pending_embargo,
            '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,
            'registered_meta': node.registered_meta,
            'registered_schema': serialize_meta_schema(node.registered_schema),
            'registration_count': len(node.node__registrations),
            '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': len(node.forks),
            'templated_count': len(node.templated_list),
            'watched_count': len(node.watchconfig__watched),
            'private_links': [x.to_json() for x in node.private_links_active],
            'points': len(node.get_points(deleted=False, folders=False)),
            'piwik_site_id': node.piwik_site_id,
            'comment_level': node.comment_level,
            'has_comments': bool(getattr(node, 'commented', [])),
            'has_children': bool(getattr(node, 'commented', False)),
            'identifiers': {
                'doi': node.get_identifier_value('doi'),
                'ark': node.get_identifier_value('ark'),
            },
        },
        'parent_node': {
            'exists': parent is not None,
            'id': parent._primary_key if parent else '',
            'title': parent.title if parent else '',
            'category': parent.category_display if parent else '',
            'url': parent.url if parent else '',
            'api_url': parent.api_url if parent else '',
            'absolute_url': parent.absolute_url if parent else '',
            'registrations_url': parent.web_url_for('node_registrations') if parent else '',
            'is_public': parent.is_public if parent else '',
            'is_contributor': parent.is_contributor(user) if parent else '',
            'can_view': parent.can_view(auth) if parent else False
        },
        'user': {
            'is_contributor': node.is_contributor(user),
            'is_admin_parent': parent.is_admin_parent(user) if parent else False,
            'can_edit': (node.can_edit(auth)
                         and not node.is_registration),
            'has_read_permissions': node.has_permission(user, 'read'),
            'permissions': node.get_permissions(user) if user else [],
            'is_watching': user.is_watching(node) if user else False,
            'piwik_token': user.piwik_token if user else '',
            'id': user._id if user else None,
            'username': user.username if user else None,
            'fullname': user.fullname if user else '',
            'can_comment': node.can_comment(auth),
        },
        # TODO: Namespace with nested dicts
        'addons_enabled': node.get_addon_names(),
        'node_categories': Node.CATEGORY_MAP,
    }
    return data
Beispiel #24
0
def get_metaschema(schema_name, schema_version=1):
    meta_schema = get_schema_or_fail(
        Q('name', 'eq', schema_name)
        & Q('schema_version', 'eq', schema_version))
    return serialize_meta_schema(meta_schema), http.OK