Skip to content
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

DRY common response object database fields #107

Merged
merged 13 commits into from
Aug 22, 2023
64 changes: 20 additions & 44 deletions usaon_vta_survey/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
User,
)

response_object_fields = [
Copy link
Member

Choose a reason for hiding this comment

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

maybe common_response_object_fields?

Copy link
Member

Choose a reason for hiding this comment

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

Also, is there a way we can generate this list from the mixin class? There are many ways to get the "fields" out of a class, but they're all pretty messy. We could make ResponseObjectFieldMixin a pydantic class, and then I think we have more intuitive access to its fields. Or we could use one of these methods:

https://stackoverflow.com/questions/9058305/getting-attributes-of-a-class

I don't feel we need to address this in this PR, except to leave a comment for future us that some DRYing needs to be done.

'short_name',
'full_name',
'organization',
'funder',
'funding_country',
'website',
'description',
'contact_name',
'contact_title',
'contact_email',
'tags',
'version',
]


class CustomModelConverter(ModelConverter):
@converts("String")
Expand Down Expand Up @@ -61,57 +76,18 @@ def conv_String(self, field_args, **extra):
# Response entities ("nodes" from Sankey diagram perspective)
ResponseObservingSystem: model_form(
ResponseObservingSystem,
only=[
'short_name',
'full_name',
'organization',
'funder',
'funding_country',
'website',
'description',
'contact_name',
'contact_title',
'contact_email',
'tags',
'version',
],
only=response_object_fields,
),
# TODO: Restrict "rating" values to correct range
ResponseDataProduct: model_form(
ResponseDataProduct,
only=[
'short_name',
'full_name',
'organization',
'funder',
'funding_country',
'website',
'description',
'contact_name',
'contact_title',
'contact_email',
'tags',
'version',
],
only=response_object_fields,
),
ResponseApplication: model_form(
ResponseApplication,
only=[
'short_name',
'full_name',
'organization',
'funder',
'funding_country',
'website',
'description',
'contact_name',
'contact_title',
'contact_email',
'tags',
'version',
'performance_criteria',
'performance_rating',
],
only=response_object_fields.append(
['performance_criteria', 'performance_rating']
),
rmarow marked this conversation as resolved.
Show resolved Hide resolved
),
ResponseSocietalBenefitArea: model_form(
ResponseSocietalBenefitArea,
Expand Down
Loading