Exemplo n.º 1
0
def _make_response_data_model(
    name: str, fields: Dict[str, Raw], skip_none: Optional[bool] = False
) -> Tuple[Model, Model]:
    model = Model(f"{name}Data", fields)
    return model, Model(
        f"{name}Response", {"message": String(), "data": Nested(model, skip_none=skip_none)}
    )
Exemplo n.º 2
0
from models import db_category_data
from models.common import _make_response_data_model
from models.requests.recipes import (
    _db_recipe,
    _db_recipe_response_model as db_recipe_response_model,
    db_recipe_data,
    recipe_model,
)

recipe_update_response_data, recipe_update_response_model = _make_response_data_model(
    "UpdateRecipe",
    {
        "existingCategories": List(Integer),
        "newCategories": List(Nested(db_category_data, skip_none=True)),
        "categoryFailedAdds": List(String),
        "imgSrc": String(),
    },
    skip_none=True,
)

recipe_add_response_data, recipe_add_response_model = _make_response_data_model(
    "AddRecipe",
    {
        **_db_recipe,
        "existingCategories": List(Integer),
        "newCategories": List(Nested(db_category_data, skip_none=True)),
        "categoryFailedAdds": List(String),
    },
    skip_none=True,
)
Exemplo n.º 3
0
from flask_restx.fields import String
from . import task_api

ConvertDocsModel = task_api.model(
    'ConvertDocsModel', {
        'task_status_key':
        String(description=
               'ConversionTaskStatus key for the new doc to be converted', )
    })
Exemplo n.º 4
0
from flask_restx import Model
from flask_restx.fields import String

_email = {"email": String(required=True)}
_password = {"password": String(required=True)}
_confirmation_code = {"confirmationCode": String(required=True)}
_refresh_token = {"refreshToken": String(required=True)}

sign_up_model = Model("SignUp", {**_email, **_password})

confirm_sign_up_model = Model("ConfirmSignUp", _confirmation_code)

sign_in_model = sign_up_model.clone("SignIn")

refresh_id_token_model = Model("RefreshIdToken", _refresh_token)

resend_code_model = Model("ResendCode", _email)

forgot_password_model = Model("ForgotPassword", _email)

confirm_forgot_password_model = Model("ConfirmForgotPassword", {
    **_email,
    **_password,
    **_confirmation_code
})
Exemplo n.º 5
0
    category_update_model,
    category_with_id_model,
    db_category_data,
)
from models.requests.recipes import (
    batch_recipe_add_model,
    batch_recipe_delete_model,
    batch_recipe_update_model,
    db_recipe_data,
    recipe_model,
    recipe_update_model,
    recipe_with_id_model,
)
from models.requests.users import shopping_list_data

invalid_input_model = Model("InvalidInput", {"message": String()})
not_found_model = Model("NotFound", {"message": String()})


def register_recipe_request_models(api: Namespace) -> None:
    for model in (
            batch_recipe_add_model,
            batch_recipe_delete_model,
            batch_recipe_update_model,
            db_recipe_data,
            invalid_input_model,
            not_found_model,
            recipe_model,
            recipe_update_model,
            recipe_with_id_model,
    ):
Exemplo n.º 6
0
auth_reqparser.add_argument(name="password",
                            type=str,
                            location="form",
                            required=True,
                            nullable=False)
"""
"User" is the name of the API Model, and this value will be used to identify
the JSON object in the Swagger UI page. Please read the Flask-RESTx documentation
for detailed examples of creating API models. Basically, an API model is a
dictionary where the keys are the names of attributes on the object that
we need to serialize, and the values are a class from the fields module
that formats the value of the attibute on the object to ensure that
it can be safely included in the HTTP response.

Any other attributes of the object are considered private and will not be
included in the JSON. If the name of the attribute on the object is different
than the name that you wish to use in the JSON, specify the name of the attribute
on the object using the attribute parameter, which is what we are doing
for registered_on in the code above.
"""
user_model = Model(
    "User",
    {
        "email": String,
        "public_id": String,
        "admin": Boolean,
        "registered_on": String(attribute="registered_on_str"),
        "token_expires_in": String,
    },
)
Exemplo n.º 7
0
blueprint = Blueprint('apiv2', __name__, url_prefix='/api/v2')

api = Api(
    blueprint,
    version='2.0',
    title=settings.api.title,
    description=settings.api.description,
)

ns = api.namespace('mawaqit', description='Provides Mawaqit')

mawaqit = api.model('Mawaqit', {
    settings.column_names_en.date: Date(),
    settings.column_names_en.wilaya: Nested(api.model('Wilaya', {
        'code': String(),
        'arabic_name': String(),
        'english_name': String(),
    })),
    settings.salawat_en.fajr: Time(),
    settings.salawat_en.chorok: Time(),
    settings.salawat_en.dhohr: Time(),
    settings.salawat_en.asr: Time(),
    settings.salawat_en.maghrib: Time(),
    settings.salawat_en.icha: Time(),
})

