-
Notifications
You must be signed in to change notification settings - Fork 358
[ENG-9827] - save collection-submission custom metadata to CedarMetadataRecord on create/update #11735
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
base: feature/es2-consolidation
Are you sure you want to change the base?
[ENG-9827] - save collection-submission custom metadata to CedarMetadataRecord on create/update #11735
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,12 @@ | |
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| CEDAR_METADATA_FIELDS = [ | ||
| 'collected_type', 'status', 'volume', 'issue', | ||
| 'program_area', 'school_type', 'study_design', | ||
| 'data_type', 'disease', 'grade_levels', | ||
| ] | ||
|
|
||
|
|
||
| class CollectionSubmission(TaxonomizableMixin, BaseModel): | ||
| primary_identifier_name = 'guid___id' | ||
|
|
@@ -94,6 +100,19 @@ def is_submitted_by_moderator_contributor(self, event_data): | |
| def state(self, new_state): | ||
| self.machine_state = new_state.value | ||
|
|
||
| def sync_cedar_metadata(self): | ||
| """Create or update a CedarMetadataRecord from this submission's custom metadata fields.""" | ||
|
|
||
| from osf.models import CedarMetadataRecord | ||
| if not (self.collection.provider_id and self.collection.provider.required_metadata_template): | ||
| return | ||
| template = self.collection.provider.required_metadata_template | ||
| metadata = {f: getattr(self, f) for f in CEDAR_METADATA_FIELDS if getattr(self, f, '')} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the main thing this has to do is make a valid cedar record (is why calling |
||
| record, _ = CedarMetadataRecord.objects.get_or_create(guid=self.guid, template=template) | ||
| record.metadata = metadata | ||
| record.is_published = True | ||
| record.save() | ||
|
|
||
| def _notify_contributors_pending(self, event_data): | ||
| user = event_data.kwargs.get('user') | ||
| for contributor in self.guid.referent.contributors: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about calling
validate_required_metadataaftersync_cedar_metadata, instead of removing the validation entirely? (looks like now it's never validated)