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

Allow catalogNumber format to be determined by CollectionObjectType #5431

Merged
merged 29 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
06c1ed6
Allow Field Formatters to reference field they format
melton-jason Nov 19, 2024
3e713c6
Merge remote-tracking branch 'origin/production' into issue-5232
melton-jason Nov 19, 2024
17275b8
Add catalognumformatname to cot
melton-jason Nov 20, 2024
f3fd280
Change models + update datamodel
melton-jason Nov 21, 2024
9897241
Define picklists for fields expecting catalognumber format name
melton-jason Nov 21, 2024
668fbce
Merge remote-tracking branch 'origin/production' into issue-5232
melton-jason Nov 21, 2024
1db84c1
Add migration to handle COT catnum format name in schema config
melton-jason Nov 21, 2024
a5aabf0
Merge remote-tracking branch 'origin/production' into issue-5232
melton-jason Nov 22, 2024
0105c6d
Pass app registry to permission initialization
melton-jason Nov 25, 2024
a870b74
Write a migration to fix schema config bugs from other migrations
melton-jason Nov 25, 2024
a2349fe
Update migration for COT -> catalogNuberFormatName
melton-jason Nov 25, 2024
f789f15
Add isrequired to schema config field fixes
melton-jason Nov 25, 2024
f453cf9
Resolve incorrect app for models in permission migration
melton-jason Nov 26, 2024
56fb288
Merge remote-tracking branch 'origin/production' into issue-5232
melton-jason Nov 26, 2024
48b588c
Correct table label generation in schema config migrations
melton-jason Nov 26, 2024
fb1cec9
Autonumber CO's based on co -> cot -> catalogNumberFormatName
melton-jason Dec 3, 2024
7478dd3
Merge remote-tracking branch 'origin/production' into issue-5232
melton-jason Dec 3, 2024
6778868
Merge branch 'production' into issue-5232
melton-jason Dec 3, 2024
5186bbd
Modify default COT form to include catalogNumberFormatName
melton-jason Dec 3, 2024
bdcbec0
Merge branch 'production' into issue-5232
melton-jason Dec 4, 2024
e9a62dc
Make migrations_utils a python module
melton-jason Dec 4, 2024
7ac3ce2
Merge branch 'issue-5232' of https://github.com/specify/specify7 into…
melton-jason Dec 4, 2024
9225785
Resolve faulty import
melton-jason Dec 4, 2024
807f439
Resolve ordering of recently merged migrations
melton-jason Dec 4, 2024
b7bd298
Resolve failing backend tests
melton-jason Dec 4, 2024
be0b5c6
Update frontend testing files
melton-jason Dec 4, 2024
946ca8e
Write simple frontend tests for catNum being dictated by COT
melton-jason Dec 4, 2024
3618ba1
Remove unused import
melton-jason Dec 4, 2024
6a35ba4
Merge remote-tracking branch 'origin/production' into issue-5232
melton-jason Dec 7, 2024
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
6 changes: 4 additions & 2 deletions config/common/common.views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2083,10 +2083,12 @@
<row>
<cell type="label" labelfor="1"/>
<cell type="field" id="1" name="name" uitype="text" isrequired="true"/>
<cell type="label" labelfor="2"/>
<cell type="field" id="2" name="catalogNumberFormatName" uitype="combobox"/>
</row>
<row>
<cell type="label" labelfor="2"/>
<cell type="field" id="2" name="taxontreedef" uitype="querycbx" isrequired="true"/>
<cell type="label" labelfor="3"/>
<cell type="field" id="3" name="taxontreedef" uitype="querycbx" isrequired="true"/>
</row>
</rows>
</viewdef>
Expand Down
7 changes: 5 additions & 2 deletions specifyweb/context/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
check_permission_targets, skip_collection_access_check, query_pt, \
CollectionAccessPT
from specifyweb.specify.models import Collection, Institution, \
Specifyuser, Spprincipal, Spversion
Specifyuser, Spprincipal, Spversion, Collectionobjecttype
from specifyweb.specify.schema import base_schema
from specifyweb.specify.api import uri_for_model
from specifyweb.specify.serialize_datamodel import datamodel_to_json
Expand Down Expand Up @@ -341,7 +341,10 @@ def domain(request):
'embeddedPaleoContext': collection.discipline.ispaleocontextembedded,
'paleoContextChildTable': collection.discipline.paleocontextchildtable,
'catalogNumFormatName': collection.catalognumformatname,
'defaultCollectionObjectType': uri_for_model(collection.collectionobjecttype.__class__, collection.collectionobjecttype.id) if collection.collectionobjecttype is not None else None
'defaultCollectionObjectType': uri_for_model(collection.collectionobjecttype.__class__, collection.collectionobjecttype.id) if collection.collectionobjecttype is not None else None,
'collectionObjectTypeCatalogNumberFormats': {
uri_for_model(cot.__class__, cot.id): cot.catalognumberformatname for cot in collection.cotypes.all()
}
}