# TODO: add validation to say: day and (from and to) are mutually execlusive
"""
Time filtering: 
* If no time filter is speified, mawaqait of the current date will be returned
Exemplo n.º 8
0
from flask_restx.fields import DateTime, Integer, List, String

from models.common import _make_response_data_model

_shopping_list = {
    "shoppingList": List(String),
}

_user = {
    **_shopping_list,
    "userId": String(required=True),
    "nextCategoryId": Integer(),
    "nextRecipeId": Integer(),
    "signUpTime": DateTime(),
}

shopping_list_data, _shopping_list_response_model = _make_response_data_model(
    "ShoppingList", _shopping_list)
Exemplo n.º 9
0
from flask_restx import Model
from flask_restx.fields import DateTime, Integer, List, Nested, String

from models.common import _make_response_data_model

_recipe_id = Integer(required=True)
_name = String(min_length=1, max_length=200, required=True)
_desc = String(max_length=200)
_cook_time = String()
_ingredients = List(String)
_instructions = List(String)
_create_time = DateTime(required=True)
_update_time = DateTime(required=True)
_adapted_from = String()
_url = String()
_imgSrc = String()

# Editable recipe fields
_recipe = {
    "name": _name,
    "desc": _desc,
    "cookTime": _cook_time,
    "ingredients": _ingredients,
    "instructions": _instructions,
    "categories": List(String),
    "adaptedFrom": _adapted_from,
    "url": _url,
    "imgSrc": _imgSrc,
}
recipe_model = Model("Recipe", _recipe)
Exemplo n.º 10
0
from flask_restx.fields import List, String

from models.common import _make_response_data_model

scrape_response_data, scrape_response_model = _make_response_data_model(
    "Scrape",
    {
        "url": String(required=True),
        "name": String(),
        "imgSrc": String(),
        "adaptedFrom": String(),
        "yield": String(),
        "cookTime": String(),
        "instructions": List(String),
        "ingredients": List(String),
    },
    skip_none=True,
)
Exemplo n.º 11
0
                                  type=positive,
                                  required=False,
                                  choices=[5, 10, 25, 50, 100],
                                  default=10)

widget_owner_model = Model("Widget Owner", {
    "email": String,
    "public_id": String
})

widget_model = Model(
    "Widget",
    {
        "name": String,
        "info_url": String,
        "created_at": String(attribute="created_at_str"),
        "created_at_iso8601": DateTime(attribute="created_at"),
        "created_at_rfc822": DateTime(attribute="created_at",
                                      dt_format="rfc822"),
        "deadline": String(attribute="deadline_str"),
        "deadline_passed": Boolean,
        "time_remaining": String(attribute="time_remaining_str"),
        "owner": Nested(widget_owner_model),
        "link": Url("api.widget"),
    },
)

pagination_links_model = Model(
    "Nav Links",
    {
        "self": String,
Exemplo n.º 12
0
from flask_restx import Model
from flask_restx.fields import String, List, Nested

person = Model(
    'Person Model', {
        'id': String(),
        'name': String(),
        'gender': String(),
        'eye_color': String(),
        'hair_color': String(),
        'age': String(),
    })

film_model = Model(
    'Film Model', {
        'id': String(),
        'title': String(),
        'description': String(),
        'director': String(),
        'producer': String(),
        'release_date': String(),
        'rt_score': String(),
        'people': List(Nested(person)),
    })
Exemplo n.º 13
0
from datasearchtool.webapp.api.namespaces.input_sources import (
    InputSourceResource,
    DOC_NAME,
    DATA_SOURCE_TYPE_ENUM,
    DATA_SOURCE_TYPE_FIELD_NAME,
    DATA_SOURCE_NAME_FIELD_NAME,
)

BaseInputSourceModel = build_doc_type_spec(DatabaseTableInputSourceField)

InputSourceModel = Model.clone(
    "DatabaseTableInputSourceModel",
    BaseInputSourceModel,
    {
        DATA_SOURCE_TYPE_FIELD_NAME:
        String(enum=DATA_SOURCE_TYPE_ENUM, required=True),
        DATA_SOURCE_NAME_FIELD_NAME:
        String(required=True),
    },
)

CompleteInputSourceModel = Model.clone(
    "DatabaseTableCompleteInputSourceModel",
    InputSourceModel,
    {
        DOC_NAME: String(),
    },
)

InputSourceEditionModel = Model(
    "DatabaseTableInputSourceEditionModel",
Exemplo n.º 14
0
blueprint = Blueprint('apiv1', __name__, url_prefix='/api/v1')

api = Api(
    blueprint,
    version='1.0',
    title=settings.api.title,
    description=settings.api.description,
)

ns = api.namespace('mawaqit', description='Provides Mawaqit')

mawaqit = api.model(
    'Mawaqit', {
        settings.column_names.date: Date(),
        settings.column_names.wilaya: String(),
        settings.salawat.fajr: Time(),
        settings.salawat.chorok: Time(),
        settings.salawat.dhohr: Time(),
        settings.salawat.asr: Time(),
        settings.salawat.maghrib: Time(),
        settings.salawat.icha: Time(),
    })

mawaqit_en = api.model(
    'MawaqitEn', {
        settings.column_names_en.date: Date(),
        settings.column_names_en.wilaya: String(),
        settings.salawat_en.fajr: Time(),
        settings.salawat_en.chorok: Time(),
        settings.salawat_en.dhohr: Time(),
Exemplo n.º 15
0
from typing import Dict, Optional, Tuple

from flask_restx import Model
from flask_restx.fields import DateTime, Nested, Raw, String

_user_id = String(required=True)
_name = String(min_length=1, max_length=200, required=True)
_create_time = DateTime(required=True)
_update_time = DateTime(required=True)


def _make_response_data_model(
    name: str, fields: Dict[str, Raw], skip_none: Optional[bool] = False
) -> Tuple[Model, Model]:
    model = Model(f"{name}Data", fields)
    return model, Model(
        f"{name}Response", {"message": String(), "data": Nested(model, skip_none=skip_none)}
    )
Exemplo n.º 16
0
from flask_restx.fields import String
from . import public_api

GenerateUploadSessionModel = public_api.model(
    'UploadSessionModel', {
        'mimetype':
        String(description=
               'Mimetype of file whose session upload is about to begin')
    })

GenerateUploadSessionResponse = public_api.model(
    'SessionResponse', {
        'upload_url': String(description='Upload Session url'),
        'blob_name': String(description='Storage Object name')
    })

ConvertDocumentParser = public_api.parser()
ConvertDocumentParser.add_argument('pdf-name',
                                   default='Converted.pdf',
                                   help="PDF download name")
Exemplo n.º 17
0
from flask_restx.fields import Boolean, String

from models.common import _make_response_data_model

refresh_id_token_response_data, refresh_id_token_response_model = _make_response_data_model(
    "RefreshIdToken",
    {"idToken": String(), "user": String(), "refreshTokenExpired": Boolean()},
    skip_none=True,
)

sign_in_token_response_data, sign_in_token_response_model = _make_response_data_model(
    "SignIn", {"idToken": String(), "user": String(), "refreshToken": String()}, skip_none=True
)
Exemplo n.º 18
0
    "email": String,
    "public_id": String
})

widget_model = Model(
    "Widget",
    {
        "name": String,
        "info_url": String,
        # "created_at_iso8601": "2019-09-20T04:47:50",
        "created_at_iso8601": DateTime(attribute="created_at"),
        # "created_at_rfc822": "Fri, 20 Sep 2019 04:47:50 -0000",
        "created_at_rfc822": DateTime(attribute="created_at",
                                      dt_format="rfc822"),
        # "deadline": "09/20/19 10:59:59 PM UTC-08:00",
        "deadline": String(attribute="deadline_str"),
        "deadline_passed": Boolean,
        # "time_remaining": "16 hours 41 minutes 42 seconds",
        "time_remaining": String(attribute="time_remaining_str"),
        # "owner": {
        #    "email": "*****@*****.**",
        #    "public_id": "475807a4-8497-4c5c-8d70-109b429bb4ef",
        # }
        "owner": Nested(widget_owner_model),
        # "link": "/api/v1/widgets/first_widget",
        "link": Url("api.widget"),
    },
)

pagination_links_model = Model(
    "Nav Links",
Exemplo n.º 19
0
    batch_recipe_get_response_model,
    batch_recipe_update_response_data,
    batch_recipe_update_response_model,
    db_recipe_response_model,
    recipe_add_response_data,
    recipe_add_response_model,
    recipe_delete_response_data,
    recipe_delete_response_model,
    recipe_update_response_data,
    recipe_update_response_model,
)
from models.responses.scrape import scrape_response_data, scrape_response_model
from models.responses.users import shopping_list_response_model

default_response_model = Model("DefaultResponse", {
    "message": String(),
    "data": Wildcard(String)
})


def register_recipe_response_models(api: Namespace) -> None:
    for model in (
            batch_recipe_add_response_data,
            batch_recipe_add_response_model,
            batch_recipe_delete_response_data,
            batch_recipe_delete_response_model,
            batch_recipe_get_response_data,
            batch_recipe_get_response_model,
            batch_recipe_update_response_data,
            batch_recipe_update_response_model,
            db_recipe_response_model,