Skip to content

Commit

Permalink
adding private fields models to lyon project
Browse files Browse the repository at this point in the history
  • Loading branch information
Fujistone committed Sep 29, 2024
1 parent f213212 commit e990f2b
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
32 changes: 32 additions & 0 deletions projects/lyon/models/intermediate/decidim_awesome/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2

models:
- name: int_decidim_awesome_private_proposal_fields
description: "Model for parsing the information in the private proposals fields and unnest the XML data into readable questions and answers columns."
columns:
- name: id
description: "Primary key."
- name: proposal_id
description: "Id of the proposal the private field is linked to."
- name: private_field_description
description: "Description of the private field to be answered."
- name: private_field_content
description: "The content filled by the user for a specific private field. There can be multiple content for the same private field description."


unit_tests:

- name: testing_that_the_correct_xml_information_are_parsed
description: "Checks that age matching fetches the correct infos "
model: int_decidim_awesome_proposal_extra_fields
given:
- input: ref('stg_decidim_awesome_proposal_extra_fields')
format: dict
rows:
- {id: 1, proposal_id: 101, private_body_clear: "<xml><dl class=\"decidim_awesome-custom_fields\" data-generator=\"decidim_awesome\" data-version=\"0.10.3\"><dt name=\"radio-group-1725003392539-0\">Cette idée est déposée à titre :</dt><dd id=\"radio-group-1725003392539-0\" name=\"radio-group\"><div alt=\"individuel\">Individuel</div></dd><dt name=\"radio-group-1725003468065-0\">Votre tranche d'âge :</dt><dd id=\"radio-group-1725003468065-0\" name=\"radio-group\"><div alt=\"1625\">16-25 ans</div></dd></dl></xml>"}
expect:
format: dict
rows:
- {id: 1, proposal_id: 101, private_field_description: "Cette idée est déposée à titre :", private_field_content: "Individuel"}
- {id: 1, proposal_id: 101, private_field_description: "Votre tranche d'âge :", private_field_content: "16-25 ans"}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WITH parsed_data AS (
SELECT
decidim_awesome_proposal_extra_fields.id,
decidim_awesome_proposal_extra_fields.proposal_id,
xpath('//text()', unnest(xpath('//dt', xml_data)))::text AS private_field_description,
unnest(xpath('//dd/div/text()', unnest(xpath('//dd', xml_data))))::text AS private_field_content
FROM
{{ ref ("stg_decidim_awesome_proposal_extra_fields")}} AS decidim_awesome_proposal_extra_fields,
LATERAL xmlparse(document private_body_clear) AS xml_data
)
SELECT
parsed_data.id,
parsed_data.proposal_id,
replace(replace(private_field_description, '{"', ''), '"}', '') AS private_field_description,
parsed_data.private_field_content
FROM
parsed_data
WHERE
private_field_content IS NOT NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT
decidim_awesome_proposal_extra_fields.id,
decidim_awesome_proposal_extra_fields.proposal_id,
decidim_awesome_proposal_extra_fields.private_field_description,
decidim_awesome_proposal_extra_fields.private_field_content,
decidim_proposals_proposals.decidim_component_id,
components.ps_title
FROM
{{ ref ("int_decidim_awesome_proposal_extra_fields")}} AS decidim_awesome_proposal_extra_fields
JOIN {{ ref ("stg_decidim_proposals")}} AS decidim_proposals_proposals ON decidim_awesome_proposal_extra_fields.proposal_id = decidim_proposals_proposals.id
JOIN {{ ref ("components")}} AS components ON decidim_proposals_proposals.decidim_component_id = components.id
25 changes: 25 additions & 0 deletions projects/lyon/models/staging/decidim_awesome/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: 2


sources:
- name: decidim
database: "{{ env_var('DBNAME') }}"
schema: public
tables:
- name: decidim_awesome_proposal_extra_fields_test

models:
- name: stg_decidim_awesome_proposal_extra_fields
description: "Table for private proposal fields in the module decidim awesome."
columns:
- name: id
description: "Primary key."
data_tests:
- not_null
- unique
- name: proposal_id
description: "Id of the proposal the private field is linked to."
data_tests:
- not_null
- name: private_body
description: "Body of the answers of the private proposals fields answered by the user. The format is XML."
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WITH source AS (
SELECT * FROM {{ source('decidim', 'decidim_awesome_proposal_extra_fields_test') }}
)


SELECT
id,
decidim_proposal_id AS proposal_id,
updated_at,
created_at,
replace(private_body_clear, '&nbsp;', '') AS private_body_clear
FROM source

0 comments on commit e990f2b

Please sign in to comment.