Skip to content

Commit

Permalink
Merge branch 'release/votepeloclima' into feature/dashboard-others-in…
Browse files Browse the repository at this point in the history
…formations
  • Loading branch information
sergiomario committed Sep 3, 2024
2 parents 09ae8bf + de0f3f5 commit 8bd244c
Show file tree
Hide file tree
Showing 57 changed files with 1,630 additions and 270 deletions.
Empty file.
9 changes: 9 additions & 0 deletions app/contrib/partners/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.contrib import admin
from adminsortable2.admin import SortableAdminMixin

from .models import Partner


@admin.register(Partner)
class PartnerAdmin(SortableAdminMixin, admin.ModelAdmin):
list_display = ("name", "link")
6 changes: 6 additions & 0 deletions app/contrib/partners/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PartnersConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "contrib.partners"
29 changes: 29 additions & 0 deletions app/contrib/partners/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2 on 2024-08-30 23:17

from django.db import migrations, models
import django.db.models.deletion
import filer.fields.file


class Migration(migrations.Migration):

initial = True

dependencies = [
('filer', '0017_image__transparent'),
]

operations = [
migrations.CreateModel(
name='Partner',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, verbose_name='Nome da Parceria')),
('link', models.URLField(blank=True, null=True, verbose_name='Link da Parceria')),
('logo', filer.fields.file.FilerFileField(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='filer.file', verbose_name='Imagem')),
],
options={
'verbose_name': 'Parceiro',
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2 on 2024-09-02 21:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('partners', '0001_initial'),
]

operations = [
migrations.AlterModelOptions(
name='partner',
options={'ordering': ['position'], 'verbose_name': 'Parceiro'},
),
migrations.AddField(
model_name='partner',
name='position',
field=models.PositiveIntegerField(default=0),
),
]
18 changes: 18 additions & 0 deletions app/contrib/partners/migrations/0003_alter_partner_position.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2024-09-02 21:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('partners', '0002_alter_partner_options_partner_position'),
]

operations = [
migrations.AlterField(
model_name='partner',
name='position',
field=models.PositiveIntegerField(default=0, verbose_name='Posição'),
),
]
Empty file.
24 changes: 24 additions & 0 deletions app/contrib/partners/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models
from django.utils.translation import gettext_lazy as _

from filer.fields.file import FilerFileField


class Partner(models.Model):
name = models.CharField(max_length=100, verbose_name="Nome da Parceria")
logo = FilerFileField(verbose_name=_("Imagem"), on_delete=models.SET_NULL, null=True, blank=True)
link = models.URLField(blank=True, null=True, verbose_name="Link da Parceria")

position = models.PositiveIntegerField(
default=0,
blank=False,
null=False,
verbose_name="Posição"
)

def __str__(self):
return self.name

class Meta:
verbose_name = "Parceiro"
ordering = ["position"]
5 changes: 5 additions & 0 deletions app/contrib/partners/templates/partners/partners_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% for partner in partners %}
<a href="{{ partner.link }}" target="_blank" rel="noopener noreferrer">
<img src="{{ partner.logo.url }}" alt="{{ partner.name }}">
</a>
{% endfor %}
9 changes: 9 additions & 0 deletions app/contrib/partners/templatetags/partners_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import template
from ..models import Partner

register = template.Library()

@register.inclusion_tag("partners/partners_list.html")
def show_partners():
partners = Partner.objects.all()
return {'partners': partners}
5 changes: 1 addition & 4 deletions app/org_eleicoes/eleicaodoano/eleicao/csv/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
def get_states(column_label="name"):
import csv

<<<<<<<< HEAD:app/org_eleicoes/eleicao/csv/choices.py
csv_filename = settings.BASE_DIR / "eleicoes/eleicao/csv/states.csv"
========
csv_filename = settings.BASE_DIR / "org_eleicoes/eleicaodoano/eleicao/csv/states.csv"
>>>>>>>> release/votepeloclima:app/org_eleicoes/eleicaodoano/eleicao/csv/choices.py

states = []
with open(csv_filename) as f:
reader = csv.DictReader(f)
Expand Down
1 change: 1 addition & 0 deletions app/org_eleicoes/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ djangocms-video
djangocms_snippet
djangocms-frontend>=1.2.1
django-prometheus
django-filer==3.1.3
# Authentication all platforms
# django-allauth
bcrypt
Expand Down
76 changes: 74 additions & 2 deletions app/org_eleicoes/votepeloclima/candidature/admin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,85 @@
from django.contrib import admin
from django import forms
from entangled.forms import EntangledModelForm

from .models import Candidature, CandidatureFlow


class CandidatureAdmin(admin.ModelAdmin):
search_fields = ("legal_name", "ballot_name", "email", "political_party")
list_display = ("legal_name", "email", "political_party", "status")
list_display = ("legal_name", "email", "political_party", "status", "updated_at")
ordering = ("updated_at", )

def has_add_permission(self, request):
return False

def has_change_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


