Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted memo_code to boolean and added schema query param #121

Merged
merged 5 commits into from
May 18, 2022
Merged
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
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-05-16 11:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('scha_transactions', '0007_alter_schatransaction_committee_account'),
]

operations = [
migrations.AlterField(
model_name='schatransaction',
name='memo_code',
field=models.BooleanField(blank=True, default=False, null=True),
),
]
2 changes: 1 addition & 1 deletion django-backend/fecfiler/scha_transactions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class SchATransaction(SoftDeleteModel, CommitteeOwnedModel):
conduit_city = models.TextField(null=True, blank=True)
conduit_state = models.TextField(null=True, blank=True)
conduit_zip = models.TextField(null=True, blank=True)
memo_code = models.TextField(null=True, blank=True)
memo_code = models.BooleanField(null=True, blank=True, default=False)
memo_text_description = models.TextField(null=True, blank=True)
reference_to_si_or_sl_system_code_that_identifies_the_account = models.TextField(
null=True, blank=True
Expand Down
5 changes: 3 additions & 2 deletions django-backend/fecfiler/scha_transactions/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import SchATransaction
from .views import SchATransactionViewSet

# Create a router and register our viewsets with it.
router = DefaultRouter()
router.register(r"sch-a-transactions", SchATransaction, basename="sch-a-transactions")
router.register(r"sch-a-transactions", SchATransactionViewSet,
basename="sch-a-transactions")

# The API URLs are now determined automatically by the router.
urlpatterns = [
Expand Down
6 changes: 4 additions & 2 deletions django-backend/fecfiler/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from .authentication.authenticate_login import LogoutView

BASE_V1_URL = r"^api/v1/"

urlpatterns = [
url(r"^api-auth/", include("rest_framework.urls", namespace="rest_framework")),
Expand All @@ -15,8 +16,9 @@
template_name="swagger-ui.html", url_name="schema"
),
),
url(r"^api/v1/", include("fecfiler.contacts.urls")),
url(r"^api/v1/", include("fecfiler.f3x_summaries.urls")),
url(BASE_V1_URL, include("fecfiler.contacts.urls")),
url(BASE_V1_URL, include("fecfiler.f3x_summaries.urls")),
url(BASE_V1_URL, include("fecfiler.scha_transactions.urls")),
url(r"^api/v1/auth/logout/$", LogoutView.as_view(), name="logout"),
url(r"^api/v1/token/obtain$", obtain_jwt_token),
url(r"^api/v1/token/refresh$", refresh_jwt_token),
Expand Down
8 changes: 6 additions & 2 deletions django-backend/fecfiler/validation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class FecSchemaValidatorSerializerMixin(serializers.Serializer):
def get_schema_name(self, data):
"""Gets the schema name to retrieve the correct schema from fecfile_validate

You need to either define `schema_name` or overide this function to provide the
`validate` function with a schema
You need to either define `schema_name`, set the query parameter 'schema',
or overide this function to provide the `validate` function with a schema

Args:
data: data being serialized. May contain information needed to determine
Expand All @@ -38,6 +38,10 @@ def get_schema_name(self, data):
:py:function:`fecfile_validate.validate` that will
match a schema defined in the package
"""
request = self.context.get("request", None)
if request and request.query_params.get("schema"):
self.schema_name = request.query_params.get("schema")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this got me wondering if setting the schema name would impact subsequent requests. basically is a single serializer instance used in drf for each request. I ran a little test printing schema_name before and after we set it. It does not persist across requests.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so no change required


assert self.schema_name is not None, (
f"'{self.__class__.__name__}' should either include a "
"`schema_name` attribute, or override the `get_schema_name()` method."
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ django-cors-headers==3.11.0
djangorestframework==3.13.1
djangorestframework-jwt==1.11.0
drf-spectacular==0.21.2
git+https://github.com/fecgov/fecfile-validate@e692949fc4d116a852e7d0fe4d7563d94518e234#egg=fecfile_validate&subdirectory=fecfile_validate_python
git+https://github.com/fecgov/fecfile-validate@18458b40ecb1369e8e0d2d0b7102c8b085b3c772#egg=fecfile_validate&subdirectory=fecfile_validate_python
GitPython==3.1.27
gunicorn==19.10.0
Jinja2==2.11.3
Expand Down