-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: create custom_form_options api #6408
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,46 @@ | ||
| from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | ||
| from app.models import db | ||
| from app.api.schema.custom_form_options import CustomFormOptionSchema | ||
| from app.models.custom_form_option import CustomFormOptions | ||
|
|
||
|
|
||
| class CustomFormOptionList(ResourceList): | ||
| """ | ||
| Create and List Custom Form Options | ||
| """ | ||
|
|
||
| def query(self, view_kwargs): | ||
| query_ = self.session.query(CustomFormOptions) | ||
| if view_kwargs.get('custom_form_id'): | ||
| query_ = self.session.query(CustomFormOptions).filter( | ||
| getattr(CustomFormOptions, 'custom_form_id') == view_kwargs['custom_form_id']) | ||
| return query_ | ||
|
|
||
| schema = CustomFormOptionSchema | ||
| data_layer = {'session': db.session, | ||
| 'model': CustomFormOptions, | ||
| 'methods': { | ||
| 'query': query | ||
| }} | ||
|
|
||
|
|
||
| class CustomFormOptionDetail(ResourceDetail): | ||
| """ | ||
| CustomForm Resource | ||
| """ | ||
|
|
||
| schema = CustomFormOptionSchema | ||
| data_layer = {'session': db.session, | ||
| 'model': CustomFormOptions | ||
| } | ||
|
|
||
|
|
||
| class CustomFormOptionRelationship(ResourceRelationship): | ||
| """ | ||
| CustomForm Resource | ||
| """ | ||
|
|
||
| schema = CustomFormOptionSchema | ||
| data_layer = {'session': db.session, | ||
| 'model': CustomFormOptions | ||
| } |
This file contains hidden or 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,32 @@ | ||
| from marshmallow_jsonapi import fields | ||
| from marshmallow_jsonapi.flask import Relationship | ||
|
|
||
| from app.api.helpers.utilities import dasherize | ||
| from app.api.schema.base import SoftDeletionSchema | ||
| from utils.common import use_defaults | ||
|
|
||
|
|
||
| @use_defaults() | ||
| class CustomFormOptionSchema(SoftDeletionSchema): | ||
| """ | ||
| API Schema for Custom Forms database model | ||
| """ | ||
|
|
||
| class Meta: | ||
| """ | ||
| Meta class for CustomForm Schema | ||
| """ | ||
| type_ = 'custom-form-option' | ||
| self_view = 'v1.custom_form_option_detail' | ||
| self_view_kwargs = {'id': '<id>'} | ||
| inflect = dasherize | ||
|
|
||
| id = fields.Integer(dump_only=True) | ||
| value = fields.Str(required=True) | ||
| custom_form = Relationship(attribute='custom_form', | ||
| self_view='v1.custom_form_option_form', | ||
| self_view_kwargs={'id': '<id>'}, | ||
| related_view='v1.custom_form_detail', | ||
| related_view_kwargs={'custom_form_option_id': '<id>'}, | ||
| schema='CustomFormSchema', | ||
| type_='custom_form') |
This file contains hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| from app.models import db | ||
| from app.models.base import SoftDeletionModel | ||
|
|
||
|
|
||
| class CustomFormOptions(SoftDeletionModel): | ||
| __tablename__ = 'custom_form_options' | ||
| id = db.Column(db.Integer, primary_key=True) | ||
| value = db.Column(db.String, nullable=False) | ||
| custom_form_id = db.Column(db.Integer, db.ForeignKey('custom_forms.id', ondelete='CASCADE')) | ||
|
|
||
| def __init__(self, | ||
| custom_form_id=None, | ||
| deleted_at=None, | ||
| value=None): | ||
| self.custom_form_id = custom_form_id | ||
| self.value = value | ||
| self.deleted_at = deleted_at | ||
|
|
||
| def __repr__(self): | ||
| return '<CustomFormOption %r>' % self.id | ||
|
|
||
| def __str__(self): | ||
| return self.__repr__() |
38 changes: 38 additions & 0 deletions
38
migrations/versions/rev-2019-08-24-20:32:00-ebfe89366d48_.py
This file contains hidden or 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,38 @@ | ||
| """empty message | ||
|
|
||
| Revision ID: ebfe89366d48 | ||
| Revises: 90d62fe3b5e3 | ||
| Create Date: 2019-08-24 20:32:00.535676 | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'ebfe89366d48' | ||
| down_revision = '90d62fe3b5e3' | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('custom_form_options', | ||
| sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True), | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('value', sa.String(), nullable=False), | ||
| sa.Column('custom_form_id', sa.Integer(), nullable=True), | ||
| sa.ForeignKeyConstraint(['custom_form_id'], ['custom_forms.id'], ondelete='CASCADE'), | ||
| sa.PrimaryKeyConstraint('id') | ||
| ) | ||
| op.add_column('custom_forms', sa.Column('description', sa.String(), nullable=True)) | ||
| op.add_column('custom_forms', sa.Column('is_complex', sa.Boolean(), nullable=False, server_default='False')) | ||
|
|
||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_column('custom_forms', 'is_complex') | ||
| op.drop_column('custom_forms', 'description') | ||
| op.drop_table('custom_form_options') | ||
| # ### end Alembic commands ### |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.