Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awards/schema.py: read app config for alternate funding validation #429

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,13 @@ const CustomFundingSchema = Yup.object().shape({
id: Yup.string().required(i18next.t("Funder is required.")),
}),
award: Yup.object().shape({
title: Yup.string().test({
name: "testTitle",
message: i18next.t("Title must be set alongside number."),
test: function testTitle(value) {
const { number } = this.parent;

if (number && !value) {
return false;
}

return true;
},
}),
number: Yup.string().test({
name: "testNumber",
message: i18next.t("Number must be set alongside title."),
test: function testNumber(value) {
const { title } = this.parent;

if (title && !value) {
return false;
}

return true;
},
}),
title: Yup.string(),
number: Yup.string(),
url: Yup.string()
.url(i18next.t("URL must be valid."))
.test({
name: "validateUrlDependencies",
message: i18next.t("URL must be set alongside title and number."),
message: i18next.t("URL must be set alongside title or number."),
test: function testUrl(value) {
const { title, number } = this.parent;

Expand Down
7 changes: 5 additions & 2 deletions invenio_vocabularies/contrib/awards/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in invenio_vocabularies/contrib/awards/schema.py

View workflow job for this annotation

GitHub Actions / Python / Tests (3.9, postgresql14, opensearch2)

isort-check """Awards schema.""" -from flask import current_app from functools import partial +from flask import current_app from invenio_i18n import lazy_gettext as _ from marshmallow import Schema, ValidationError, fields, validate, validates_schema from marshmallow_utils.fields import IdentifierSet, SanitizedUnicode

Check failure on line 1 in invenio_vocabularies/contrib/awards/schema.py

View workflow job for this annotation

GitHub Actions / Python / Tests (3.12, postgresql14, opensearch2)

isort-check """Awards schema.""" -from flask import current_app from functools import partial +from flask import current_app from invenio_i18n import lazy_gettext as _ from marshmallow import Schema, ValidationError, fields, validate, validates_schema from marshmallow_utils.fields import IdentifierSet, SanitizedUnicode
#
# Copyright (C) 2021-2024 CERN.
#
Expand All @@ -8,6 +8,7 @@

"""Awards schema."""

from flask import current_app
tmorrell marked this conversation as resolved.
Show resolved Hide resolved
from functools import partial

from invenio_i18n import lazy_gettext as _
Expand Down Expand Up @@ -90,9 +91,11 @@
id_ = data.get("id")
number = data.get("number")
title = data.get("title")
if not id_ and not (number and title):

if not id_ and not (number or title):
raise ValidationError(
_("An existing id or number/title must be present."), "award"
_("An existing id or either number or title must be present."),
"award",
)


Expand Down
Loading