Exemple #1
0
def create_product_id(key, data, errors, context):
    general_non_data_types = (u'publication', u'video', u'conference',
                              u'service', u'pumf', u'generic')
    general_data_types = (u'view', u'indicator', u'chart')
    # if there was an error before calling our validator
    # don't bother with our validation
    if errors[key] or errors[('subject_codes', )] or errors[(
            'top_parent_id', )]:
        return

    product_id_new = _data_lookup(('product_id_new', ), data)
    if product_id_new and is_legacy_id(product_id_new):
        return

    data_set_type = _data_lookup(('type', ), data)
    # make sure subject_codes processed
    shortcode_validate(('subject_codes', ), data, errors, context)
    subject_codes = shortcode_output(_data_lookup(('subject_codes', ), data))
    top_parent_id = _data_lookup(('top_parent_id', ), data)

    if data_set_type in general_non_data_types:
        try:
            product_id_new = h.next_non_data_product_id(
                subject_code=subject_codes[0][:2],
                product_type_code=_data_lookup(('product_type_code', ), data))
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[('subject_codes', )].append(_(ve.error_summary[u'Message']))
            errors[key].append(_('PID could not be generated'))
            return
        except IndexError:
            errors[('subject_codes', )].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
    elif data_set_type == u'issue':
        if not top_parent_id:
            errors[('top_parent_id', )].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
        issue_number = _data_lookup('issue_number', data)
        if not issue_number:
            issue_number = h.next_issue_number(top_parent_id)
            _data_update(issue_number, ('issue_number', ), data)
        product_id_new = u'{pid}{issue_number}'.format(
            pid=top_parent_id, issue_number=issue_number)
        data[key] = product_id_new
        return product_id_new
    elif data_set_type == u'article':
        if not top_parent_id:
            errors[('top_parent_id', )].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
        issue_number = _data_lookup('issue_number', data)
        if not issue_number:
            issue_number = h.next_issue_number(top_parent_id)
            _data_update(issue_number, ('issue_number', ), data)
        try:
            if is_legacy_id(top_parent_id):
                product_id_new = get_next_legacy_article_id(
                    context=context,
                    data_dict={
                        'parentProduct':
                        u'{top_parent_id}{issue_number}'.format(
                            top_parent_id=top_parent_id,
                            issue_number=issue_number)
                    })
            else:
                product_id_new = h.next_article_id(top_parent_id=top_parent_id,
                                                   issue_number=issue_number)
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[key].append(_(ve))
            return
    elif data_set_type == u'cube':
        try:
            product_id_new = get_next_cube_id(
                context=context,
                data_dict={'subjectCode': subject_codes[0][:2]})
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[('subject_codes', )].append(_(ve.error_dict['message']))
            errors[key].append(_('PID could not be generated'))
            return
        except IndexError:
            errors[('subject_codes', )].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
    elif data_set_type in general_data_types:
        if not top_parent_id or top_parent_id is missing:
            errors[('top_parent_id', )].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
        try:
            product_id_new = get_next_product_id(
                context, {
                    'parentProductId': top_parent_id,
                    'productType': data.get((u'product_type_code', ))
                })
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[('top_parent_id', )].append(ve.error_dict['message'])
            errors[key].append(_('PID could not be generated'))
            return
        except NotFound as e:
            errors[('top_parent_id', )].append(e[0])
            errors[key].append(_('PID could not be generated'))
            return
    else:
        errors[key].append(
            _('create_product_id not yet implemented for {data_set_type}'.
              format(data_set_type=data_set_type)))

    return
