Skip to content

Commit

Permalink
Merge pull request #141 from fecgov/release/sprint-9
Browse files Browse the repository at this point in the history
Release/sprint 9
  • Loading branch information
dheitzer authored Jun 23, 2022
2 parents af8d196 + 41bade6 commit 588c33a
Show file tree
Hide file tree
Showing 12 changed files with 383 additions and 49 deletions.
2 changes: 1 addition & 1 deletion bin/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cd django-backend

# Run migrations
./manage.py migrate --noinput
./manage.py migrate --noinput > migrate.out

# Run application
python wait_for_db.py && gunicorn --bind 0.0.0.0:8080 fecfiler.wsgi -w 9 -t 200
202 changes: 202 additions & 0 deletions django-backend/fecfiler/f3x_summaries/fixtures/report_code_labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
[
{
"model": "f3x_summaries.reportcodelabel",
"pk": 1,
"fields": {
"label": "APRIL 15 (Q1)",
"report_code": "Q1"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 2,
"fields": {
"label": "JULY 15 (Q2)",
"report_code": "Q2"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 3,
"fields": {
"label": "OCTOBER 15 (Q3)",
"report_code": "Q3"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 4,
"fields": {
"label": "JANUARY 31 (YE)",
"report_code": "YE"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 5,
"fields": {
"label": "TERMINATION (TER)",
"report_code": "TER"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 6,
"fields": {
"label": "JANUARY 31 (31)",
"report_code": "MY"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 7,
"fields": {
"label": "GENERAL (12G)",
"report_code": "12G"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 8,
"fields": {
"label": "PRIMARY (12P)",
"report_code": "12P"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 9,
"fields": {
"label": "RUNOFF (12R)",
"report_code": "12R"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 10,
"fields": {
"label": "SPECIAL (12S)",
"report_code": "12S"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 11,
"fields": {
"label": "CONVENTION (12C)",
"report_code": "12C"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 12,
"fields": {
"label": "GENERAL (30G)",
"report_code": "30G"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 13,
"fields": {
"label": "RUNOFF (30R)",
"report_code": "30R"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 14,
"fields": {
"label": "SPECIAL (30S)",
"report_code": "30S"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 15,
"fields": {
"label": "FEBRUARY 20 (M2)",
"report_code": "M2"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 16,
"fields": {
"label": "MARCH 30 (M3)",
"report_code": "M3"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 17,
"fields": {
"label": "APRIL 20 (M4)",
"report_code": "M4"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 18,
"fields": {
"label": "MAY 20 (M5)",
"report_code": "M5"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 19,
"fields": {
"label": "JUNE 20 (M6)",
"report_code": "M6"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 20,
"fields": {
"label": "JULY 20 (M7)",
"report_code": "M7"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 21,
"fields": {
"label": "AUGUST 20 (M8)",
"report_code": "M8"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 22,
"fields": {
"label": "SEPTEMBER 20 (M9)",
"report_code": "M9"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 23,
"fields": {
"label": "OCTOBER 20 (M10)",
"report_code": "M10"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 24,
"fields": {
"label": "NOVEMBER 20 (M11)",
"report_code": "M11"
}
},
{
"model": "f3x_summaries.reportcodelabel",
"pk": 25,
"fields": {
"label": "DECEMBER 20 (M12)",
"report_code": "M12"
}
}
]
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
# Generated by Django 3.2.12 on 2022-05-16 01:16

from fecfiler.f3x_summaries.models import F3XSummary
from django.db import migrations, models


def convert_fecfile_booleans(apps, schema_editor):
for f3x_summary in F3XSummary.objects.all():
f3x_summary.change_of_address = (
True if f3x_summary.change_of_address in ["true", "X"] else False
)
f3x_summary.qualified_committee = (
True if f3x_summary.qualified_committee in ["true", "X"] else False
)
f3x_summary.save()


class Migration(migrations.Migration):

dependencies = [
('f3x_summaries', '0008_auto_20220503_1411'),
("f3x_summaries", "0008_auto_20220503_1411"),
]

operations = [
migrations.RunPython(convert_fecfile_booleans),
migrations.AlterField(
model_name='f3xsummary',
name='change_of_address',
model_name="f3xsummary",
name="change_of_address",
field=models.BooleanField(blank=True, default=False, null=True),
),
migrations.AlterField(
model_name='f3xsummary',
name='qualified_committee',
model_name="f3xsummary",
name="qualified_committee",
field=models.BooleanField(blank=True, default=False, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 3.2.12 on 2022-05-25 15:57

from django.db import migrations, models
import django.db.models.deletion
from django.core.management import call_command


def forwards_func(apps, schema_editor):
call_command(
"loaddata",
"fecfiler/f3x_summaries/fixtures/report_code_labels.json",
)


class Migration(migrations.Migration):

dependencies = [
("f3x_summaries", "0009_auto_20220515_2116"),
]

operations = [
migrations.CreateModel(
name="ReportCodeLabel",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("label", models.TextField(blank=True, null=True)),
("report_code", models.TextField(blank=True, null=True, unique=True)),
],
options={
"db_table": "report_code_labels",
},
),
migrations.AddIndex(
model_name="reportcodelabel",
index=models.Index(
fields=["report_code"], name="report_code_report__9cd13b_idx"
),
),
migrations.RunPython(forwards_func),
migrations.AlterField(
model_name="f3xsummary",
name="report_code",
field=models.ForeignKey(
blank=True,
db_column="report_code",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="f3x_summaries.reportcodelabel",
to_field="report_code",
),
),
]
21 changes: 20 additions & 1 deletion django-backend/fecfiler/f3x_summaries/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
from fecfiler.committee_accounts.models import CommitteeOwnedModel


class ReportCodeLabel(models.Model):
label = models.TextField(null=True, blank=True)
report_code = models.TextField(null=True, blank=True, unique=True)

def __str__(self):
return self.label

class Meta:
db_table = "report_code_labels"
indexes = [models.Index(fields=["report_code"])]


class F3XSummary(SoftDeleteModel, CommitteeOwnedModel):
"""Generated model from json schema"""

Expand All @@ -16,7 +28,14 @@ class F3XSummary(SoftDeleteModel, CommitteeOwnedModel):

state = models.TextField(null=True, blank=True)
zip = models.TextField(null=True, blank=True)
report_code = models.TextField(null=True, blank=True)
report_code = models.ForeignKey(
ReportCodeLabel,
models.SET_NULL,
null=True,
blank=True,
to_field="report_code",
db_column="report_code",
)
election_code = models.TextField(null=True, blank=True)
date_of_election = models.TextField(null=True, blank=True)
state_of_election = models.TextField(null=True, blank=True)
Expand Down
17 changes: 16 additions & 1 deletion django-backend/fecfiler/f3x_summaries/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .models import F3XSummary
from .models import F3XSummary, ReportCodeLabel
from rest_framework.serializers import ModelSerializer, SlugRelatedField
from fecfiler.committee_accounts.serializers import CommitteeOwnedSerializer
from fecfiler.validation import serializers
import logging
Expand All @@ -10,6 +11,13 @@ class F3XSummarySerializer(
CommitteeOwnedSerializer, serializers.FecSchemaValidatorSerializerMixin
):
schema_name = "F3X"
report_code = SlugRelatedField(
many=False,
required=False,
read_only=False,
slug_field="report_code",
queryset=ReportCodeLabel.objects.all(),
)

class Meta:
model = F3XSummary
Expand All @@ -20,3 +28,10 @@ class Meta:
"created",
"updated",
]
foreign_key_fields = {"report_code": "report_code"}


class ReportCodeLabelSerializer(ModelSerializer):
class Meta:
model = ReportCodeLabel
fields = ("label", "report_code")
6 changes: 5 additions & 1 deletion django-backend/fecfiler/f3x_summaries/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import F3XSummaryViewSet
from .views import F3XSummaryViewSet, ReportCodeLabelViewSet

# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r"f3x-summaries", F3XSummaryViewSet, basename="f3x-summaries")
router.register(
r"report-code-labels",
ReportCodeLabelViewSet,
basename="report-code-labels")

# The API URLs are now determined automatically by the router.
urlpatterns = [
Expand Down
Loading

0 comments on commit 588c33a

Please sign in to comment.