wagtail-enap-designsystem 1.2.1.136__py3-none-any.whl → 1.2.1.137__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wagtail-enap-designsystem might be problematic. Click here for more details.
- enap_designsystem/blocks/form.py +160 -24
- enap_designsystem/settings.py +2 -2
- enap_designsystem/templates/enap_designsystem/form_templates/formulario_page.html +397 -1080
- enap_designsystem/templates/enap_designsystem/includes/form_field.html +935 -1
- {wagtail_enap_designsystem-1.2.1.136.dist-info → wagtail_enap_designsystem-1.2.1.137.dist-info}/METADATA +1 -1
- {wagtail_enap_designsystem-1.2.1.136.dist-info → wagtail_enap_designsystem-1.2.1.137.dist-info}/RECORD +9 -9
- {wagtail_enap_designsystem-1.2.1.136.dist-info → wagtail_enap_designsystem-1.2.1.137.dist-info}/WHEEL +0 -0
- {wagtail_enap_designsystem-1.2.1.136.dist-info → wagtail_enap_designsystem-1.2.1.137.dist-info}/licenses/LICENSE +0 -0
- {wagtail_enap_designsystem-1.2.1.136.dist-info → wagtail_enap_designsystem-1.2.1.137.dist-info}/top_level.txt +0 -0
enap_designsystem/blocks/form.py
CHANGED
|
@@ -662,7 +662,7 @@ class CheckboxMultiRedirectFieldBlock(blocks.StructBlock):
|
|
|
662
662
|
|
|
663
663
|
class Meta:
|
|
664
664
|
icon = "redirect"
|
|
665
|
-
label = "
|
|
665
|
+
label = "🔀 Checkbox Multi-Redirecionamento"
|
|
666
666
|
|
|
667
667
|
|
|
668
668
|
class ConditionalFieldBlock(blocks.StructBlock):
|
|
@@ -1870,46 +1870,78 @@ class FormularioPage(Page):
|
|
|
1870
1870
|
|
|
1871
1871
|
return total_score, score_details
|
|
1872
1872
|
|
|
1873
|
+
# Substituir o método get_all_steps() na classe FormularioPage
|
|
1874
|
+
|
|
1873
1875
|
def get_all_steps(self):
|
|
1874
|
-
"""
|
|
1876
|
+
"""PROCESSA CAMPOS SEM ANINHAMENTO INFINITO - VERSÃO CORRIGIDA"""
|
|
1875
1877
|
steps = []
|
|
1876
1878
|
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
+
def extract_fields_safely(fields, depth=0, max_depth=3):
|
|
1880
|
+
"""
|
|
1881
|
+
Extrai campos com limite de profundidade para evitar aninhamento infinito
|
|
1882
|
+
"""
|
|
1883
|
+
if depth > max_depth:
|
|
1884
|
+
print(f"⚠️ Limite de profundidade atingido no nível {depth}")
|
|
1885
|
+
return []
|
|
1886
|
+
|
|
1887
|
+
extracted_fields = []
|
|
1888
|
+
|
|
1889
|
+
for field_block in fields:
|
|
1890
|
+
# Sempre adicionar o campo principal
|
|
1891
|
+
extracted_fields.append(field_block)
|
|
1892
|
+
|
|
1893
|
+
# Processar campos aninhados apenas se necessário
|
|
1894
|
+
if hasattr(field_block, 'value') and isinstance(field_block.value, dict):
|
|
1895
|
+
|
|
1896
|
+
# Campos condicionais normais
|
|
1897
|
+
if field_block.block_type == 'conditional_field_condicional':
|
|
1898
|
+
conditional_options = field_block.value.get('conditional_options_con', [])
|
|
1899
|
+
for option in conditional_options:
|
|
1900
|
+
if hasattr(option, 'value') and 'fields_to_show_con' in option.value:
|
|
1901
|
+
nested_fields = option.value['fields_to_show_con']
|
|
1902
|
+
# NÃO adicionar aqui - será processado pelo frontend
|
|
1903
|
+
print(f"Campo condicional encontrado com {len(nested_fields)} campos aninhados")
|
|
1904
|
+
|
|
1905
|
+
# Campos multi-redirect
|
|
1906
|
+
elif field_block.block_type == 'checkbox_multi_redirect_field':
|
|
1907
|
+
redirect_options = field_block.value.get('redirect_options', [])
|
|
1908
|
+
for option in redirect_options:
|
|
1909
|
+
if hasattr(option, 'value') and 'fields_to_show' in option.value:
|
|
1910
|
+
nested_fields = option.value['fields_to_show']
|
|
1911
|
+
# NÃO adicionar aqui - será processado pelo frontend
|
|
1912
|
+
print(f"Campo multi-redirect encontrado com {len(nested_fields)} campos aninhados")
|
|
1913
|
+
|
|
1914
|
+
return extracted_fields
|
|
1879
1915
|
|
|
1880
|
-
|
|
1881
|
-
|
|
1916
|
+
print(f"=== PROCESSANDO {len(self.form_steps)} STEPS (Versão Corrigida) ===")
|
|
1917
|
+
|
|
1918
|
+
# Processar cada step
|
|
1882
1919
|
for index, step_block in enumerate(self.form_steps):
|
|
1883
1920
|
order = step_block.value.get('order', str(index + 1))
|
|
1884
|
-
print(f"Step {index}: order='{order}'")
|
|
1885
|
-
|
|
1886
1921
|
try:
|
|
1887
1922
|
order_num = int(order) if order else index + 1
|
|
1888
1923
|
except (ValueError, TypeError):
|
|
1889
1924
|
order_num = index + 1
|
|
1890
1925
|
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
steps_with_order.sort(key=lambda x: x[0])
|
|
1895
|
-
print(f"Ordem final: {[(x[0], x[1]) for x in steps_with_order]}")
|
|
1896
|
-
|
|
1897
|
-
# Processar steps na ordem correta
|
|
1898
|
-
for position, (order_num, original_index, step_block) in enumerate(steps_with_order):
|
|
1926
|
+
# Extrair campos de forma segura (sem recursão infinita)
|
|
1927
|
+
step_fields = extract_fields_safely(step_block.value['fields'])
|
|
1928
|
+
|
|
1899
1929
|
step_data = {
|
|
1900
|
-
'number':
|
|
1901
|
-
'original_number':
|
|
1930
|
+
'number': index + 1,
|
|
1931
|
+
'original_number': index + 1,
|
|
1902
1932
|
'order': order_num,
|
|
1903
1933
|
'logo': step_block.value.get('logo'),
|
|
1904
1934
|
'logo_alt': step_block.value.get('logo_alt', ''),
|
|
1905
|
-
'fields':
|
|
1935
|
+
'fields': step_fields, # Apenas campos do nível principal
|
|
1906
1936
|
'id': step_block.id,
|
|
1907
1937
|
'sections': []
|
|
1908
1938
|
}
|
|
1909
1939
|
|
|
1910
|
-
|
|
1940
|
+
print(f"✅ Step {index + 1}: {len(step_fields)} campos (sem aninhamento)")
|
|
1941
|
+
|
|
1942
|
+
# Organizar em seções
|
|
1911
1943
|
current_section = None
|
|
1912
|
-
for field_block in
|
|
1944
|
+
for field_block in step_fields:
|
|
1913
1945
|
if field_block.block_type == 'section_header':
|
|
1914
1946
|
current_section = {
|
|
1915
1947
|
'title': field_block.value['title'],
|
|
@@ -1925,14 +1957,118 @@ class FormularioPage(Page):
|
|
|
1925
1957
|
'fields': []
|
|
1926
1958
|
}
|
|
1927
1959
|
step_data['sections'].append(current_section)
|
|
1928
|
-
|
|
1929
1960
|
current_section['fields'].append(field_block)
|
|
1930
1961
|
|
|
1931
1962
|
steps.append(step_data)
|
|
1932
|
-
print(f"Step processado: {position + 1} (ordem {order_num})")
|
|
1933
1963
|
|
|
1934
|
-
|
|
1964
|
+
total_fields = sum(len(step['fields']) for step in steps)
|
|
1965
|
+
print(f"🎉 RESULTADO: {len(steps)} steps com {total_fields} campos principais")
|
|
1966
|
+
|
|
1935
1967
|
return steps
|
|
1968
|
+
|
|
1969
|
+
|
|
1970
|
+
# TAMBÉM ADICIONAR este método para extrair dados condicionais de forma mais limpa
|
|
1971
|
+
|
|
1972
|
+
def build_conditional_data(self):
|
|
1973
|
+
"""Constrói dados condicionais de forma mais organizada"""
|
|
1974
|
+
conditional_data = {}
|
|
1975
|
+
|
|
1976
|
+
for step_index, step_block in enumerate(self.form_steps):
|
|
1977
|
+
for field_block in step_block.value['fields']:
|
|
1978
|
+
field_id = f"{field_block.block_type}_{field_block.id}"
|
|
1979
|
+
|
|
1980
|
+
# Campos condicionais "condicional"
|
|
1981
|
+
if field_block.block_type == 'conditional_field_condicional':
|
|
1982
|
+
options_data = {}
|
|
1983
|
+
|
|
1984
|
+
for option in field_block.value.get('conditional_options_con', []):
|
|
1985
|
+
option_value = option.value['value_con']
|
|
1986
|
+
action = option.value['action_con']
|
|
1987
|
+
|
|
1988
|
+
if action == 'show_fields_con':
|
|
1989
|
+
# Extrair IDs dos campos que devem aparecer
|
|
1990
|
+
nested_field_ids = []
|
|
1991
|
+
for nested_field in option.value.get('fields_to_show_con', []):
|
|
1992
|
+
nested_id = f"{nested_field.block_type}_{nested_field.id}"
|
|
1993
|
+
nested_field_ids.append(nested_id)
|
|
1994
|
+
|
|
1995
|
+
options_data[option_value] = {
|
|
1996
|
+
'action': 'show_fields',
|
|
1997
|
+
'field_ids': nested_field_ids
|
|
1998
|
+
}
|
|
1999
|
+
else:
|
|
2000
|
+
options_data[option_value] = {
|
|
2001
|
+
'action': 'nothing'
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
conditional_data[field_id] = {
|
|
2005
|
+
'type': 'conditional_field_condicional',
|
|
2006
|
+
'options': options_data
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
# Campos multi-redirect
|
|
2010
|
+
elif field_block.block_type == 'checkbox_multi_redirect_field':
|
|
2011
|
+
options_data = {}
|
|
2012
|
+
|
|
2013
|
+
for option in field_block.value.get('redirect_options', []):
|
|
2014
|
+
option_value = option.value['value']
|
|
2015
|
+
action = option.value['action']
|
|
2016
|
+
|
|
2017
|
+
if action == 'show_fields':
|
|
2018
|
+
nested_field_ids = []
|
|
2019
|
+
for nested_field in option.value.get('fields_to_show', []):
|
|
2020
|
+
nested_id = f"{nested_field.block_type}_{nested_field.id}"
|
|
2021
|
+
nested_field_ids.append(nested_id)
|
|
2022
|
+
|
|
2023
|
+
options_data[option_value] = {
|
|
2024
|
+
'action': 'show_fields',
|
|
2025
|
+
'field_ids': nested_field_ids
|
|
2026
|
+
}
|
|
2027
|
+
else:
|
|
2028
|
+
options_data[option_value] = {
|
|
2029
|
+
'action': action
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
conditional_data[field_id] = {
|
|
2033
|
+
'type': 'checkbox_multi_redirect_field',
|
|
2034
|
+
'field_type': field_block.value.get('field_type', 'checkbox'),
|
|
2035
|
+
'options': options_data
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
return conditional_data
|
|
2039
|
+
|
|
2040
|
+
|
|
2041
|
+
# SUBSTITUIR também o método get_context para incluir os dados condicionais corretos
|
|
2042
|
+
|
|
2043
|
+
def get_context(self, request, *args, **kwargs):
|
|
2044
|
+
"""Adiciona contexto personalizado - VERSÃO CORRIGIDA"""
|
|
2045
|
+
context = super().get_context(request, *args, **kwargs)
|
|
2046
|
+
|
|
2047
|
+
# Informações básicas dos steps
|
|
2048
|
+
context['total_form_steps'] = len(self.form_steps)
|
|
2049
|
+
context['all_steps'] = self.get_all_steps()
|
|
2050
|
+
|
|
2051
|
+
# Dados condicionais organizados
|
|
2052
|
+
conditional_data = self.build_conditional_data()
|
|
2053
|
+
context['conditional_data_json'] = json.dumps(conditional_data)
|
|
2054
|
+
|
|
2055
|
+
# Extrair nome do usuário
|
|
2056
|
+
full_name = 'Usuário'
|
|
2057
|
+
if request.method == 'POST':
|
|
2058
|
+
for key, value in request.POST.items():
|
|
2059
|
+
if key.startswith('nome_completo_field_') and value:
|
|
2060
|
+
full_name = value.strip()
|
|
2061
|
+
break
|
|
2062
|
+
|
|
2063
|
+
context['full_name'] = full_name
|
|
2064
|
+
|
|
2065
|
+
# Status de sucesso
|
|
2066
|
+
if request.GET.get('success'):
|
|
2067
|
+
context['form_success'] = True
|
|
2068
|
+
context['email_sent'] = request.GET.get('email_sent') == '1'
|
|
2069
|
+
context['admin_notified'] = request.GET.get('admin_notified') == '1'
|
|
2070
|
+
|
|
2071
|
+
return context
|
|
1936
2072
|
class Meta:
|
|
1937
2073
|
verbose_name = "Formulário Dinâmico"
|
|
1938
2074
|
verbose_name_plural = "Formulários Dinâmicos"
|
enap_designsystem/settings.py
CHANGED
|
@@ -4,7 +4,7 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
4
4
|
|
|
5
5
|
RECAPTCHA_PUBLIC_KEY = "6Lf_9MMrAAAAAOAsVXk8F5scxr6vsZJzC2jJnGHb"
|
|
6
6
|
RECAPTCHA_PRIVATE_KEY = "6Lf_9MMrAAAAAJqd_uA1_ekq3F-bD24KRhBcfKCF"
|
|
7
|
-
|
|
7
|
+
DATA_UPLOAD_MAX_NUMBER_FIELDS = 9000000
|
|
8
8
|
WAGTAIL_404_TEMPLATE = '404.html'
|
|
9
9
|
|
|
10
10
|
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
|
|
@@ -25,4 +25,4 @@ TEMPLATES = [
|
|
|
25
25
|
],
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
|
-
]
|
|
28
|
+
]
|