diff --git a/app/votepeloclima/candidature/forms.py b/app/votepeloclima/candidature/forms.py index 8d0fd8f2..042480c1 100644 --- a/app/votepeloclima/candidature/forms.py +++ b/app/votepeloclima/candidature/forms.py @@ -56,7 +56,18 @@ def __init__(self, *args, **kwargs): self.fields['city'].choices = get_choices(self.data.get('state')) elif self.initial.get('state'): self.fields['city'].choices = get_choices(self.initial.get('state')) - + class Media: + css = { + "all": [ + "https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css", + ] + } + js = [ + "https://code.jquery.com/jquery-3.5.1.min.js", + "https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js", + "https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/i18n/pt-BR.js", + "js/address-fields.js", + ] class ProfileForm(forms.Form): video = forms.URLField(label="Vídeo", required=False) @@ -87,7 +98,7 @@ class CheckoutForm(forms.Form): register_form_list = [ - # ("captcha", CaptchaForm), + ("captcha", CaptchaForm), ("informacoes-iniciais", InitialForm), ("informacoes-de-candidatura", ApplicationForm), ("complemente-seu-perfil", ProfileForm), diff --git a/app/votepeloclima/candidature/migrations/0005_alter_candidatureflow_candidature_and_more.py b/app/votepeloclima/candidature/migrations/0005_alter_candidatureflow_candidature_and_more.py new file mode 100644 index 00000000..b13cc357 --- /dev/null +++ b/app/votepeloclima/candidature/migrations/0005_alter_candidatureflow_candidature_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2 on 2024-07-09 19:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('candidature', '0004_alter_candidatureflow_properties'), + ] + + operations = [ + migrations.AlterField( + model_name='candidatureflow', + name='candidature', + field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='candidature.candidature'), + ), + migrations.AlterField( + model_name='candidatureflow', + name='status', + field=models.CharField(choices=[('draft', 'Editando'), ('submitted', 'Enviado'), ('invalid', 'Inválido'), ('is_valid', 'Válido'), ('draft_requested', 'Edição Requisitada')], default='draft', max_length=50), + ), + ] diff --git a/app/votepeloclima/candidature/static/js/address-fields.js b/app/votepeloclima/candidature/static/js/address-fields.js index ad8d877a..82188ac2 100644 --- a/app/votepeloclima/candidature/static/js/address-fields.js +++ b/app/votepeloclima/candidature/static/js/address-fields.js @@ -4,27 +4,42 @@ $(function () { const $stateField = $('[data-address-fields="state"]'); const $cityField = $('[data-address-fields="city"]'); - console.log("oiee") if ($stateField.length) { - $stateField.select2({ dropdownAutoWidth: true, width: 'auto', placeholder: 'Selecione seu estado' }); - $cityField.select2({ allowClear: true, dropdownAutoWidth: true, width: 'auto', placeholder: 'Selecione sua cidade' }); + $stateField.prepend('').val(""); + $stateField.select2({ + allowClear: true, + dropdownAutoWidth: true, + width: "auto", + placeholder: "Selecione seu estado" + }); + + $cityField.prepend('').val(""); + $cityField.select2({ + allowClear: true, + dropdownAutoWidth: true, + width: "auto", + placeholder: "Selecione sua cidade" + }); var uf; $stateField.on("change", (evt) => { uf = evt.target.value; const url = $stateField.data("address-url"); - $.get(url + "?state=" + uf, (data) => { - $cityField.empty(); - $cityField.append(''); - $.each(data, (index, value) => { - $cityField.append( - '' - ); + $cityField.empty(); + $cityField.append(''); + + if (uf) { + $.get(url + "?state=" + uf, (data) => { + $.each(data, (index, value) => { + $cityField.append( + '' + ); + }); }); - }); + } }); } }); -}(window.jQuery)); +}(jQuery)); diff --git a/app/votepeloclima/candidature/templates/candidature/done.html b/app/votepeloclima/candidature/templates/candidature/done.html index c53caf32..f342a9ee 100644 --- a/app/votepeloclima/candidature/templates/candidature/done.html +++ b/app/votepeloclima/candidature/templates/candidature/done.html @@ -1,23 +1,23 @@ {% for step in checkout_steps %} {% if step.name == 'checkout' %} -
- {% csrf_token %} - {{ wizard.form.media }} - {{ wizard.management_form }} - {% if wizard.form.forms %} - {{ wizard.form.management_form }} - {% for form in wizard.form.forms %} - {{ form.as_p }} - {% endfor %} - {% else %} - {{ wizard.form.as_p }} - {% endif %} - -
+
+ {% csrf_token %} + {{ wizard.form.media }} + {{ wizard.management_form }} + {% if wizard.form.forms %} + {{ wizard.form.management_form }} + {% for form in wizard.form.forms %} + {{ form.as_p }} + {% endfor %} + {% else %} + {{ wizard.form.as_p }} + {% endif %} + +
{% else %}
Editar {{ step.form.as_p }}
{% endif %} -{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/app/votepeloclima/candidature/utils.py b/app/votepeloclima/candidature/utils.py index b45193b2..817cbd78 100644 --- a/app/votepeloclima/candidature/utils.py +++ b/app/votepeloclima/candidature/utils.py @@ -18,7 +18,7 @@ def get_ufs(): def get_choices(uf): csv_filename = settings.BASE_DIR / "votepeloclima/candidature/csv/places.csv" - choices = set() + choices = [] with open(csv_filename) as f: reader = csv.DictReader(f) reader.fieldnames = [field.strip() for field in reader.fieldnames] @@ -27,4 +27,4 @@ def get_choices(uf): city_code = row["Código Município Completo"].strip() city_name = row["Nome_Município"].strip() choices.append((city_code, city_name)) - return sorted(list(choices), key=lambda x: x[1]) + return sorted(choices, key=lambda x: x[1])