Skip to content

Commit

Permalink
fix(vote): update method to persist candidature with new form behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
igr-santos committed Jul 30, 2024
1 parent e17040d commit 8da802d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated by Django 4.2 on 2024-07-30 01:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('candidature', '0006_alter_candidature_options_and_more'),
]

operations = [
migrations.RenameField(
model_name='candidature',
old_name='cpf_cnpj',
new_name='cpf',
),
migrations.RemoveField(
model_name='candidature',
name='tse_id',
),
migrations.AlterField(
model_name='candidature',
name='photo',
field=models.FileField(blank=True, null=True, upload_to='candidatures/photos/'),
),
migrations.AlterField(
model_name='candidature',
name='state',
field=models.CharField(max_length=10),
),
migrations.AlterField(
model_name='candidature',
name='video',
field=models.FileField(blank=True, null=True, upload_to='candidatures/videos/'),
),
]
11 changes: 2 additions & 9 deletions app/org_eleicoes/votepeloclima/candidature/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,28 @@


class Candidature(models.Model):
# Step 1
legal_name = models.CharField(max_length=150)
ballot_name = models.CharField(max_length=100)
birth_date = models.DateField()
email = models.EmailField()
cpf_cnpj = models.CharField(max_length=30)
tse_id = models.CharField(max_length=30, null=True, blank=True)
# Step 2
cpf = models.CharField(max_length=30)
number_id = models.PositiveIntegerField()
intended_position = models.CharField(max_length=50)
state = models.CharField(max_length=2)
state = models.CharField(max_length=10)
city = models.CharField(max_length=60)
is_collective_mandate = models.BooleanField(default=False, blank=True)
political_party = models.CharField(max_length=60)
# Step 3
video = models.FileField(upload_to="candidatures/videos/", null=True, blank=True)
photo = models.FileField(upload_to="candidatures/photos/", null=True, blank=True)
gender = models.CharField(max_length=30)
color = models.CharField(max_length=30)
sexuality = models.CharField(max_length=30, null=True, blank=True)
social_media = models.JSONField(blank=True, null=True, default=list)
# Step 4
education = models.CharField(max_length=50, null=True, blank=True)
employment = models.CharField(max_length=50, null=True, blank=True)
short_description = models.TextField()
milestones = models.JSONField(blank=True, null=True, default=list)
# Step 5
flags = models.JSONField(blank=True)
# Step 6
appointments = models.JSONField(blank=True)

class Meta:
Expand Down
10 changes: 6 additions & 4 deletions app/org_eleicoes/votepeloclima/candidature/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ def done(self, form_list, form_dict, **kwargs):
values = {}

for step, form in form_dict.items():
if step not in self.steps_hide_on_checkout and step != "checkout":
if step not in ("captcha", "checkout"):
if isinstance(form, ProposeForm):
values.update({"flags": form.cleaned_data})
values.update({"flags": form.cleaned_data.get("properties")})
elif isinstance(form, AppointmentForm):
values.update({"appointments": form.cleaned_data})
values.update({"appointments": form.cleaned_data.get("properties")})
else:
values.update(form.cleaned_data)
cleaned = form.cleaned_data.copy()
properties = cleaned.pop("properties", {})
values.update({**properties, **cleaned})

obj = Candidature.objects.create(**values)
flow.candidature = obj
Expand Down

0 comments on commit 8da802d

Please sign in to comment.