Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ <h3 class="section_title"><span>Perfil</span></h3>
<p>Data nascimento: {{ candidate.birth_date }}</p>
<p>Estado civil: {{ candidate.marital_status }}</p>
<p>Escolaridade: {{ candidate.education }}</p>
<p>E-mail: {{ candidate.email }}</p>
<p>E-mail: <a href="mailto:{{ candidate.email|lower }}" target="_blank">{{ candidate.email|lower }}</a></p>
{% if candidate.twitter %}<p>Twitter: <a href="{{ candidate.twitter }}" target="_blank">{{ candidate.twitter }}</a></p> {% endif %}
{% if candidate.facebook %}<p>Facebook: <a href="{{ candidate.facebook }}" target="_blank">{{ candidate.facebook }}</a></p> {% endif %}
{% if candidate.instagram %}<p>Instagram: <a href="{{ candidate.instagram }}" target="_blank">{{ candidate.instagram }}</a></p> {% endif %}
<p>Ocupação: {{ candidate.job }}</p>
<p>Total bens: {{ candidate.property_value }}</p>

{% if candidate.projects %}<p>Projetos: {{ candidate.projects }}</p> {% endif %}

<p>Total bens: R$ {{ candidate.property_value|default_if_none:"0" }}</p>

<h3 class="section_title"><span>Financiamento</span></h3>
<br>
<p>Data última atualização: {{ budget.dataUltimaAtualizacaoContas }}</p>
Expand Down
24 changes: 19 additions & 5 deletions django/mdb/candidates/templates/candidates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</div>
<div class="col col-12 col-sm-6 col-lg-4 mt-4">
<h1>Por mais mulheres eleitas no legislativo</h1>


</div>
</div>
</div>
Expand All @@ -16,7 +18,7 @@ <h1>Por mais mulheres eleitas no legislativo</h1>
{% extends "base.html" %}

{% block js %}
<script type="text/javascript" src="/static/assets/js/src/candidate.js"></script>
<script type="text/javascript" src="/static/assets/js/src/candidate.js?v=1"></script>
<script type="text/javascript">CandidateHandler($, "{{host}}")</script>
<script type="text/javascript">
(function($) {
Expand All @@ -32,6 +34,10 @@ <h1>Por mais mulheres eleitas no legislativo</h1>
$partido.show();
}
});


// CandidateHandler($, "{{host}}")

});
})(jQuery);
</script>
Expand All @@ -50,11 +56,19 @@ <h1>Por mais mulheres eleitas no legislativo</h1>

<h2 class="section_title mb-4"><span>Veja as candidaturas femininas deste ano</span></h2>

<div class="form-group search-group">
<input type="text" name="nome" id="nome" class="form-control search-input autocomplete-candidates" placeholder="Buscar por nome da candidata">

<img src="/static/img/icons/icon-search.png" class="search-button">
</div>

<div class="form-group">OU</div>
<!-- lista cargo -->
<div class="form-group">
<select class="selectpicker form-control" id="cargo">
<option value="">Selecione Cargo</option>
<option value="Presidente">Presidente</option>
<option value="Vice-presidente">Vice-presidente</option>
<option value="Senador">Senadora</option>
<option value="Governador">Governadora</option>
<option value="Vice-governador">Vice-governadora</option>
Expand Down Expand Up @@ -143,7 +157,7 @@ <h2 class="section_title mb-4"><span>Veja as candidaturas femininas deste ano</s
</div>
<!-- /lista partidos -->

<!-- lista pauta
<!-- lista pauta
<div class="form-group">
<select class="selectpicker form-control" data-live-search="true" id="pauta">
<option value="">Selecione a Pauta</option>
Expand All @@ -153,7 +167,7 @@ <h2 class="section_title mb-4"><span>Veja as candidaturas femininas deste ano</s

</div>
</div>


</div>
</div><!--/filterbox-->
Expand Down Expand Up @@ -184,13 +198,13 @@ <h1 class="section_title text-center mt-5"><span>Veja os partidos que mais apoia

<div class="row legenda">
<div class="col-1 mt-1 p-2">
<img src="/static/img/icon_person.png" class="img-fluid" alt="Person" />
<img src="/static/img/icon_person.png" class="img-fluid icon-highlight" alt="Person" />
</div>
<div class="col-5 mt-2">
<p>% de mulheres no partido.</p>
</div>
<div class="col-1 mt-1 p-2">
<img src="/static/img/icon_money.png" class="img-fluid" alt="Money" />
<img src="/static/img/icon_money.png" class="img-fluid icon-highlight" alt="Money" />
</div>
<div class="col-5 mt-2">
<p>% de dinheiro destinado às mulheres pelo partido.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ <h1>Por mais mulheres eleitas no legislativo</h1>
<h2 class="section_title text-center pt-3"><span>Sobre</span></h2>
<p class="section_text pt-3">{{ party.about }}</p>

