diff --git a/CHANGELOG.md b/CHANGELOG.md index 486d60c31..dd4ee57d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Integrate facility/processing type taxonomy into facility claims [#1639](https://github.com/open-apparel-registry/open-apparel-registry/pull/1639) - Index extended fields [#1651](https://github.com/open-apparel-registry/open-apparel-registry/pull/1651) - Allow searching contributors by name and admin email [#1668](https://github.com/open-apparel-registry/open-apparel-registry/pull/1668) +- Add support for facility_type_processing_type meta extended field [#1671](https://github.com/open-apparel-registry/open-apparel-registry/pull/1671) ### Changed diff --git a/src/django/api/extended_fields.py b/src/django/api/extended_fields.py index 56e3908cc..f5812b9bc 100644 --- a/src/django/api/extended_fields.py +++ b/src/django/api/extended_fields.py @@ -115,10 +115,19 @@ def create_extendedfields_for_single_item(item, raw_data): return False contributor = item.source.contributor + # facility_type_processing_type is a special "meta" field that attempts to + # simplify the submission process for contributors. + if (raw_data.get('facility_type_processing_type')): + if raw_data.get('facility_type') is None: + raw_data['facility_type'] = \ + raw_data['facility_type_processing_type'] + if raw_data.get('processing_type') is None: + raw_data['processing_type'] = \ + raw_data['facility_type_processing_type'] # Add a facility_type extended field if the user only # submitted a processing_type - if (raw_data.get('processing_type') and - raw_data.get('facility_type') is None): + elif (raw_data.get('processing_type') and + raw_data.get('facility_type') is None): raw_data['facility_type'] = raw_data['processing_type'] # Add a processing_type extended field if the user only # submitted a facility_type diff --git a/src/django/api/models.py b/src/django/api/models.py index 6726fa494..5e144f8c5 100644 --- a/src/django/api/models.py +++ b/src/django/api/models.py @@ -2403,6 +2403,10 @@ class ExtendedField(models.Model): updated_at = models.DateTimeField(auto_now=True) history = HistoricalRecords() + def __str__(self): + return "{} - {} - {} ({})".format( + self.field_name, self.facility_id, self.contributor.name, self.id) + @staticmethod def post_save(sender, **kwargs): instance = kwargs.get('instance') diff --git a/src/django/api/processing.py b/src/django/api/processing.py index 06bc3eafe..36bdf1b56 100644 --- a/src/django/api/processing.py +++ b/src/django/api/processing.py @@ -114,6 +114,19 @@ def parse_facility_list_item(item): fields = [f.lower() for f in parse_csv_line(item.source.facility_list.header)] values = parse_csv_line(item.raw_data) + + # facility_type_processing_type is a special "meta" field that attempts + # to simplify the submission process for contributors. + if 'facility_type_processing_type' in fields: + if 'facility_type' not in fields: + fields.append('facility_type') + values.append( + values[fields.index('facility_type_processing_type')]) + if 'processing_type' not in fields: + fields.append('processing_type') + values.append( + values[fields.index('facility_type_processing_type')]) + if CsvHeaderField.COUNTRY in fields: item.country_code = get_country_code( values[fields.index(CsvHeaderField.COUNTRY)])