Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remover campo zona para Candidatas #31

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions app/eleicao/bonde_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
def create_form_entry(**form_data):
email = form_data.get("email")
name = form_data.get("name")
# Activist get_or_create
activist = Activist.objects.get(email=email)

if not activist:
activist = Activist.objects.create(email=email, name=name)

# Activist get_or_create
activist, created = Activist.objects.get_or_create(email=email)

if created:
activist.name = name
activist.save()

state = form_data.get("state")
city = form_data.get("city")
Expand Down
6 changes: 3 additions & 3 deletions app/eleicao/csv/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def get_choices(uf, city=None):
for row in reader:
if row["uf"] == uf:
if city:
if city == row["city"]:
if city.upper() == row["city"].upper():
choices.append(
(row["neighborhood"], row["neighborhood"].capitalize())
(row["neighborhood"].capitalize(), row["neighborhood"].capitalize())
)
else:
choices.append((row["city"], row["city"].capitalize()))
choices.append((row["city"].capitalize(), row["city"].capitalize()))

return list(set(choices))
29 changes: 15 additions & 14 deletions app/eleicao/forms/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ class Meta:

class Candidate2Form(forms.ModelForm):
number = forms.IntegerField(label="Numero do candidato")
zone_id = forms.IntegerField()

class Meta:
model = Address
fields = [
"state",
"city",
"neighborhood",
"zone_id",
"number",
]

Expand All @@ -30,7 +28,6 @@ def __init__(self, *args, **kwargs):
# self.fields["state"].widget = s2forms.Select2Widget()
self.fields["city"].widget = forms.Select()
self.fields["neighborhood"].widget = forms.Select()
self.fields["zone_id"].widget = forms.Select()


class Candidate3Form(forms.ModelForm):
Expand Down Expand Up @@ -62,17 +59,21 @@ class Candidate6Form(forms.Form):
agree = forms.BooleanField(
label="Li e estou de acordo com os compromissos listados assim"
)


class PlacesWidget(s2forms.ModelSelect2Widget):

search_fields = [
"places__state__icontains",
"places__city__icontains",
"places__neighborhood__icontains"
]
search_fields = [
"places__state__icontains",
"places__city__icontains",
"places__neighborhood__icontains",
]


class VoterForm(forms.ModelForm):

zone = forms.ModelChoiceField(
queryset=PollingPlace.objects.all(), label="Onde você vota?", required=True
)

zone = forms.ModelChoiceField(queryset= PollingPlace.objects.all(), label ="Onde você vota?", required=True)
class Meta:
model = Voter
fields = ["name", "email", "whatsapp", "zone"]
class Meta:
model = Voter
fields = ["name", "email", "whatsapp", "zone"]
17 changes: 17 additions & 0 deletions app/eleicao/migrations/0013_remove_candidate_zone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2 on 2023-08-07 17:06

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('eleicao', '0012_alter_address_neighborhood'),
]

operations = [
migrations.RemoveField(
model_name='candidate',
name='zone',
),
]
1 change: 0 additions & 1 deletion app/eleicao/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ class Candidate(models.Model):
"Quero receber atualizações da campanha e do NOSSAS.", default=False
)
themes = models.ManyToManyField(Theme)
zone = models.ForeignKey(PollingPlace, on_delete=models.CASCADE)
place = models.ForeignKey(Address, on_delete=models.CASCADE)

def __str__(self):
Expand Down
12 changes: 5 additions & 7 deletions app/eleicao/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:

def get_queryset(self) -> QuerySet[Any]:
qs = super().get_queryset()

filter_state = self.request.GET.get("uf", None)
if filter_state:
return qs.filter(place__state__iexact=filter_state)
Expand All @@ -56,6 +56,7 @@ class CandidateCreateView(SessionWizardView):
Candidate5Form,
Candidate6Form,
]

file_storage = settings.DEFAULT_FILE_STORAGE
# model = Candidate
# fields = "__all__"
Expand All @@ -82,16 +83,11 @@ def done(self, form_list, **kwargs):
.first()
.id
)
# PollingPlace
# zone = values.pop("zone")
# polling_place = PollingPlace.objects.get(id=zone)

obj = Candidate.objects.create(**values)
# obj.zone = polling_place
obj.themes.set(themes)
obj.save()


# Integrate with Bonde
fe = create_form_entry(state=state, city=city, **values)

Expand All @@ -116,6 +112,8 @@ def results_view(request):
filter_zone = request.GET.get("zone", None)

return render(request=request, template_name="eleicao/voter_results.html")


class ResultsCandidateView(ListView):
template_name = "eleicao/voter_results.html"
model = Candidate
Expand All @@ -128,4 +126,4 @@ def get_queryset(self) -> QuerySet[Any]:
if filter_zone:
return Candidate.objects.filter(zone=filter_zone)

return super().get_queryset()
return super().get_queryset()