Skip to content

NBB316 - updated get_field in Attachment model#46

Open
bdaisey wants to merge 1 commit into
imsweb:3.0from
bdaisey:update_get_field
Open

NBB316 - updated get_field in Attachment model#46
bdaisey wants to merge 1 commit into
imsweb:3.0from
bdaisey:update_get_field

Conversation

@bdaisey
Copy link
Copy Markdown

@bdaisey bdaisey commented Dec 10, 2020

@dcwatson heads up, let me know if you need any more info! Brad and I discussed this solution yesterday to give us desired behavior on NBB but let me know if there is a better way to approach this / unintended consequences.

Related to https://git.imsweb.com/bioshare/neurobiobank/-/issues/316

By default, attachments.models.Property has required = True. This update will allow an Attachment to have a non-required Property, which will allow for the display of the Property's label even if the Property has no value set.

The need for this was discovered on NBB because we want to allow attachments to have an associated property 'request-document-type' with 'required=false', so we need a way to allow the property key to exist without (necessarily) having a value set on all Attachments.

Desired behavior with a value set:
image

Desired behavior with NO value set:
image

(The current behavior is the server error described in the NBB issue, and the user will not see any popup on the front end when clicking the 'View Properties' icon on an attachment.)

Comment thread attachments/models.py
if prop.data_type == 'model' and prop.slug in self.data:
return prop.label, prop.model_queryset().get(pk=self.data.get(prop.slug, [])[0])
pk = self.data.get(prop.slug, [])[0]
value = prop.model_queryset().get(pk=self.data.get(prop.slug, [])[0]) if pk else ''
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this just be .get(pk=pk)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don't know exactly how/where this is called, but returning None feels more appropriate for a default than ''. Or maybe even add a default=None kwarg that you could pass the empty string if you wanted.

Comment thread attachments/models.py
"""
if prop.data_type == 'model' and prop.slug in self.data:
return prop.label, prop.model_queryset().get(pk=self.data.get(prop.slug, [])[0])
pk = self.data.get(prop.slug, [])[0]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will raise an IndexError if the slug isn't in self.data since the default is an empty list

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brad should clearly be doing these reviews instead of me!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I was thinking you wanted to be looped in on all updates here, but will assign to Brad or Noah next time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants