Skip to content

Commit

Permalink
Merge pull request #326 from fecgov/release/sprint-19
Browse files Browse the repository at this point in the history
Release/sprint 19
  • Loading branch information
toddlees authored Jan 30, 2023
2 parents ceb9663 + 8131759 commit fe8594a
Show file tree
Hide file tree
Showing 60 changed files with 1,795 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def create_uuid(apps, schema_editor):
committee_account.save()


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -27,7 +23,7 @@ class Migration(migrations.Migration):
name="uuid",
field=models.UUIDField(default=uuid.uuid4, editable=False),
),
migrations.RunPython(create_uuid, noop),
migrations.RunPython(create_uuid, migrations.RunPython.noop),
migrations.AlterField(
model_name="committeeaccount",
name="uuid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def create_uuid(apps, schema_editor):
contact.save()


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -27,7 +23,7 @@ class Migration(migrations.Migration):
name="uuid",
field=models.UUIDField(default=uuid.uuid4, editable=False, null=True),
),
migrations.RunPython(create_uuid, noop),
migrations.RunPython(create_uuid, migrations.RunPython.noop),
migrations.AlterField(
model_name="contact",
name="uuid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def update_uuid(apps, schema_editor):
Contact.objects.update(committee_account=models.Subquery(committee_uuid))


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -38,7 +34,7 @@ class Migration(migrations.Migration):
to="committee_accounts.CommitteeAccount",
),
),
migrations.RunPython(update_uuid, noop),
migrations.RunPython(update_uuid, migrations.RunPython.noop),
migrations.RemoveField(
model_name="contact",
name="committee_account_old",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.1.3 on 2023-01-03 21:51

from django.db import migrations, models
import uuid


class Migration(migrations.Migration):

dependencies = [
("contacts", "0010_auto_20220915_1309"),
]

operations = [
migrations.AlterField(
model_name="contact",
name="id",
field=models.UUIDField(
default=uuid.uuid4, editable=False, primary_key=True, serialize=False
),
),
]
49 changes: 46 additions & 3 deletions django-backend/fecfiler/contacts/serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import logging

from django.db import transaction
from fecfiler.committee_accounts.serializers import CommitteeOwnedSerializer
from fecfiler.validation import serializers
from rest_framework.serializers import IntegerField
from rest_framework.serializers import (
IntegerField,
UUIDField,
ModelSerializer,
)
from rest_framework.exceptions import ValidationError

from .models import Contact

Expand All @@ -13,7 +19,10 @@ class ContactSerializer(
serializers.FecSchemaValidatorSerializerMixin, CommitteeOwnedSerializer
):
contact_value = dict(
COM="Committee", IND="Individual", ORG="Organization", CAN="Candidate",
COM="Committee",
IND="Individual",
ORG="Organization",
CAN="Candidate",
)

# Contains the number of transactions linked to the contact
Expand All @@ -27,7 +36,13 @@ class Meta:
fields = [
f.name
for f in Contact._meta.get_fields()
if f.name not in ["deleted", "schatransaction"]
if f.name
not in [
"deleted",
"schatransaction",
"scheduleatransaction",
"schedulebtransaction",
]
]
fields.append("transaction_count")
read_only_fields = [
Expand All @@ -44,3 +59,31 @@ def to_internal_value(self, data):
if "transaction_count" in data:
del data["transaction_count"]
return super().to_internal_value(data)


class LinkedContactSerializerMixin(ModelSerializer):
contact = ContactSerializer(allow_null=True, required=False)
contact_id = UUIDField(required=False, allow_null=False)

def create(self, validated_data: dict):
with transaction.atomic():
self.create_or_update_contact(validated_data)
return super().create(validated_data)

def update(self, instance, validated_data: dict):
with transaction.atomic():
self.create_or_update_contact(validated_data)
return super().update(instance, validated_data)

def create_or_update_contact(self, validated_data: dict):
contact_data = validated_data.pop("contact", None)
contact_id = validated_data.get("contact_id", None)
if not contact_id:
if not contact_data:
raise ValidationError(
{"contact_id": ["No contact or contact id provided"]}
)
contact: Contact = Contact.objects.create(**contact_data)
validated_data["contact_id"] = contact.id
else:
Contact.objects.filter(id=contact_id).update(**contact_data)
2 changes: 1 addition & 1 deletion django-backend/fecfiler/contacts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ContactViewSet(CommitteeOwnedViewSet):
in CommitteeOwnedViewSet's implementation of get_queryset()
"""
queryset = (
Contact.objects.annotate(transaction_count=Count("schatransaction"))
Contact.objects.annotate(transaction_count=Count("scheduleatransaction"))
.all()
.order_by("-created")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"comment": "SA15 transaction to count",
"model": "scha_transactions.schatransaction",
"model": "transactions.scheduleatransaction",
"fields": {
"id": "474a1a10-da68-4d71-9a11-9509df48e1aa",
"committee_account_id": "735db943-9446-462a-9be0-c820baadb622",
Expand All @@ -16,7 +16,7 @@
},
{
"comment": "SA15 transaction to count",
"model": "scha_transactions.schatransaction",
"model": "transactions.scheduleatransaction",
"fields": {
"id": "0da3bad2-54ec-4a90-a37c-13ce4ec4e253",
"committee_account_id": "735db943-9446-462a-9be0-c820baadb622",
Expand All @@ -31,7 +31,7 @@
},
{
"comment": "SA15 transaction to NOT count",
"model": "scha_transactions.schatransaction",
"model": "transactions.scheduleatransaction",
"fields": {
"id": "7e5df0bc-fe32-4639-8426-b31bd23c3de7",
"committee_account_id": "735db943-9446-462a-9be0-c820baadb622",
Expand All @@ -46,7 +46,7 @@
},
{
"comment": "SA11AI transaction to NOT count with SA15",
"model": "scha_transactions.schatransaction",
"model": "transactions.scheduleatransaction",
"fields": {
"id": "f431efe8-9b5f-4539-b7e5-5ae3c32b4e28",
"committee_account_id": "735db943-9446-462a-9be0-c820baadb622",
Expand All @@ -59,4 +59,4 @@
"transaction_type_identifier": "INDIVIDUAL_RECEIPT"
}
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def create_uuid(apps, schema_editor):
f3xsummary.save()


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -27,7 +23,7 @@ class Migration(migrations.Migration):
name="uuid",
field=models.UUIDField(default=uuid.uuid4, editable=False),
),
migrations.RunPython(create_uuid, noop),
migrations.RunPython(create_uuid, migrations.RunPython.noop),
migrations.AlterField(
model_name="f3xsummary",
name="uuid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ def update_uuid(apps, schema_editor):
)


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -49,7 +45,7 @@ class Migration(migrations.Migration):
to="web_services.WebPrintSubmission",
),
),
migrations.RunPython(update_uuid, noop),
migrations.RunPython(update_uuid, migrations.RunPython.noop),
migrations.RemoveField(
model_name="f3xsummary",
name="upload_submission_old",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def update_uuid(apps, schema_editor):
F3XSummary.objects.update(committee_account=models.Subquery(committee_uuid))


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -38,7 +34,7 @@ class Migration(migrations.Migration):
to="committee_accounts.CommitteeAccount",
),
),
migrations.RunPython(update_uuid, noop),
migrations.RunPython(update_uuid, migrations.RunPython.noop),
migrations.RemoveField(
model_name="f3xsummary",
name="committee_account_old",
Expand Down
2 changes: 2 additions & 0 deletions django-backend/fecfiler/f3x_summaries/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class Meta:
not in [
"deleted",
"schatransaction",
"scheduleatransaction",
"schedulebtransaction",
"dotfec",
"memotext",
"uploadsubmission",
Expand Down
4 changes: 2 additions & 2 deletions django-backend/fecfiler/f3x_summaries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fecfiler.committee_accounts.views import CommitteeOwnedViewSet
from .models import F3XSummary
from .report_codes.views import report_code_label_mapping
from fecfiler.scha_transactions.models import SchATransaction
from fecfiler.transactions.schedule_a.models import ScheduleATransaction
from fecfiler.web_services.models import FECSubmissionState, FECStatus
from fecfiler.memo_text.models import MemoText
from fecfiler.web_services.models import DotFEC, UploadSubmission, WebPrintSubmission
Expand Down Expand Up @@ -90,7 +90,7 @@ def hard_delete_reports(self, request):
committee_account__committee_id=committee_id
)
report_count = reports.count()
transaction_count = SchATransaction.objects.filter(
transaction_count = ScheduleATransaction.objects.filter(
report__committee_account__committee_id=committee_id
).count()
memo_count = MemoText.objects.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def create_uuid(apps, schema_editor):
memo_text.save()


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -27,7 +23,7 @@ class Migration(migrations.Migration):
name="uuid",
field=models.UUIDField(default=uuid.uuid4, editable=False),
),
migrations.RunPython(create_uuid, noop),
migrations.RunPython(create_uuid, migrations.RunPython.noop),
migrations.AlterField(
model_name="memotext",
name="uuid",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ def update_uuid(apps, schema_editor):
MemoText.objects.update(committee_account=models.Subquery(committee_uuid))


def noop():
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -38,7 +34,7 @@ class Migration(migrations.Migration):
to="committee_accounts.CommitteeAccount",
),
),
migrations.RunPython(update_uuid, noop),
migrations.RunPython(update_uuid, migrations.RunPython.noop),
migrations.RemoveField(
model_name="memotext",
name="committee_account_old",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ def set_is_report_level_memo(apps, _):
memo.save()


def noop(_apps, _):
# Empty function for reversing the migration
pass


class Migration(migrations.Migration):

dependencies = [
Expand All @@ -27,5 +22,5 @@ class Migration(migrations.Migration):
name="is_report_level_memo",
field=models.BooleanField(default=True),
),
migrations.RunPython(set_is_report_level_memo, noop),
migrations.RunPython(set_is_report_level_memo, migrations.RunPython.noop),
]
Loading

0 comments on commit fe8594a

Please sign in to comment.