{% if hasPresident or hasVicePresident or hasGovernor or hasViceGovernor %}
<h2 class="section_title text-center pt-3"><span>Candidaturas Majoritárias Femininas</span></h2>
<p class="section_text pt-3">
{% if hasPresident %}Presidente<br>{% endif %}
{% if hasVicePresident %}Vice-Presidente<br>{% endif %}
{% if hasGovernor %}Governador<br>{% endif %}
{% if hasViceGovernor %}Vice-Governador<br>{% endif %}
{% endif %}

<h2 class="section_title text-center pt-3"><span>Espaço às candidaturas<br>femininas no partido</span></h2>

<div class="row">
Expand Down
28 changes: 27 additions & 1 deletion django/mdb/candidates/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def get(self, request):
page_size = int(query.get('page_size') or settings.PAGE_SIZE)
page = int(query.get('page') or 1)

candidates = Candidate.objects.all()
candidates = Candidate.objects.all().order_by('name')


# filter candiadates
if 'ano' in query:
Expand All @@ -89,6 +90,8 @@ def get(self, request):
candidates = candidates.filter(job_role__name=query['cargo'])
if 'pauta' in query:
candidates = candidates.filter(agenda__name=query['pauta'])
if 'nome' in query:
candidates = candidates.filter(name__icontains=query['nome'])

paginated_candidates = candidates[(page-1)*page_size:page*page_size]
serializer = CandidateSerializer(paginated_candidates, many=True)
Expand Down Expand Up @@ -231,9 +234,32 @@ def get_context_data(self, **kwargs):
party = self.get_object()

stats = PartyJobRoleStats.objects.filter(political_party=party)
majoritaryCandidates = Candidate.objects.values_list('name', 'job_role_id').filter(political_party_id=party.id, job_role_id__in=[1,2,3,4], gender='F')
hasPresident = False
hasVicePresident = False
hasGovernor = False
hasViceGovernor = False

for candidate in majoritaryCandidates:

if candidate[1] == 1:
hasPresident = True
if candidate[1] == 2:
hasVicePresident = True
if candidate[1] == 3:
hasGovernor = True
if candidate[1] == 4:
hasViceGovernor = True


charts = StatsSerializer(stats, many=True).data
charts.append(PartySerializer(party).data)

context['hasPresident'] = hasPresident
context['hasVicePresident'] = hasVicePresident
context['hasGovernor'] = hasGovernor
context['hasViceGovernor'] = hasViceGovernor