Exemple #2
0
def create_product_id(key, data, errors, context):
    general_non_data_types = (
        u'publication',
        u'video',
        u'conference',
        u'service',
        u'pumf',
        u'generic'
    )
    general_data_types = (
        u'view',
        u'indicator',
        u'chart'
    )
    # if there was an error before calling our validator
    # don't bother with our validation
    if errors[key]:
        return

    product_id_new = _data_lookup(('product_id_new',), data)
    if product_id_new:
        return

    data_set_type = _data_lookup(('type',), data)
    # make sure subject_codes processed
    shortcode_validate(('subject_codes',), data, errors, context)
    subject_codes = shortcode_output(_data_lookup(('subject_codes',), data))
    top_parent_id = _data_lookup(('top_parent_id',), data)

    if data_set_type in general_non_data_types:
        if len(subject_codes) != 1 or not re.match('\d\d', subject_codes[0]):
            errors[key].append(_(
                'exactly one 2-digit subject code must be provided '
                'when creating a new product'
            ))
            return

        try:
            product_id_new = h.next_non_data_product_id(
                subject_code=subject_codes[0],
                product_type_code=_data_lookup(('product_type_code',), data)
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[key].append(_(ve))
            return
    elif data_set_type == u'article':
        if not top_parent_id or top_parent_id is missing:
            errors[key].append(_('missing top_parent_id'))
            return
        issue_number = _data_lookup(('issue_number',), data)
        if not issue_number or issue_number is missing:
            errors[key].append(_('missing issue_number'))
            return
        try:
            product_id_new = h.next_article_id(
                top_parent_id=top_parent_id,
                issue_number=issue_number
            )
        except ValidationError as ve:
            errors[key].append(_(ve))
            return
        data[key] = product_id_new
        return product_id_new
    elif data_set_type == u'cube':
        if len(subject_codes) != 1 or not re.match('\d\d', subject_codes[0]):
            errors[key].append(_(
                'exactly one 2-digit subject code must be provided '
                'when creating a new product'
            ))
            return

        try:
            product_id_new = get_next_cube_id(
                context,
                {'subjectCode': subject_codes[0]}
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[key].append(ve)
            return
    elif data_set_type in general_data_types:
        if not top_parent_id or top_parent_id is missing:
            errors[key].append(_('missing top_parent_id'))
            return
        try:
            product_id_new = get_next_product_id(
                context,
                {
                    'parentProductId': top_parent_id,
                    'productType': data.get((u'product_type_code',))
                }
            )
            data[key] = product_id_new
            return product_id_new
        except (ValidationError, ObjectNotFound) as e:
            errors[key].append(e)
            return
    else:
        errors[key].append(_(
            'create_product_id not yet implemented for {data_set_type}'.format(
                data_set_type=data_set_type
            )
        ))

    return
Exemple #3
0
def create_product_id(key, data, errors, context):
    general_non_data_types = (
        u'publication',
        u'video',
        u'conference',
        u'service',
        u'pumf',
        u'generic'
    )
    general_data_types = (
        u'view',
        u'indicator',
        u'chart'
    )
    # if there was an error before calling our validator
    # don't bother with our validation
    if errors[key] or errors[('subject_codes',)] or errors[('top_parent_id',)]:
        return

    # product_id_new = _data_lookup(('product_id_new',), data)
    # if product_id_new:
    #     return
    data_set_type = _data_lookup(('type',), data)
    # make sure subject_codes processed
    shortcode_validate(('subject_codes',), data, errors, context)
    subject_codes = shortcode_output(_data_lookup(('subject_codes',), data))
    top_parent_id = _data_lookup(('top_parent_id',), data)

    if data_set_type in general_non_data_types:
        try:
            product_id_new = h.next_non_data_product_id(
                subject_code=subject_codes[0][:2],
                product_type_code=_data_lookup(('product_type_code',), data)
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[('subject_codes',)].append(_(ve.error_summary[u'Message']))
            errors[key].append(_('PID could not be generated'))
            return
        except IndexError:
            errors[('subject_codes',)].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
    elif data_set_type == u'article':
        if not top_parent_id:
            errors[('top_parent_id',)].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
        issue_number = _data_lookup('issue_number', data)
        if not issue_number:
            errors[('issue_number',)].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
        try:
            if is_legacy_id(top_parent_id):
                product_id_new = get_next_legacy_article_id(
                    context=context,
                    data_dict={
                        'parentProduct': u'{top_parent_id}{issue_number}'
                                         .format(
                                            top_parent_id=top_parent_id,
                                            issue_number=issue_number
                                         )
                        }
                )
            else:
                product_id_new = h.next_article_id(
                    top_parent_id=top_parent_id,
                    issue_number=issue_number
                )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[key].append(_(ve))
            return
    elif data_set_type == u'cube':
        try:
            product_id_new = get_next_cube_id(
                context=context,
                data_dict={'subjectCode': subject_codes[0][:2]}
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[('subject_codes',)].append(_(ve.error_dict['message']))
            errors[key].append(_('PID could not be generated'))
            return
        except IndexError:
            errors[('subject_codes',)].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
    elif data_set_type in general_data_types:
        if not top_parent_id or top_parent_id is missing:
            errors[('top_parent_id',)].append(_('Missing value'))
            errors[key].append(_('PID could not be generated'))
            return
        try:
            product_id_new = get_next_product_id(
                context,
                {
                    'parentProductId': top_parent_id,
                    'productType': data.get((u'product_type_code',))
                }
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[('top_parent_id',)].append(ve.error_dict['message'])
            errors[key].append(_('PID could not be generated'))
            return
        except NotFound as e:
            errors[('top_parent_id',)].append(e[0])
            errors[key].append(_('PID could not be generated'))
            return
    else:
        errors[key].append(_(
            'create_product_id not yet implemented for {data_set_type}'.format(
                data_set_type=data_set_type
            )
        ))

    return
def create_product_id(key, data, errors, context):
    general_non_data_types = (u"publication", u"video", u"conference", u"service", u"pumf", u"generic")
    general_data_types = (u"view", u"indicator", u"chart")
    # if there was an error before calling our validator
    # don't bother with our validation
    if errors[key] or errors[("subject_codes",)] or errors[("top_parent_id",)]:
        return

    product_id_new = _data_lookup(("product_id_new",), data)
    if product_id_new and is_legacy_id(product_id_new):
        return

    data_set_type = _data_lookup(("type",), data)
    # make sure subject_codes processed
    shortcode_validate(("subject_codes",), data, errors, context)
    subject_codes = shortcode_output(_data_lookup(("subject_codes",), data))
    top_parent_id = _data_lookup(("top_parent_id",), data)

    if data_set_type in general_non_data_types:
        try:
            product_id_new = h.next_non_data_product_id(
                subject_code=subject_codes[0][:2], product_type_code=_data_lookup(("product_type_code",), data)
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[("subject_codes",)].append(_(ve.error_summary[u"Message"]))
            errors[key].append(_("PID could not be generated"))
            return
        except IndexError:
            errors[("subject_codes",)].append(_("Missing value"))
            errors[key].append(_("PID could not be generated"))
            return
    elif data_set_type == u"issue":
        if not top_parent_id:
            errors[("top_parent_id",)].append(_("Missing value"))
            errors[key].append(_("PID could not be generated"))
            return
        issue_number = _data_lookup("issue_number", data)
        if not issue_number:
            issue_number = h.next_issue_number(top_parent_id)
            _data_update(issue_number, ("issue_number",), data)
        product_id_new = u"{pid}{issue_number}".format(pid=top_parent_id, issue_number=issue_number)
        data[key] = product_id_new
        return product_id_new
    elif data_set_type == u"article":
        if not top_parent_id:
            errors[("top_parent_id",)].append(_("Missing value"))
            errors[key].append(_("PID could not be generated"))
            return
        issue_number = _data_lookup("issue_number", data)
        if not issue_number:
            issue_number = h.next_issue_number(top_parent_id)
            _data_update(issue_number, ("issue_number",), data)
        try:
            if is_legacy_id(top_parent_id):
                product_id_new = get_next_legacy_article_id(
                    context=context,
                    data_dict={
                        "parentProduct": u"{top_parent_id}{issue_number}".format(
                            top_parent_id=top_parent_id, issue_number=issue_number
                        )
                    },
                )
            else:
                product_id_new = h.next_article_id(top_parent_id=top_parent_id, issue_number=issue_number)
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[key].append(_(ve))
            return
    elif data_set_type == u"cube":
        try:
            product_id_new = get_next_cube_id(context=context, data_dict={"subjectCode": subject_codes[0][:2]})
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[("subject_codes",)].append(_(ve.error_dict["message"]))
            errors[key].append(_("PID could not be generated"))
            return
        except IndexError:
            errors[("subject_codes",)].append(_("Missing value"))
            errors[key].append(_("PID could not be generated"))
            return
    elif data_set_type in general_data_types:
        if not top_parent_id or top_parent_id is missing:
            errors[("top_parent_id",)].append(_("Missing value"))
            errors[key].append(_("PID could not be generated"))
            return
        try:
            product_id_new = get_next_product_id(
                context, {"parentProductId": top_parent_id, "productType": data.get((u"product_type_code",))}
            )
            data[key] = product_id_new
            return product_id_new
        except ValidationError as ve:
            errors[("top_parent_id",)].append(ve.error_dict["message"])
            errors[key].append(_("PID could not be generated"))
            return
        except NotFound as e:
            errors[("top_parent_id",)].append(e[0])
            errors[key].append(_("PID could not be generated"))
            return
    else:
        errors[key].append(
            _("create_product_id not yet implemented for {data_set_type}".format(data_set_type=data_set_type))
        )

    return