Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matheus Fernandes <matheus.souza.fernandes@gmail.com>
- Loading branch information
1 parent
2c6c8e5
commit e75e79d
Showing
10 changed files
with
291 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/pygov_br/django_apps/camara_deputados/data_importer/proposal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from django.db import transaction | ||
from pygov_br.django_apps.base import BaseDataImporter | ||
from pygov_br.django_apps.camara_deputados import models | ||
from pygov_br.camara_deputados import cd | ||
|
||
|
||
class ProposalTypeImporter(BaseDataImporter): | ||
|
||
field_relation = { | ||
"id": "id", | ||
"is_active": "ativa", | ||
"description": "descricao", | ||
"gender": "genero", | ||
"initials": "tipoSigla", | ||
} | ||
|
||
def get_model(self): | ||
return models.ProposalType | ||
|
||
def get_data(self): | ||
return cd.proposals.types() | ||
|
||
|
||
class ProposalImporter(BaseDataImporter): | ||
|
||
field_relation = { | ||
"id": "id", | ||
"year": "ano", | ||
"number": "numero", | ||
"submission_date": "datApresentacao", | ||
"name": "nome", | ||
"summary": "txtEmenta", | ||
"summary_explanation": "txtExplicacaoEmenta", | ||
"proposal_type": "tipoProposicao", | ||
} | ||
|
||
def get_model(self): | ||
return models.Proposal | ||
|
||
def get_data(self): | ||
return cd.proposals.filter(proposal_type='PL', year=2016) | ||
|
||
def clean_author(self, data): | ||
if data['idecadastro']: | ||
return models.Deputy.objects.get(enrollment_id=data['idecadastro']) | ||
else: | ||
return None | ||
|
||
def clean_proposal_type(self, data): | ||
return models.ProposalType.objects.get(initials=data['sigla']) | ||
|
||
@transaction.atomic | ||
def after_save_object(self, obj): | ||
extra_info = cd.proposals.get(proposal_type=obj.proposal_type.initials, | ||
proposal_number=obj.number, | ||
year=obj.year) | ||
obj.indexes = extra_info['Indexacao'] | ||
obj.link = extra_info['LinkInteiroTeor'] | ||
if extra_info['ideCadastro']: | ||
try: | ||
author = models.Deputy.objects.get( | ||
id=extra_info['ideCadastro'] | ||
) | ||
obj.author = author | ||
except models.Deputy.DoesNotExist: | ||
print('nao existe', extra_info['ideCadastro']) | ||
|
||
obj.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/pygov_br/django_apps/camara_deputados/migrations/0002_auto_20170719_2250.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2017-07-19 22:50 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('camara_deputados', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Proposal', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('year', models.IntegerField()), | ||
('number', models.IntegerField()), | ||
('submission_date', models.DateField()), | ||
('name', models.CharField(max_length=500)), | ||
('summary', models.TextField()), | ||
('summary_explanation', models.TextField()), | ||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='camara_deputados.Deputy')), | ||
], | ||
options={ | ||
'verbose_name': 'Proposal', | ||
'verbose_name_plural': 'Proposals', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='ProposalType', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('is_active', models.BooleanField()), | ||
('description', models.CharField(max_length=500)), | ||
('gender', models.CharField(max_length=2)), | ||
('initials', models.CharField(max_length=50)), | ||
], | ||
options={ | ||
'verbose_name': 'Proposal Type', | ||
'verbose_name_plural': 'Proposal Types', | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='proposal', | ||
name='proposal_type', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='camara_deputados.ProposalType'), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
src/pygov_br/django_apps/camara_deputados/migrations/0003_auto_20170719_2307.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2017-07-19 23:07 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('camara_deputados', '0002_auto_20170719_2250'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='proposal', | ||
name='summary', | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name='proposal', | ||
name='summary_explanation', | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
src/pygov_br/django_apps/camara_deputados/migrations/0004_auto_20170719_2314.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2017-07-19 23:14 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('camara_deputados', '0003_auto_20170719_2307'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='proposal', | ||
name='author', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='camara_deputados.Deputy'), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
src/pygov_br/django_apps/camara_deputados/migrations/0005_auto_20170719_2330.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2017-07-19 23:30 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('camara_deputados', '0004_auto_20170719_2314'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='proposal', | ||
name='indexes', | ||
field=models.CharField(blank=True, max_length=500, null=True), | ||
), | ||
migrations.AddField( | ||
model_name='proposal', | ||
name='link', | ||
field=models.CharField(blank=True, max_length=500, null=True), | ||
), | ||
] |
21 changes: 21 additions & 0 deletions
21
src/pygov_br/django_apps/camara_deputados/migrations/0006_auto_20170720_2347.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11 on 2017-07-20 23:47 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('camara_deputados', '0005_auto_20170719_2330'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='proposal', | ||
name='author', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='proposals', to='camara_deputados.Deputy'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters