Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1705 from open-apparel-registry/feature/jcw/raw-f…
Browse files Browse the repository at this point in the history
…acility-processing-types
  • Loading branch information
jwalgran committed Mar 14, 2022
2 parents 78ceaf4 + 8719433 commit e731760
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- Allow submitting non-taxonomy facility type and processing type [#1705](https://github.com/open-apparel-registry/open-apparel-registry/pull/1705)

### Deprecated

### Removed
Expand Down
18 changes: 16 additions & 2 deletions src/app/src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,26 @@ export const EXTENDED_FIELD_TYPES = [
{
label: 'Processing Type',
fieldName: 'processing_type',
formatValue: v => v.matched_values.map(val => val[3]),
formatValue: v => {
const rawValues = Array.isArray(v.raw_values)
? v.raw_values
: v.raw_values.toString().split('|');
return v.matched_values.map((val, i) =>
val[3] !== null ? val[3] : rawValues[i],
);
},
},
{
label: 'Facility Type',
fieldName: 'facility_type',
formatValue: v => v.matched_values.map(val => val[2]),
formatValue: v => {
const rawValues = Array.isArray(v.raw_values)
? v.raw_values
: v.raw_values.toString().split('|');
return v.matched_values.map((val, i) =>
val[2] !== null ? val[2] : rawValues[i],
);
},
},
{
label: 'Product Type',
Expand Down
18 changes: 10 additions & 8 deletions src/app/src/util/util.facilitiesCSV.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ const formatFacilityType = (
contributor_name,
},
) => {
const matches = matched_values.map(values =>
let raw =
typeof raw_values === 'string' ? raw_values.split('|') : raw_values;

const matches = matched_values.map((values, i) =>
formatAttribution({
value: values[2],
value: values[2] !== null ? values[2] : raw[i],
contributor_name,
updated_at,
}),
);
let raw =
typeof raw_values === 'string' ? raw_values.split('|') : raw_values;
raw = raw.map(value =>
formatAttribution({
value,
Expand All @@ -78,15 +79,16 @@ const formatProcessingType = (
contributor_name,
},
) => {
const matches = matched_values.map(values =>
let raw =
typeof raw_values === 'string' ? raw_values.split('|') : raw_values;

const matches = matched_values.map((values, i) =>
formatAttribution({
value: values[3],
value: values[3] !== null ? values[3] : raw[i],
contributor_name,
updated_at,
}),
);
let raw =
typeof raw_values === 'string' ? raw_values.split('|') : raw_values;
raw = raw.map(value =>
formatAttribution({
value,
Expand Down
7 changes: 0 additions & 7 deletions src/django/api/extended_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from api.models import Contributor, ExtendedField, ProductType
from api.facility_type_processing_type import (
get_facility_and_processing_type,
ALL_PROCESSING_TYPES
)


Expand Down Expand Up @@ -33,12 +32,6 @@ def get_facility_and_processing_type_extendfield_value(field, field_value):

for value in deduped_values:
result = get_facility_and_processing_type(value)
if result[0] is None:
raise ValueError(
f'No match found for {field}. Value must '
'be one of the following: '
f'{", ".join(list(ALL_PROCESSING_TYPES.keys()))}'
)
results.append(result)

return {
Expand Down
3 changes: 2 additions & 1 deletion src/django/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,8 @@ def index_extendedfields(facility_ids=list):
facility_types = set()
for values_list in facility_type_values:
for facility_type_value in values_list:
facility_types.add(facility_type_value[2])
if facility_type_value[2] is not None:
facility_types.add(facility_type_value[2])
facility.facility_type = list(facility_types)

# Use clean taxonomy values in the index for processing_type:
Expand Down
16 changes: 12 additions & 4 deletions src/django/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8212,18 +8212,26 @@ def test_multiple_facility_values(self, mock_get):
self.assertEqual(0, len(facility_index.processing_type))

@patch('api.geocoding.requests.get')
def test_invalid_value(self, mock_get):
def test_non_taxonomy_value(self, mock_get):
mock_get.return_value = Mock(ok=True, status_code=200)
mock_get.return_value.json.return_value = geocoding_data
self.join_group_and_login()
response = self.client.post(self.url, json.dumps({
'country': "US",
'name': "Azavea",
'address': "990 Spring Garden St., Philadelphia PA 19123",
'processing_type': 'sadfjhasdf'
'facility_type_processing_type': 'sewing|not a taxonomy value'
}), content_type='application/json')
self.assertEqual(0, ExtendedField.objects.all().count())
self.assertEqual(response.status_code, 400)
self.assertEqual(1, ExtendedField.objects.filter(
field_name='facility_type').count())
self.assertEqual(1, ExtendedField.objects.filter(
field_name='processing_type').count())
self.assertEqual(response.status_code, 201)

data = json.loads(response.content)
index_row = FacilityIndex.objects.filter(id=data['oar_id']).first()
self.assertEqual(['Final Product Assembly'], index_row.facility_type)
self.assertEqual(['Sewing'], index_row.processing_type)

@patch('api.geocoding.requests.get')
def test_search_by_processing_type(self, mock_get):
Expand Down

0 comments on commit e731760

Please sign in to comment.