class CandidatureFlowAdminForm(EntangledModelForm):
legal_name = forms.CharField(label='Nome Legal', required=True)
cpf = forms.CharField(label='CPF', required=True)
email = forms.EmailField(label='Email', required=True)
birth_date = forms.DateField(
label='Data de Nascimento',
required=False,
widget=forms.DateInput(attrs={'type': 'date'})
)
ballot_name = forms.CharField(label='Nome na Urna', required=True)
number_id = forms.CharField(label='Número de Identificação', required=True)
intended_position = forms.CharField(label='Cargo Pretendido', required=True)
state = forms.CharField(label='Estado', required=True)
city = forms.CharField(label='Cidade', required=True)
political_party = forms.CharField(label='Partido Político', required=True)
deputy_mayor = forms.CharField(label='Vice-prefeito', required=False)
deputy_mayor_political_party = forms.CharField(label='Partido do Vice-prefeito', required=False)

class Meta:
model = CandidatureFlow
entangled_fields = {'properties': [
'legal_name', 'cpf', 'email', 'birth_date',
'ballot_name', 'number_id', 'intended_position',
'state', 'city', 'political_party',
'deputy_mayor', 'deputy_mayor_political_party'
]}
untangled_fields = ['photo', 'video', 'status']


class CandidatureFlowAdmin(admin.ModelAdmin):
form = CandidatureFlowAdminForm
list_filter = ("status", )
list_display = ("legal_name", "email", "political_party", "status")
list_display = ("legal_name", "email", "political_party", "status", "created_at", "updated_at")
ordering = ("updated_at", )

fieldsets = (
(None, {
'fields': ('photo', 'video', 'status')
}),
('Informações Pessoais', {
'fields': (
'legal_name',
'cpf',
'email',
'birth_date'
)
}),
('Dados de Candidatura', {
'fields': (
'ballot_name',
'number_id',
'intended_position',
'state',
'city',
'political_party',
'deputy_mayor',
'deputy_mayor_political_party'
)
}),
)

@admin.display
def legal_name(self, obj):
Expand All @@ -29,6 +95,12 @@ def political_party(self, obj):

def has_add_permission(self, request):
return False

def has_change_permission(self, request, obj=None):
return False

def has_delete_permission(self, request, obj=None):
return False


admin.site.register(Candidature, CandidatureAdmin)
Expand Down
55 changes: 45 additions & 10 deletions app/org_eleicoes/votepeloclima/candidature/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import sys

from django import forms
Expand Down Expand Up @@ -161,14 +162,14 @@ def __init__(
text_help_text=None,
help_text=None,
attrs=None,
max_length=None
max_length=None,
):

if attrs is None:
attrs = {}
if max_length:
attrs['maxlength'] = max_length
attrs["maxlength"] = max_length

widgets = [
SwitchInput(
attrs={"data-checktext": ""}, label=checkbox_label, help_text=help_text
Expand Down Expand Up @@ -231,7 +232,7 @@ def __init__(
text_label=text_label,
text_help_text=text_help_text,
help_text=help_text,
max_length=max_length
max_length=max_length,
)

super().__init__(
Expand Down Expand Up @@ -293,7 +294,8 @@ def decompress(self, value):
return value
if value is None:
return []
return [v.strip() for v in value.split(",")]

return [v.strip() for v in value.split("|")]

def value_from_datadict(self, data, files, name):
values = []
Expand Down Expand Up @@ -358,7 +360,7 @@ def __init__(
size=5,
item_label=None,
add_button_text=None,
delimiter=",",
delimiter="|",
max_length=None,
min_length=None,
placeholder=None,
Expand Down Expand Up @@ -388,9 +390,9 @@ def get_bound_field(self, form, field_name):
class ToogleButtonInput(forms.CheckboxInput):
template_name = "forms/widgets/toggle_button.html"

@property
def media(self):
return forms.Media(css={"screen": ["css/icons.css"]})
# @property
# def media(self):
# return forms.Media(css={"screen": ["css/icons.css"]})

def __init__(self, text_html, icon_name=None, *args, **kwargs):
self.text_html = text_html
Expand Down Expand Up @@ -462,10 +464,43 @@ def clean(self, value, initial):
return value


class ImageField(forms.ImageField):

def __init__(
self, *, max_size=10, max_length=None, allow_empty_file=False, **kwargs
):
super().__init__(
max_length=max_length, allow_empty_file=allow_empty_file, **kwargs
)
# 10MB
self.max_size = max_size * 1024 * 1024
self.widget.attrs["accept"] = "image/png,image/jpeg"

def clean(self, value, initial):
value = super().clean(value, initial)
if value.size > self.max_size:
raise forms.ValidationError(
"Por favor, escolha uma imagem com tamanho de até %s. Tamanho Atual %s"
% (filesizeformat(self.max_size), filesizeformat(value.size))
)

return value


class HTMLBooleanField(forms.BooleanField):

def get_bound_field(self, form, field_name):
bound_field = forms.BoundField(form, self, field_name)
bound_field.label = mark_safe(bound_field.label)

return bound_field


class ButtonCheckboxSelectMultiple(forms.CheckboxSelectMultiple):
template_name = "forms/widgets/button_input_select.html"
option_template_name = "forms/widgets/button_input_option.html"


class ButtonRadioSelect(forms.RadioSelect):
template_name = "forms/widgets/button_input_select.html"
option_template_name = "forms/widgets/button_input_option.html"
Empty file.
Loading

0 comments on commit 8bd244c

Please sign in to comment.