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

Add support for facility_type_processing_type meta extended field #1671

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 11 additions & 2 deletions src/django/api/extended_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/django/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions src/django/api/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down