return HttpResponse(json.dumps(domain), content_type='application/json')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const fileNameTestSpec: TestDefinition = {
byYear: false,
}),
],
tables.CollectionObject
tables.CollectionObject,
tables.CollectionObject?.getLiteralField('catalogNumber')
),
testCases: [
['000.jpg', '000'],
Expand All @@ -79,7 +80,8 @@ const fileNameTestSpec: TestDefinition = {
byYear: false,
}),
],
tables.CollectionObject
tables.CollectionObject,
tables.CollectionObject?.getLiteralField('catalogNumber')
),
testCases: [
['45265.jpg', '45265'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('serializeResource', () => {
isNot: false,
isPrompt: null,
isRelFld: null,
isStrict: false,
modifiedByAgent: null,
operEnd: null,
operStart: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ requireContext();
test('domain data is fetched and parsed correctly', async () =>
expect(fetchContext).resolves.toEqual({
catalogNumFormatName: 'CatalogNumberNumeric',
collectionObjectTypeCatalogNumberFormats: {
'/api/specify/collectionobjecttype/1/': null,
'/api/specify/collectionobjecttype/2/': 'CatalogNumber',
'/api/specify/collectionobjecttype/3/': 'CatalogNumberNumericRegex',
},
domainLevelIds: {
collection: 4,
discipline: 3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* schema, but it's here for now.
*/

import type { RR, Writable } from '../../utils/types';
import type { IR, RR, Writable } from '../../utils/types';
import { load } from '../InitialContext';

type Schema = {
Expand All @@ -21,6 +21,7 @@ type Schema = {
readonly embeddedPaleoContext: boolean;
readonly paleoContextChildTable: string;
readonly catalogNumFormatName: string;
readonly collectionObjectTypeCatalogNumberFormats: IR<string | null>;
readonly defaultCollectionObjectType: string | null;
readonly orgHierarchy: readonly [
'CollectionObject',
Expand Down Expand Up @@ -51,6 +52,8 @@ const schemaBase: Writable<Schema> = {
paleoContextChildTable: undefined!,
catalogNumFormatName: undefined!,

collectionObjectTypeCatalogNumberFormats: {},

// Default collectionObjectType for the collection
defaultCollectionObjectType: undefined!,

Expand Down Expand Up @@ -94,6 +97,8 @@ export const fetchContext = load<
schemaBase.embeddedPaleoContext = data.embeddedPaleoContext;
schemaBase.paleoContextChildTable = data.paleoContextChildTable;
schemaBase.catalogNumFormatName = data.catalogNumFormatName;
schemaBase.collectionObjectTypeCatalogNumberFormats =
data.collectionObjectTypeCatalogNumberFormats;
schemaBase.defaultCollectionObjectType = data.defaultCollectionObjectType;
return schemaBase;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import type { IR, RA, RR } from '../../utils/types';
import { getField } from './helpers';
import type { TableFields } from './helperTypes';
import type { SpecifyResource } from './legacyTypes';
import { schema } from './schema';
import { LiteralField, Relationship } from './specifyField';
import type { SpecifyTable } from './specifyTable';
import type { Tables } from './types';
import type { CollectionObject, Tables } from './types';

export const schemaAliases: RR<'', IR<string>> & {
readonly [TABLE_NAME in keyof Tables]?: IR<TableFields<Tables[TABLE_NAME]>>;
Expand Down Expand Up @@ -106,12 +107,21 @@ export const schemaExtras: {
collection.otherSideName = 'collectionObjects';

/*
* Catalog number formatter is taken from the field on the collection,
* if present
* The Catalog number format is determined in the following heirarchy,
* using the 'next level' if the format is not defined (or falsy):
*
* - The Collection Object's collectionObjectType -> catalogNumberFormatName
* - Collection -> catalogNumFormatName
* - Schema Configuration format for catalognumber
*/
const catalognumber = getField(table, 'catalogNumber');
catalognumber.getFormat = (): string | undefined =>
schema.catalogNumFormatName ||
catalognumber.getFormat = (
resource?: SpecifyResource<CollectionObject>
): string | undefined =>
(schema.collectionObjectTypeCatalogNumberFormats[
resource?.get('collectionObjectType') ?? ''
] ??
schema.catalogNumFormatName) ||
LiteralField.prototype.getFormat.call(catalognumber);
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { camelToHuman } from '../../utils/utils';
import { type UiFormatter, getUiFormatters } from '../FieldFormatters';
import { isTreeTable } from '../InitialContext/treeRanks';
import { getFrontEndPickLists } from '../PickLists/definitions';
import { AnySchema } from './helperTypes';
import type { SpecifyResource } from './legacyTypes';
import { schema, unescape } from './schema';
import { getFieldOverwrite, getGlobalFieldOverwrite } from './schemaOverrides';
Expand Down Expand Up @@ -273,13 +274,15 @@ export class LiteralField extends FieldBase {
}

// Returns the name of the UIFormatter for the field from the schema config.
public getFormat(): string | undefined {
public getFormat(_resource?: SpecifyResource<AnySchema>): string | undefined {
return this.localization.format ?? undefined;
}

// Returns the UIFormatter for the field specified in the schema config.
public getUiFormatter(): UiFormatter | undefined {
return getUiFormatters()[this.getFormat() ?? ''];
public getUiFormatter(
resource?: SpecifyResource<AnySchema>
): UiFormatter | undefined {
return getUiFormatters()[this.getFormat(resource) ?? ''];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6471,6 +6471,7 @@ export type Spdataset = {
export type CollectionObjectType = {
readonly tableName: 'CollectionObjectType';
readonly fields: {
readonly catalogNumberFormatName: string | null;
readonly name: string;
readonly text1: string | null;
readonly text2: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`field formatters are fetched and parsed correctly 1`] = `
{
"AccessionNumber": UiFormatter {
"field": "[literalField Accession.accessionNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -50,6 +51,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "AccessionNumber",
},
"AccessionNumberByYear": UiFormatter {
"field": "[literalField Accession.accessionNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -97,6 +99,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "AccessionNumberByYear",
},
"AccessionStringFormatter": UiFormatter {
"field": "[literalField Accession.accessionNumber]",
"fields": [
AlphaNumberField {
"autoIncrement": false,
Expand All @@ -112,6 +115,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "AccessionStringFormatter",
},
"CatalogNumber": UiFormatter {
"field": "[literalField CollectionObject.catalogNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -143,6 +147,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "CatalogNumber",
},
"CatalogNumberAlphaNumByYear": UiFormatter {
"field": "[literalField CollectionObject.catalogNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -174,6 +179,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "CatalogNumberAlphaNumByYear",
},
"CatalogNumberNumeric": CatalogNumberNumeric {
"field": "[literalField CollectionObject.catalogNumber]",
"fields": [
CatalogNumberNumericField {
"autoIncrement": true,
Expand All @@ -189,6 +195,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "Catalog Number Numeric",
},
"CatalogNumberNumericRegex": UiFormatter {
"field": "[literalField CollectionObject.catalogNumber]",
"fields": [
RegexField {
"autoIncrement": false,
Expand All @@ -204,12 +211,14 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "CatalogNumberNumericRegex",
},
"Date": UiFormatter {
"field": undefined,
"fields": [],
"isSystem": true,
"table": undefined,
"title": "Date",
},
"DeaccessionNumber": UiFormatter {
"field": "[literalField Deaccession.deaccessionNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -257,6 +266,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "DeaccessionNumber",
},
"GiftNumber": UiFormatter {
"field": "[literalField Gift.giftNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -288,6 +298,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "GiftNumber",
},
"InfoRequestNumber": UiFormatter {
"field": "[literalField InfoRequest.infoReqNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -319,6 +330,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "InfoRequestNumber",
},
"KUITeach": CatalogNumberNumeric {
"field": "[literalField CollectionObject.catalogNumber]",
"fields": [
CatalogNumberNumericField {
"autoIncrement": true,
Expand All @@ -334,6 +346,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "Catalog Number Numeric",
},
"LoanNumber": UiFormatter {
"field": "[literalField Loan.loanNumber]",
"fields": [
YearField {
"autoIncrement": false,
Expand Down Expand Up @@ -365,6 +378,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "LoanNumber",
},
"NumericBigDecimal": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -380,6 +394,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericBigDecimal",
},
"NumericByte": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -395,6 +410,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericByte",
},
"NumericDouble": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -410,6 +426,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericDouble",
},
"NumericFloat": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -425,6 +442,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericFloat",
},
"NumericInteger": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -440,6 +458,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericInteger",
},
"NumericLong": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -455,6 +474,7 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericLong",
},
"NumericShort": UiFormatter {
"field": undefined,
"fields": [
NumericField {
"autoIncrement": false,
Expand All @@ -470,24 +490,28 @@ exports[`field formatters are fetched and parsed correctly 1`] = `
"title": "NumericShort",
},
"PartialDate": UiFormatter {
"field": undefined,
"fields": [],
"isSystem": false,
"table": undefined,
"title": "PartialDate",
},
"PartialDateMonth": UiFormatter {
"field": undefined,
"fields": [],
"isSystem": false,
"table": undefined,
"title": "PartialDateMonth",
},
"PartialDateYear": UiFormatter {
"field": undefined,
"fields": [],
"isSystem": false,
"table": undefined,
"title": "PartialDateYear",
},
"SearchDate": UiFormatter {
"field": undefined,
"fields": [],
"isSystem": true,
"table": undefined,
Expand Down
Loading
Loading