context['party'] = party
context['party_img'] = party.initials.lower()
context['charts'] = json.dumps(charts)
Expand Down
89 changes: 62 additions & 27 deletions django/static/assets/js/src/candidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ function CandidateHandler($, host) {

this.init = function() {

var selects = [
var fields = [
{
name: 'nome'
},
{
name: 'estado'
},
Expand All @@ -18,21 +21,23 @@ function CandidateHandler($, host) {
}
];

selects.map(function(select) {
this.fetchSelectData(host, select.path, select.name);

fields.map(function(field) {
this.fetchSelectData(host, field.path, field.name);
});

selects.map(function(select) {
this.onSelectRefresh(select.name, '/api/candidates', selects);
fields.map(function(field) {
this.onFieldRefresh(field.name, '/api/candidates', fields);
});

this.registerLoadMoreCandidates(host + '/api/candidates', selects);

this.registerLoadMoreCandidates(host + '/api/candidates', fields);
};

this.registerLoadMoreCandidates = function(host, selects) {
this.registerLoadMoreCandidates = function(host, fields) {
this.$("#loadMoreCandidates").on('click', function (e) {
e.preventDefault();
this.fetchCandidates(host, selects);
this.fetchCandidates(host, fields);
}.bind(this));
};

Expand All @@ -56,12 +61,12 @@ function CandidateHandler($, host) {
};


this.setInfinityScroll = function(id, host, selects) {
this.setInfinityScroll = function(id, host, fields) {
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 1000) {
if (!this.waitingFetchCandidates) {
this.waitingFetchCandidates = true;
this.fetchCandidates(host, selects, this.page);
this.fetchCandidates(host, fields, this.page);
}
}
});
Expand All @@ -85,19 +90,21 @@ function CandidateHandler($, host) {
this.refreshSelectPicker();
};

this.readSelectStates = function(selects){
this.readInputStates = function(inputs){
var query = {};
selects.map(function(select) {
var value = this.$('#' + select.name).val();
inputs.map(function(input) {
var value = this.$('#' + input.name).val();

if (value != undefined && value.length > 0) {
query[select.name] = value;
query[input.name] = value;
}
});
return query;
};

this.fetchCandidates = function(host, selects) {
var query = this.readSelectStates(selects);

this.fetchCandidates = function(host, inputs) {
var query = this.readInputStates(inputs);

query['ano'] = '2018';
query['sexo'] = 'F';
Expand Down Expand Up @@ -184,12 +191,36 @@ function CandidateHandler($, host) {
media.append(statusDiv);
};

this.onSelectRefresh = function(id, host, selects) {
this.$('#'+id).change(function() {
this.page = 0;
this.clearCandidates();
this.fetchCandidates(host, selects);
}.bind(this));
this.onFieldRefresh = function(id, host, fields) {

var type = this.$('#'+id).attr('type');

if(type){
this.$('#'+id).next('.search-button').click(function() {
this.setCandidate(host, fields)
}.bind(this));

this.$('#'+id).keypress(function(event) {
if(event.keyCode === 13){
this.setCandidate(host, fields)
}
}.bind(this));
}
else{


this.$('#'+id).change(function() {
this.$('#nome').val('');
this.setCandidate(host, fields)
}.bind(this));
}

};

this.setCandidate = function(host, fields){
this.page = 0;
this.clearCandidates();
this.fetchCandidates(host, fields);
};

this.clearCandidates = function() {
Expand All @@ -215,7 +246,7 @@ function CandidateHandler($, host) {
this.processImgName = function(party) {
return party.toLowerCase().replace(/ /g, '');
};

this.getPartyImg = function(candidate) {
var p = this.processImgName(candidate.political_party_initials);
var path = `/static/img/partidos/${p}.png`;
Expand Down Expand Up @@ -269,7 +300,9 @@ $.getJSON("/api/parties/", function (response) {
// load view
function getPartyDetails(partyInfo) {
var partyImg = this.processImgName(partyInfo.initials);

var lblLeftWomen = (partyInfo.women_pct > 0) ? 'left: '+Math.round(100*partyInfo.women_pct+1)+'%' : '';
var lblLeftMoney = (partyInfo.money_women_pct > 0) ? 'left: '+Math.round(100*partyInfo.money_women_pct+1)+'%' : '';

return '<div class="item-party">' +
'<div class="row mb-4 justify-content-center">' +
'<div class="col-4 text-center">' +
Expand All @@ -281,11 +314,12 @@ function getPartyDetails(partyInfo) {

'<div class="row">' +
'<div class="col-1 mt-1 p-1">' +
'<img src="/static/img/icon_person.png" class="img-fluid" alt="Person" />' +
'<img src="/static/img/icon_person.png" class="img-fluid icon-highlight" alt="Person" />' +
'</div>'+
'<div class="col-11">'+
'<div class="label-progress" style="'+lblLeftWomen+'">'+Math.round(100*partyInfo.women_pct)+'%</div>'+
'<div class="arrow-progress">'+
'<div class="arrow-bar" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>' +
'<div class="arrow-bar" role="progressbar" style="width: '+Math.round(100*partyInfo.women_pct)+'%" aria-valuenow="'+Math.round(100*partyInfo.women_pct)+'%" aria-valuemin="0" aria-valuemax="100"></div>' +
'</div>' +
'<div class="progress">' +
'<div class="progress-bar" role="progressbar" style="width: '+100*partyInfo.women_pct+'%" aria-valuenow="'+partyInfo.women_pct+'" aria-valuemin="0" aria-valuemax="100"></div>' +
Expand All @@ -300,8 +334,9 @@ function getPartyDetails(partyInfo) {
'<img src="/static/img/icon_money.png" class="img-fluid" alt="Money" />' +
'</div>' +
'<div class="col-11">' +
'<div class="label-progress" style="'+lblLeftMoney+'">'+Math.round(100*partyInfo.money_women_pct)+'%</div>'+
'<div class="arrow-progress">' +
'<div class="arrow-bar" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>' +
'<div class="arrow-bar" role="progressbar" style="width: '+Math.round(100*partyInfo.money_women_pct)+'%" aria-valuenow="'+Math.round(100*partyInfo.money_women_pct)+'%" aria-valuemin="0" aria-valuemax="100"></div>' +
'</div>' +
'<div class="progress">' +
'<div class="progress-bar" role="progressbar" style="width: '+ 100 * partyInfo.money_women_pct + '%" aria-valuenow="' + partyInfo.money_women_pct + '" aria-valuemin="0" aria-valuemax="100"></div>' +
Expand Down
Loading