-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from fecgov/schedule-a-model
Schedule A model
- Loading branch information
Showing
20 changed files
with
440 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# .coveragerc to control coverage.py | ||
# https://coverage.readthedocs.io/en/coverage-4.3.3/source.html#execution | ||
[run] | ||
omit = | ||
# Excluding dev scripts from code coverage | ||
./scripts/json_schema_to_django_model.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
Empty file.
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 @@ | ||
# Register your models here. |
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,9 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class SchedAConfig(AppConfig): | ||
name = 'fecfiler.scha_transactions' | ||
|
||
def ready(self): | ||
# Implicitly connect a signal handlers decorated with @receiver. | ||
from . import signals # noqa |
71 changes: 71 additions & 0 deletions
71
django-backend/fecfiler/scha_transactions/migrations/0001_initial.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,71 @@ | ||
# Generated by Django 3.2.11 on 2022-02-03 01:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SchATransaction', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('form_type', models.CharField(max_length=8)), | ||
('filer_committee_id_number', models.CharField(max_length=9)), | ||
('transaction_id', models.CharField(max_length=20)), | ||
('back_reference_tran_id_number', models.CharField(blank=True, max_length=20, null=True)), | ||
('back_reference_sched_name', models.CharField(blank=True, max_length=8, null=True)), | ||
('entity_type', models.CharField(max_length=3)), | ||
('contributor_organization_name', models.CharField(max_length=200)), | ||
('contributor_last_name', models.CharField(max_length=30)), | ||
('contributor_first_name', models.CharField(max_length=20)), | ||
('contributor_middle_name', models.CharField(blank=True, max_length=20, null=True)), | ||
('contributor_prefix', models.CharField(blank=True, max_length=10, null=True)), | ||
('contributor_suffix', models.CharField(blank=True, max_length=10, null=True)), | ||
('contributor_street_1', models.CharField(blank=True, max_length=34, null=True)), | ||
('contributor_street_2', models.CharField(blank=True, max_length=34, null=True)), | ||
('contributor_city', models.CharField(blank=True, max_length=30, null=True)), | ||
('contributor_state', models.CharField(blank=True, max_length=2, null=True)), | ||
('contributor_zip', models.CharField(blank=True, max_length=9, null=True)), | ||
('election_code', models.CharField(blank=True, max_length=5, null=True)), | ||
('election_other_description', models.CharField(blank=True, max_length=20, null=True)), | ||
('contribution_date', models.IntegerField(blank=True, null=True)), | ||
('contribution_amount', models.IntegerField(blank=True, null=True)), | ||
('contribution_aggregate', models.IntegerField(blank=True, null=True)), | ||
('contribution_purpose_descrip', models.CharField(blank=True, max_length=100, null=True)), | ||
('contributor_employer', models.CharField(blank=True, max_length=38, null=True)), | ||
('contributor_occupation', models.CharField(blank=True, max_length=38, null=True)), | ||
('donor_committee_fec_id', models.CharField(blank=True, max_length=9, null=True)), | ||
('donor_committee_name', models.CharField(blank=True, max_length=200, null=True)), | ||
('donor_candidate_fec_id', models.CharField(blank=True, max_length=9, null=True)), | ||
('donor_candidate_last_name', models.CharField(blank=True, max_length=30, null=True)), | ||
('donor_candidate_first_name', models.CharField(blank=True, max_length=20, null=True)), | ||
('donor_candidate_middle_name', models.CharField(blank=True, max_length=20, null=True)), | ||
('donor_candidate_prefix', models.CharField(blank=True, max_length=10, null=True)), | ||
('donor_candidate_suffix', models.CharField(blank=True, max_length=10, null=True)), | ||
('donor_candidate_office', models.CharField(blank=True, max_length=1, null=True)), | ||
('donor_candidate_state', models.CharField(blank=True, max_length=2, null=True)), | ||
('donor_candidate_district', models.IntegerField(blank=True, null=True)), | ||
('conduit_name', models.CharField(blank=True, max_length=200, null=True)), | ||
('conduit_street1', models.CharField(blank=True, max_length=34, null=True)), | ||
('conduit_street2', models.CharField(blank=True, max_length=34, null=True)), | ||
('conduit_city', models.CharField(blank=True, max_length=30, null=True)), | ||
('conduit_state', models.CharField(blank=True, max_length=2, null=True)), | ||
('conduit_zip', models.CharField(blank=True, max_length=9, null=True)), | ||
('memo_code', models.CharField(blank=True, max_length=1, null=True)), | ||
('memo_text_description', models.CharField(blank=True, max_length=100, null=True)), | ||
('reference_to_si_or_sl_system_code_that_identifies_the_account', models.CharField(blank=True, max_length=9, null=True)), | ||
('transaction_type_identifier', models.CharField(blank=True, max_length=12, null=True)), | ||
('created', models.DateField(auto_now_add=True)), | ||
('updated', models.DateField(auto_now=True)), | ||
], | ||
options={ | ||
'db_table': 'scha_transactions', | ||
}, | ||
), | ||
] |
Empty file.
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,58 @@ | ||
from django.db import models | ||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SchATransaction(models.Model): | ||
"""Generated model from json schema""" | ||
form_type = models.CharField(null=False, blank=False, max_length=8) | ||
filer_committee_id_number = models.CharField(null=False, blank=False, max_length=9) | ||
transaction_id = models.CharField(null=False, blank=False, max_length=20) | ||
back_reference_tran_id_number = models.CharField(null=True, blank=True, max_length=20) | ||
back_reference_sched_name = models.CharField(null=True, blank=True, max_length=8) | ||
entity_type = models.CharField(null=False, blank=False, max_length=3) | ||
contributor_organization_name = models.CharField(null=False, blank=False, max_length=200) | ||
contributor_last_name = models.CharField(null=False, blank=False, max_length=30) | ||
contributor_first_name = models.CharField(null=False, blank=False, max_length=20) | ||
contributor_middle_name = models.CharField(null=True, blank=True, max_length=20) | ||
contributor_prefix = models.CharField(null=True, blank=True, max_length=10) | ||
contributor_suffix = models.CharField(null=True, blank=True, max_length=10) | ||
contributor_street_1 = models.CharField(null=True, blank=True, max_length=34) | ||
contributor_street_2 = models.CharField(null=True, blank=True, max_length=34) | ||
contributor_city = models.CharField(null=True, blank=True, max_length=30) | ||
contributor_state = models.CharField(null=True, blank=True, max_length=2) | ||
contributor_zip = models.CharField(null=True, blank=True, max_length=9) | ||
election_code = models.CharField(null=True, blank=True, max_length=5) | ||
election_other_description = models.CharField(null=True, blank=True, max_length=20) | ||
contribution_date = models.IntegerField(null=True, blank=True) | ||
contribution_amount = models.IntegerField(null=True, blank=True) | ||
contribution_aggregate = models.IntegerField(null=True, blank=True) | ||
contribution_purpose_descrip = models.CharField(null=True, blank=True, max_length=100) | ||
contributor_employer = models.CharField(null=True, blank=True, max_length=38) | ||
contributor_occupation = models.CharField(null=True, blank=True, max_length=38) | ||
donor_committee_fec_id = models.CharField(null=True, blank=True, max_length=9) | ||
donor_committee_name = models.CharField(null=True, blank=True, max_length=200) | ||
donor_candidate_fec_id = models.CharField(null=True, blank=True, max_length=9) | ||
donor_candidate_last_name = models.CharField(null=True, blank=True, max_length=30) | ||
donor_candidate_first_name = models.CharField(null=True, blank=True, max_length=20) | ||
donor_candidate_middle_name = models.CharField(null=True, blank=True, max_length=20) | ||
donor_candidate_prefix = models.CharField(null=True, blank=True, max_length=10) | ||
donor_candidate_suffix = models.CharField(null=True, blank=True, max_length=10) | ||
donor_candidate_office = models.CharField(null=True, blank=True, max_length=1) | ||
donor_candidate_state = models.CharField(null=True, blank=True, max_length=2) | ||
donor_candidate_district = models.IntegerField(null=True, blank=True) | ||
conduit_name = models.CharField(null=True, blank=True, max_length=200) | ||
conduit_street1 = models.CharField(null=True, blank=True, max_length=34) | ||
conduit_street2 = models.CharField(null=True, blank=True, max_length=34) | ||
conduit_city = models.CharField(null=True, blank=True, max_length=30) | ||
conduit_state = models.CharField(null=True, blank=True, max_length=2) | ||
conduit_zip = models.CharField(null=True, blank=True, max_length=9) | ||
memo_code = models.CharField(null=True, blank=True, max_length=1) | ||
memo_text_description = models.CharField(null=True, blank=True, max_length=100) | ||
reference_to_si_or_sl_system_code_that_identifies_the_account = models.CharField(null=True, blank=True, max_length=9) | ||
transaction_type_identifier = models.CharField(null=True, blank=True, max_length=12) | ||
created = models.DateField(auto_now_add=True) | ||
updated = models.DateField(auto_now=True) | ||
|
||
class Meta: | ||
db_table = 'scha_transactions' |
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,27 @@ | ||
"""Logs Schedule A Transaction events | ||
We use signals to log deletes rather than overwriting delete() | ||
to handle bulk delete cases | ||
https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods | ||
We use signals to log saves to be consistent with delete logging | ||
""" | ||
from django.db.models.signals import post_save, post_delete | ||
from django.dispatch import receiver | ||
from .models import SchATransaction | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(post_save, sender=SchATransaction) | ||
def log_post_save(sender, instance, created, **kwargs): | ||
action = 'created' if created else 'updated' | ||
logger.info('Schedule A Transaction: %s was %s', | ||
instance.transaction_id, action) | ||
|
||
|
||
@receiver(post_delete, sender=SchATransaction) | ||
def log_post_delete(sender, instance, **kwargs): | ||
logger.info('Schedule A Transaction: %s was deleted', | ||
instance.transaction_id) |
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,54 @@ | ||
from django.test import TestCase | ||
from django.core.exceptions import ValidationError | ||
from .models import SchATransaction | ||
|
||
|
||
class SchATransactionTestCase(TestCase): | ||
""" Test module for inserting a sched_a item""" | ||
|
||
def setUp(self): | ||
self.sa_trans = SchATransaction( | ||
form_type="SA11AI", | ||
filer_committee_id_number="C00123456", | ||
transaction_id="A56123456789-1234", | ||
entity_type="IND", | ||
contributor_organization_name="John Smith & Co.", | ||
contributor_first_name="John", | ||
contributor_last_name="Smith" | ||
) | ||
|
||
self.bad_trans = SchATransaction( | ||
form_type="SA11AI", | ||
filer_committee_id_number="C00123456", | ||
transaction_id="A56123456789-4567", | ||
entity_type="IND", | ||
contributor_organization_name="Some Org", | ||
contributor_first_name="John", | ||
) | ||
|
||
self.trans_to_del = SchATransaction( | ||
form_type="SA11AI", | ||
filer_committee_id_number="C00123456", | ||
transaction_id="A56123456789-del", | ||
entity_type="IND", | ||
contributor_organization_name="Group", | ||
contributor_first_name="John", | ||
contributor_last_name="Smith" | ||
) | ||
|
||
def test_full_clean(self): | ||
self.sa_trans.full_clean() | ||
self.assertRaises(ValidationError, self.bad_trans.full_clean) | ||
|
||
def test_save(self): | ||
self.sa_trans.save() | ||
trans = SchATransaction.objects.get(transaction_id="A56123456789-1234") | ||
self.assertIsInstance(trans, SchATransaction) | ||
self.assertEquals(trans.transaction_id, "A56123456789-1234") | ||
|
||
def test_delete(self): | ||
self.trans_to_del.save() | ||
hit = SchATransaction.objects.get(transaction_id="A56123456789-del") | ||
self.assertEquals(hit.transaction_id, "A56123456789-del") | ||
hit.delete() | ||
self.assertRaises(SchATransaction.DoesNotExist, SchATransaction.objects.get, transaction_id="A56123456789-del") |
Empty file.
Empty file.
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
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
Oops, something went wrong.