Skip to content

Commit

Permalink
Refactor show convergency to model
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatas1n committed Sep 19, 2022
1 parent faadf2c commit 8cb2f50
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-09-19 11:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('candidate', '0027_set_url_fields'),
]

operations = [
migrations.AddField(
model_name='candidatepage',
name='show_convergency',
field=models.BooleanField(default=True),
),
]
31 changes: 31 additions & 0 deletions landing/candidate/migrations/0029_set_convergency_visibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.12 on 2022-09-19 11:15

from django.db import migrations, models
from candidate.models import CandidatePage

hide_convergency = [90, 878, 4610, 90842, 105534, 123756, 141401, 141480, 141552,
160517, 204433, 207309, 214865, 219585, 219592,
204563, 122466, None]

def set_convergency(apps, schema_editor):
live_candidates = CandidatePage.objects.all().live()
for candidate in live_candidates:
is_show = candidate.id_autor not in hide_convergency
candidate.show_convergency = is_show
candidate.save()

def unset_convergency(apps, schema_editor):
live_candidates = CandidatePage.objects.all().live()
for candidate in live_candidates:
candidate.show_convergency = None
candidate.save()

class Migration(migrations.Migration):

dependencies = [
('candidate', '0028_candidatepage_show_convergency'),
]

operations = [
migrations.RunPython(set_convergency, unset_convergency),
]
11 changes: 5 additions & 6 deletions landing/candidate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from wagtailmetadata.models import MetadataPageMixin
from wagtail.core.models import Page
from wagtail.search import index
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel
from wagtail.admin.edit_handlers import FieldPanel, StreamFieldPanel, InlinePanel
from wagtail.core.fields import StreamField
from wagtailstreamforms.models import FormSubmission

Expand All @@ -17,7 +17,7 @@
from django.db.models.signals import post_save
from django.dispatch import receiver

from candidate.util import uf_list, subjects_list, subject_dict, subject_descriptions, keywords, hide_convergency
from candidate.util import uf_list, subjects_list, subject_dict, subject_descriptions, keywords
from candidate.factories import SurveyCandidateFactory

class GenderChoices(models.TextChoices):
Expand All @@ -30,6 +30,8 @@ class CandidatePage(MetadataPageMixin, Page):
DEPUTADO_CHARGE_TEXT = "Deputado(a) Federal"
SENADOR_CHARGE_TEXT = "Senador(a)"

show_convergency = models.BooleanField(blank=False, null=False, default=True)

id_autor = models.IntegerField(blank=True, null=True, unique=True)
id_parlametria = models.IntegerField(blank=True, null=True, unique=True)
id_serenata = models.IntegerField(blank=True, null=True, unique=True)
Expand Down Expand Up @@ -161,14 +163,11 @@ def is_senador(self) -> bool:
def keywords(self):
return keywords

@property
def show_convergency(self):
return self.id_autor not in hide_convergency

content_panels = Page.content_panels + [
FieldPanel("id_autor", classname="full"),
FieldPanel("id_parlametria", classname="full"),
FieldPanel("id_serenata", classname="full"),
FieldPanel("show_convergency"),
FieldPanel('campaign_name'),
FieldPanel('party'),
FieldPanel('cpf'),
Expand Down
1 change: 0 additions & 1 deletion landing/candidate/templates/candidate/candidate_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ <h2 class="candidate__name">{{ page.campaign_name }}</h2>
</div>

<div class="tabs">

{% if page.opinions_answers %}
<button onclick="openTab('result')" class="tab overline result">Resultados enquete</button>
{% endif %}
Expand Down
5 changes: 0 additions & 5 deletions landing/candidate/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,3 @@ def url_to_row_iterator(url: str) -> Generator[str, None, None]:
key = k[0]
keywords.append(key)
keywords.append(k)


hide_convergency = [90, 878, 4610, 90842, 105534, 123756, 141401, 141480, 141552,
160517, 204433, 207309, 214865, 219585, 219592,
204563,122466, None]

0 comments on commit 8cb2f50

Please sign in to comment.