From c2a7b790754b1583fffe47174277494f95f07fca Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Fri, 18 Aug 2023 16:43:26 -0600 Subject: [PATCH 01/12] Create ObjectMixin and beginning work on applying it --- usaon_vta_survey/forms.py | 16 +++---- usaon_vta_survey/models/tables.py | 30 +++++++++---- .../templates/macros/forms/misc.j2 | 42 +++++++++---------- 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/usaon_vta_survey/forms.py b/usaon_vta_survey/forms.py index 40a76e78..288c476d 100644 --- a/usaon_vta_survey/forms.py +++ b/usaon_vta_survey/forms.py @@ -62,14 +62,16 @@ def conv_String(self, field_args, **extra): ResponseObservingSystem: model_form( ResponseObservingSystem, only=[ - 'name', - 'url', - 'author_name', - 'author_email', + 'short_name', + 'long_name', + 'website_url', + 'contact_name', + 'contact_email', 'funding_country', - 'funding_agency', - 'references_citations', - 'notes', + 'organization', + 'tags', + 'version', + 'description', ], ), # TODO: Restrict "rating" values to correct range diff --git a/usaon_vta_survey/models/tables.py b/usaon_vta_survey/models/tables.py index fa913a86..d8fa7fe1 100644 --- a/usaon_vta_survey/models/tables.py +++ b/usaon_vta_survey/models/tables.py @@ -64,6 +64,26 @@ def __io__(cls) -> IORelationship: return io +class ResponseObjectFieldMixin: + """Provide shared fields between all relationshio objects to reduce repition.""" + + short_name = Column(String(256), nullable=False) + full_name = Column(String(256), nullable=False) + organization = Column(String(256), nullable=False) + # should this be funding agency? + funder = Column(String(256), nullable=False) + funding_country = Column(String(256), nullable=False) + # clairify this + website_url = Column(String(256), nullable=True) + description = Column(String(512), nullable=True) + contact_name = Column(String(256), nullable=False) + contact_title = Column(String(256), nullable=True) + contact_email = Column(String(256), nullable=False) + # how do i make it a minimum of 3 tags? + tags = Column(String, nullable=False) + version = Column(String(64), nullable=True) + + class User(BaseModel, UserMixin): __tablename__ = 'user' id = Column( @@ -185,7 +205,7 @@ class Response(BaseModel): ) -class ResponseObservingSystem(BaseModel, IORelationshipMixin): +class ResponseObservingSystem(BaseModel, IORelationshipMixin, ResponseObjectFieldMixin): __tablename__ = 'response_observing_system' __table_args__ = (UniqueConstraint('name', 'response_id'),) id = Column( @@ -213,14 +233,6 @@ class ResponseObservingSystem(BaseModel, IORelationshipMixin): 'polymorphic_on': type, } - url = Column(String(256), nullable=False) - author_name = Column(String(256), nullable=False) - author_email = Column(String(256), nullable=False) - funding_country = Column(String(256), nullable=False) - funding_agency = Column(String(256), nullable=False) - references_citations = Column(String(512), nullable=False) - notes = Column(String(512), nullable=True) - response = relationship( 'Response', back_populates='observing_systems', diff --git a/usaon_vta_survey/templates/macros/forms/misc.j2 b/usaon_vta_survey/templates/macros/forms/misc.j2 index 102ae122..94aa28a5 100644 --- a/usaon_vta_survey/templates/macros/forms/misc.j2 +++ b/usaon_vta_survey/templates/macros/forms/misc.j2 @@ -1,38 +1,38 @@ {% macro observing_system_fields(form) -%} - {{form.name.label}} {{form.name(size=50)}} - {% if form.name.errors %} + {{form.short_name.label}} {{form.short_name(size=50)}} + {% if form.short_name.errors %} {% endif %}
- {{form.url.label}} {{form.url(size=50)}} - {% if form.url.errors %} + {{form.website_url.label}} {{form.website_url(size=50)}} + {% if form.website_url.errors %} {% endif %}
- {{form.author_name.label}} {{form.author_name(size=50)}} - {% if form.author_name.errors %} + {{form.contact_name.label}} {{form.contact_name(size=50)}} + {% if form.contact_name.errors %} {% endif %}
- {{form.author_email.label}} {{form.author_email(size=50)}} - {% if form.author_email.errors %} + {{form.contact_email.label}} {{form.contact_email(size=50)}} + {% if form.contact_email.errors %} @@ -49,30 +49,30 @@ {% endif %}
- {{form.funding_agency.label}} {{form.funding_agency(size=50)}} - {% if form.funding_agency.errors %} + {{form.organization.label}} {{form.organization(size=50)}} + {% if form.organization.errors %} {% endif %}
- {{form.references_citations.label}} {{form.references_citations(size=50)}} - {% if form.references_citations.errors %} + {{form.tags.label}} {{form.tags(size=50)}} + {% if form.tags.errors %} {% endif %}
- {{form.notes.label}} {{form.notes(size=50)}} - {% if form.notes.errors %} + {{form.description.label}} {{form.description(size=50)}} + {% if form.description.errors %} From f30a7cb2b11989de71e6d2513ed9e6403e3d490a Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Mon, 21 Aug 2023 09:32:38 -0600 Subject: [PATCH 02/12] Update macro name --- usaon_vta_survey/models/tables.py | 1 + usaon_vta_survey/templates/macros/forms/misc.j2 | 2 +- usaon_vta_survey/templates/response/observing_systems.html | 4 ++-- .../response/relationships/observing_system_data_product.html | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/usaon_vta_survey/models/tables.py b/usaon_vta_survey/models/tables.py index d8fa7fe1..c3783be1 100644 --- a/usaon_vta_survey/models/tables.py +++ b/usaon_vta_survey/models/tables.py @@ -274,6 +274,7 @@ class ResponseObservingSystemResearch(BaseModel): intermediate_product = Column(String(256), nullable=False) +# ADD ResponseObjectFieldMixin class ResponseDataProduct(BaseModel, IORelationshipMixin): __tablename__ = 'response_data_product' __table_args__ = (UniqueConstraint('name', 'response_id'),) diff --git a/usaon_vta_survey/templates/macros/forms/misc.j2 b/usaon_vta_survey/templates/macros/forms/misc.j2 index 94aa28a5..87170a25 100644 --- a/usaon_vta_survey/templates/macros/forms/misc.j2 +++ b/usaon_vta_survey/templates/macros/forms/misc.j2 @@ -1,4 +1,4 @@ -{% macro observing_system_fields(form) -%} +{% macro response_object_fields(form) -%} {{form.short_name.label}} {{form.short_name(size=50)}} {% if form.short_name.errors %}