def test_inherit(self):
        api = Namespace('test')
        parent = api.model('Parent', {})
        api.inherit('Child', parent, {})

        self.assertIn('Parent', api.models)
        self.assertIn('Child', api.models)
示例#2
0
    def test_inherit(self):
        api = Namespace('test')
        parent = api.model('Parent', {})
        api.inherit('Child', parent, {})

        self.assertIn('Parent', api.models)
        self.assertIn('Child', api.models)
示例#3
0
    def test_inherit(self):
        api = Namespace('test')
        parent = api.model('Parent', {})
        api.inherit('Child', parent, {})

        assert 'Parent' in api.models
        assert 'Child' in api.models
示例#4
0
    def test_inherit(self):
        api = Namespace('test')
        parent = api.model('Parent', {})
        api.inherit('Child', parent, {})

        assert 'Parent' in api.models
        assert 'Child' in api.models
    def test_inherit_from_multiple_parents(self):
        api = Namespace('test')
        grand_parent = api.model('GrandParent', {})
        parent = api.model('Parent', {})
        api.inherit('Child', grand_parent, parent, {})

        assert 'GrandParent' in api.models
        assert 'Parent' in api.models
        assert 'Child' in api.models
    def test_inherit_from_multiple_parents(self):
        api = Namespace('test')
        grand_parent = api.model('GrandParent', {})
        parent = api.model('Parent', {})
        api.inherit('Child', grand_parent, parent, {})

        assert 'GrandParent' in api.models
        assert 'Parent' in api.models
        assert 'Child' in api.models
    def test_inherit(self):
        authorizations = {
            'apikey': {
                'type': 'apiKey',
                'in': 'header',
                'name': 'X-API-KEY'
            }
        }
        api = Namespace('test', authorizations=authorizations)
        parent = api.model('Parent', {})
        api.inherit('Child', parent, {})

        assert 'Parent' in api.models
        assert 'Child' in api.models
        assert api.authorizations == authorizations
    def test_inherit(self):
        authorizations = {
            'apikey': {
                'type': 'apiKey',
                'in': 'header',
                'name': 'X-API-KEY'
            }
        }
        api = Namespace('test', authorizations=authorizations)
        parent = api.model('Parent', {})
        api.inherit('Child', parent, {})

        assert 'Parent' in api.models
        assert 'Child' in api.models
        assert api.authorizations == authorizations
示例#9
0
        "state":
        fields.String(required=True,
                      description="Game status",
                      enum=list(CellState.__members__.keys())),
        "bombs_around":
        fields.Integer(description="Number of bombs around a pressed cell")
    })

_game = ns.inherit(
    "Game", _game_status, {
        "rows":
        fields.Integer(required=True, description="Number of rows"),
        "columns":
        fields.Integer(required=True, description="Number of columns"),
        "mines":
        fields.Integer(required=True, description="Number of bombs"),
        "started_at":
        fields.DateTime(required=True, description="When the game started"),
        "finished_at":
        fields.DateTime(required=False, description="When the game finished"),
        "grid":
        fields.List(fields.Nested(_cell))
    })


@ns.route("/")
class GameList(Resource):
    @ns.doc("List of games with its current status")
    @ns.marshal_list_with(_game_status, envelope="data")
    def get(self):
        return GameDb.list_all()
                      '/<int:project_id>/' + NSFS,
                      description="Project VNF Resources")
vendor_name_version_path = "/<string:vendor>/<string:name>/<string:version>"

funct = namespace.model(
    "VNF", {
        'name': fields.String(required=True, description='The VNF Name'),
        'vendor': fields.String(required=True, description='The VNF Vendor'),
        'version': fields.String(required=True, description='The VNF Version')
    })

funct_response = namespace.inherit(
    "Response", funct, {
        "descriptor":
        fields.Nested(model=funct, description="The Complete VNF Descriptor"),
        "id":
        fields.Integer(description='The Project ID'),
        "project_id":
        fields.Integer(description='The parent project id'),
    })


@namespace.route('/' + SERVICES + vendor_name_version_path)
@namespace.param('ws_id', 'The Workspace identifier')
@namespace.param('project_id', 'The Project identifier')
@namespace.param('vendor', 'The Network Service vendor')
@namespace.param('name', 'The Network Service name')
@namespace.param('version', 'The Network Service version')
class Lookup(Resource):
    @namespace.response(200, "OK", [funct_response])
    def get(self, ws_id, project_id, vendor, name, version):
        fields.String(
            require=True,
            example='2020-12-15T16:20:34.426644+00:00',
            description='ISO Datetime from when should the schedule be active.'
        ),
        'to':
        fields.String(
            require=True,
            example='2020-12-15T16:22:34.426644+00:00',
            description='ISO Datetime to when should the schedule be active.'),
    })

heating_schedule_create_model = heating_schedule_namespace.inherit(
    'HeatingScheduleCreate', heating_schedule_search_model, {
        'temperature':
        fields.Integer(
            require=True,
            example=21,
            description='Current temperature in the room. Temperature in °C.'),
    })

heating_schedule_update_model = heating_schedule_namespace.inherit(
    'HeatingScheduleUpdate', heating_schedule_create_model, {
        'id': fields.String(require=True, example='KLJLK43268'),
    })

heating_schedule_model = heating_schedule_namespace.inherit(
    'HeatingSchedule', heating_schedule_update_model, {
        'setBy':
        fields.String(require=True,
                      example='1234567890',
                      description='User ID of who set the schedule.'),
示例#12
0
文件: users.py 项目: adyouri/lafza
from project.core import user_utils, limit_access

api = Namespace('users')

user_schema = UserSchema(dump_only=('date_created', 'translations', 'terms',
                                    'roles'))

# Flask-Restplus models for documentation
login_model = api.model(
    'Login', {
        'username': fields.String(required=True, min_length=3, max_length=25),
        'password': fields.String(required=True, min_length=8),
    })

register_model = api.inherit(
    'Register', login_model,
    {'email': fields.String(example='*****@*****.**')})


@api.route('/register/', endpoint='register')
class RegisterAPI(Resource):
    # rate_limit = current_app.config.get('REGISTER_LIMIT', '5 per day')
    decorators = [limit_access.limiter.limit('5 per day')]

    @api.expect(register_model)
    def post(self):
        """ Register a new user """
        api_payload = request.get_json()
        username = api_payload['username']
        email = api_payload['email']
        user_is_not_unique = None
示例#13
0
    'Clue_Group_Request', {
        'name':
        fields.String(required=True, description="The name of the clue group"),
        'created_by':
        fields.String(
            required=True,
            description="The id of the user created this clue group"),
        'assigned_to':
        fields.String(
            required=True,
            description="The id of the user this clue group was assigned to"),
    })

clue_gourp_response_model = api.inherit(
    'Clue_Group_Response', clue_gourp_request_model, model_super_model, {
        'created': fields.Nested(user_response_model),
        'assigned': fields.Nested(user_response_model),
    })


@api.route('/')
class ClueGroupListResource(Resource):
    @api.doc('create_clue_group')
    @api.expect(clue_gourp_request_model)
    @api.marshal_with(clue_gourp_response_model)
    @jwt_required()
    def post(self):
        '''Create a new clue group'''
        args = request.get_json()
        return ClueGroupService.create(args)
namespace = Namespace(WORKSPACES, description="Workspace Resources")
logger = logging.getLogger(__name__)

rep = namespace.model("Repository", {
    'name': fields.String(required=True, description='The Repository Name'),
    'url': fields.Url(required=True, description='The Repository URL')
})

ws = namespace.model("Workspace", {
    'name': fields.String(required=True, description='The Workspace Name'),
    "catalogues": fields.List(fields.Nested(rep)),
    "platforms": fields.List(fields.Nested(rep))
})

ws_response = namespace.inherit("WorkspaceResponse", ws, {
    "path": fields.String(description='The Physical Workspace location'),
    "id": fields.Integer(description='The Workspace ID')
})

descriptor_content = namespace.model("Descriptor Content", {})

descriptor = namespace.model("Descriptor", {
    "id": fields.Integer(description="The descriptor id"),
    "descriptor": fields.Nested(descriptor_content)
})


@namespace.route('/')
class Workspaces(Resource):
    """Methods for the workspace resource directory"""

    @namespace.response(200, "OK", [ws_response])
示例#15
0
        if not school:
            api.abort(404, "School does not exist.")
        school.update(data)
        db.session.commit()
        return school


school_request_model = api.model(
    'School_Request', {
        'name':
        fields.String(required=True, description="The school name"),
        'describe':
        fields.String(required=False, description="The school description"),
    })

school_response_model = api.inherit('School_Response', school_request_model,
                                    model_super_model, {})


@api.route('/')
class SchoolListResource(Resource):
    @api.doc('list_schools')
    @api.marshal_list_with(school_response_model)
    @jwt_required()
    def get(self):
        '''List all schools'''
        return SchoolService.get_list()

    @api.doc('create_new_school')
    @api.expect(school_request_model)
    @api.marshal_with(school_response_model)
    @jwt_required()
示例#16
0
            api.abort(404, 'Student does not exist')
        UserService.update(student.id, data)
        return student


student_request_model = api.model(
    'Student_Request', {
        'username': fields.String(required=True, description="The username"),
        'password': fields.String(required=True, description="The password"),
        'firstname': fields.String(description="The first name"),
        'lastname': fields.String(description="The last name"),
        'email': fields.String(description="The email"),
        'phone': fields.String(description="The phone number"),
    })

student_api_model = api.inherit('Student_Response', student_request_model,
                                model_super_model, {})


@api.route('/school/<school_id>')
@api.param('school_id', 'The school id')
class StudentListResource(Resource):
    @api.doc('list_students')
    @api.marshal_list_with(student_api_model)
    @jwt_required()
    def get(self, school_id):
        '''List all students'''
        return StudentService.get_list(school_id)

    @api.doc('create_new_student')
    @api.expect(student_request_model)
    @api.marshal_with(student_api_model)
示例#17
0
user = ns.model(
    'User', {
        '_id': fields.String(description='User ID'),
        'fullname': fields.String(required=True, description='User name'),
    })

userSecret = ns.model(
    'UserSecret', {
        'username':
        fields.String(required=True, unique=True, description='User login'),
        'password':
        fields.String(required=True, unique=True, description='User password')
    })

userSignUp = ns.inherit('UserSignUp', user, userSecret, {})

userSignIn = ns.inherit(
    'UserSignIn', user,
    {'token': fields.String(description='Generated token')})

##############################
########### Routes ###########
##############################


@ns.route('/signup')
class UserSignUp(Resource):
    @ns.doc('Store user info')
    @ns.expect(userSignUp, validate=True)
    @ns.marshal_with(user)
示例#18
0
from flask import jsonify
from flask_restplus import Namespace, Resource, fields
from flask_jwt_extended import get_jwt_identity

from api.helpers import (ErrorObject, SuccessObject, convert_input_to_tuple,
                         jwt_required_extended, check_for)
from api.services import (DataSourceService as _DataSourceService,
                          DataSourceTokenService as _DataSourceTokenService)

api = Namespace('source', description="Data sources related operations")

user_dto = api.inherit(
    'User',
    {
        'id': fields.Integer(description="Id of user"),
        'username': fields.String(description="Username", example="admin1234"),
        # 'email':
        # fields.String(description="Email of user", example="*****@*****.**"),
        # 'join_date': fields.String,
        # 'last_login_date': fields.String
    })

create_data_source_dto = api.model(
    'CreateDataSourceDto',
    {
        'source':
        fields.String(description="description of the data source",
                      example="cronjob @ localhost"),
        'description':
        fields.String(description="Description of the data source",
                      example="Running on localhost"),
        # 'user':
示例#19
0
        'clue_group_id':
        fields.String(required=True, description="The id of the clue group"),
        'student_id':
        fields.String(required=False,
                      description="The id of the target student"),
        'content':
        fields.String(required=True, description="The content"),
        'deadline':
        fields.DateTime(description="The deadline"),
        'completed_at':
        fields.DateTime(description="The complete time"),
    })

clue_response_model = api.inherit(
    'Clue_response', clue_request_model, model_super_model, {
        'clue_group': fields.Nested(clue_gourp_response_model),
        'student': fields.Nested(user_response_model),
    })


@api.route('/')
class ClueListResource(Resource):
    @api.doc('create_clue')
    @api.expect(clue_request_model)
    @api.marshal_with(clue_response_model)
    @jwt_required()
    def post(self):
        '''Create a new clue'''
        args = request.get_json()
        return ClueService.create(args)
示例#20
0
        api.abort(404)


course_user_request_model = api.model(
    'Course_User_Request', {
        'user_id':
        fields.String(required=True,
                      description="The id of the user associated"),
        'course_id':
        fields.String(required=True,
                      description="The id of the course associated")
    })

course_user_response_model = api.inherit(
    'Course_User_Response', course_user_request_model, model_super_model, {
        'user': fields.Nested(user_response_model),
        'course': fields.Nested(course_response_model)
    })


@api.route('/')
class CourseUserListResource(Resource):
    @api.doc('create_course_users')
    @api.expect(course_user_request_model)
    @api.marshal_with(course_user_response_model)
    @jwt_required()
    def post(self):
        '''Create a new course user record'''
        args = request.get_json()
        return CourseUserService.create(args)
示例#21
0
        "id": fields.String(
            readOnly=True, description="The user identifier", example="1"
        ),
        "email": fields.String(
            required=True,
            description="A valid email address",
            example="*****@*****.**",
        ),
    },
)

USER_FULL = api.inherit(
    "USER_FULL",
    USER,
    {
        "password": fields.String(
            required=True, description="A strong password", example="Xy67!abc"
        )
    },
)

# Not used at present
error = api.model(
    "Error",
    {
        "success": fields.Boolean(default=False),
        "error": fields.Integer(
            description="The HTTP error code", example=400
        ),
        "message": fields.String(
            description="The associated error message",
from flask_restplus import fields

from son_editor.impl import projectsimpl
from son_editor.util.constants import WORKSPACES, PROJECTS
from son_editor.util.requestutil import prepare_response, get_json

namespace = Namespace(WORKSPACES + '/<int:ws_id>/' + PROJECTS, description="Project Resources")
logger = logging.getLogger(__name__)

pj = namespace.model("Project", {
    'name': fields.String(required=True, description='The Project Name')
})

pj_response = namespace.inherit("ProjectResponse", pj, {
    "rel_path": fields.String(description='The Projects location relative to its workpace'),
    "id": fields.Integer(description='The Project ID'),
    "workspace_id": fields.Integer(description='The parent workspace id')
})


@namespace.route('/')
class Projects(Resource):
    @namespace.response(200, "OK", [pj_response])
    def get(self, ws_id):
        """Lists projects

        Lists projects in the given workspace"""
        projects = projectsimpl.get_projects(ws_id)
        return prepare_response(projects)

    @namespace.expect(pj)
示例#23
0
from flask_restplus import fields, Namespace

vote_ns = Namespace('votes', description='Vote operations')

public_vote = vote_ns.model('Public Vote', {
    'id': fields.Integer(readonly=True, description='The vote\'s autogenerated id'),
    'value': fields.Integer(readonly=True, description='The value of the vote')
})

vote = vote_ns.inherit('Vote', public_vote, {
    'owner': fields.Integer(readonly=True, required=True, description='The id of the user that issued the vote'),
    'target': fields.Integer(readonly=True, required=True, description='The id of the idea that the vote belongs to'),
    'created': fields.DateTime(readonly=True, description='The vote\'s creation date'),
    'modified': fields.DateTime(readonly=True, description='The vote\'s last modified date')
})

new_vote = vote_ns.model('New Vote', {
    'target': fields.Integer(required=True, description='The idea id that the vote belongs to'),
    'value': fields.Integer(required=True, description='The value of the vote')
})

modify_vote = vote_ns.model('Modify Vote', {
    'value': fields.Integer(required=True, description='The value of the vote')
})
示例#24
0
from cabx.db.mongodb import DB

user_service_ns = Namespace(
    'user-service',
    description=
    'It will used to create rider details as well as login for both rider and driver'
)

user_model = user_service_ns.model(
    'User', {
        'full_name': fields.String(required=True),
        constants.MOBILE_NUMBER: fields.String(required=True)
    })

user_return_fields = user_service_ns.inherit('user_ui_fields', user_model, {
    constants.ACCESS_TOKEN: fields.String,
    constants.USER_TYPE: fields.String
})


@user_service_ns.route('/user-login')
class UserLogin(Resource):
    """
    user login authentication
    """
    @user_service_ns.errorhandler
    @user_service_ns.marshal_with(user_return_fields)
    def get(self):
        '''List Users'''
        request_id = common_utils.get_request_id()
        return_message = {constants.REQUEST_ID: request_id}
        try:
示例#25
0
        'updated': fields.DateTime(description='updated timestamp'),
        'vote_start_time': fields.DateTime(description='vote start timestamp'),
        'tag': fields.String(description='tag'),
        'category': fields.Nested(proposal_category),
        'zone': fields.Nested(proposal_zone_dto.proposal_zone),
        'creator': creator_fields,
        'estimated_hours': fields.Integer(description='estimated work hours'),
        'vote_duration_hours':
        fields.Integer(description='vote duration hours'),
        'currency_unit': fields.Nested(currency_dto.currency),
        'comments_count':
        fields.Integer(description='proposal comments count'),
    })

page_of_proposals = api.inherit(
    'Page of proposals', pagination,
    {'items': fields.List(fields.Nested(proposal))})

proposal_post = api.model(
    'proposal', {
        'zone_id': fields.String(required=True,
                                 description='proposal zone id'),
        'title': fields.String(required=True, description='proposal title'),
        'summary': fields.String(description='summary'),
        'detail': fields.String(description='detail'),
        'amount': fields.String(description='proposal amount'),
        'status': fields.String(description='proposal status'),
        'tag': fields.String(description='proposal tag'),
        'estimated_hours': fields.Integer(description='estimated work hours'),
        'vote_duration_hours':
        fields.Integer(description='vote duration hours'),
示例#26
0
    'name': fields.String(required=True, description='The VNF Name'),
    'vendor': fields.String(required=True, description='The VNF Vendor'),
    'version': fields.String(required=True, description='The VNF Version')

})

serv = namespace.model("Service", {
    'name': fields.String(required=True, description='The Service Name'),
    'vendor': fields.String(required=True, description='The Service Vendor'),
    'version': fields.String(required=True, description='The Service Version')

})

func_response = namespace.inherit("Response", funct, {
    "descriptor": fields.Nested(model=funct, description="The Complete VNF Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent project id'),
})

serv_response = namespace.inherit("Response", serv, {
    "descriptor": fields.Nested(model=serv, description="The Complete Service Descriptor"),
    "id": fields.Integer(description='The Project ID'),
    "project_id": fields.Integer(description='The parent project id'),
})


@namespace.route('/' + SERVICES + vendor_name_version_path)
@namespace.param('ws_id', 'The Workspace identifier')
@namespace.param('project_id', 'The Project identifier')
@namespace.param('vendor', 'The Network Service vendor')
@namespace.param('name', 'The Network Service name')
示例#27
0
from flask_restplus import Namespace, fields, Resource

from Extensions.Database import db
from Extensions.Errors import ValidationError
from Models.User import User

api = Namespace(name="User", path="/user", description="Manage a user")

user_request = api.model(
    "User Request", {
        "username": fields.String(required=True),
        "email": fields.String(required=True),
        "age": fields.Integer(min=1, max=99),
        "city": fields.String(enum=["BNE", "MEL", "SYD"])
    })
user_response = api.inherit("User Response", user_request,
                            {"id": fields.Integer})


@api.route("/")
class UserController(Resource):
    @api.expect(user_request, validate=True)
    @api.marshal_with(user_response, code=201)
    def post(self, **kwargs):
        """Create a user"""
        body = request.get_json()

        # check user doesn't exist
        if db.session.query(User.id).filter_by(
                username=body["username"]).scalar() is not None:
            current_app.logger.info(f"user {body['username']} exists")
            raise ValidationError("Sorry, that username is already taken!")
示例#28
0
            .first()
        if not teacher:
            api.abort(404, 'Teacher does not exist')
        UserService.update(teacher.id, data)
        return teacher

teacher_request_model = api.model('Teacher_Request', {
    'username': fields.String(required=True, description="The username"),
    'password': fields.String(required=True, description="The password"),
    'firstname': fields.String(description="The first name"),
    'lastname': fields.String(description="The last name"),
    'email': fields.String(description="The email"),
    'phone': fields.String(description="The phone number"),
})

teacher_api_model = api.inherit('Teacher_Response', teacher_request_model, model_super_model, {})

@api.route('/school/<school_id>')
@api.param('school_id', 'The school id')
class TeacherListResource(Resource):
    @api.doc('list_teachers')
    @api.marshal_list_with(teacher_api_model)
    @jwt_required()
    def get(self, school_id):
        '''List all teachers'''
        return TeacherService.get_list(school_id)

    @api.doc('create_new_teacher')
    @api.expect(teacher_request_model)
    @api.marshal_with(teacher_api_model)
    @jwt_required()
import uuid
from blog_api import bcrypt, db
from flask_restplus import Namespace, Resource, fields
from blog_api.models import User
from .category_api import category_posts
from blog_api.core.utils import CreateApiModel
from blog_api.core.authorization import admin_dev_token_required, authorization

user_api = Namespace('user', description='user methods')

user_posts = user_api.inherit('UserPostSchema', category_posts)

user = user_api.model(
    'UserSchema', {
        'id':
        fields.Integer(readonly=True, description='The user id'),
        'public_id':
        fields.String(readonly=True, description='The user public_id'),
        'username':
        fields.String(readonly=True, description='The user username'),
        'email':
        fields.String(required=True, description='The user email address'),
        'active':
        fields.Boolean(readonly=True, description='The user is active'),
        'admin':
        fields.Boolean(readonly=True, description='The user is admin'),
        'created':
        fields.DateTime(readonly=True, attribute='created_time'),
        'avatar':
        fields.String(attribute='image_file',
                      readonly=True,
示例#30
0
    example={
        'tags': {
            'tag1': 'value1',
            'tag2': 'value2'
            },
        'name': 'user_defined_name1',
        'geometry': {
            'coordinates':[32.881679, -117.233344],
            'type': 'point'
            }
        }
    )

m_point = point_api.inherit('Point', m_point_post, {
    'uuid': fields.String(
        description='Unique identifier of point',
        example='random_uuid_1')
    },
    )
m_point.example = dict(list(json.loads(model_to_json(m_point_post)).items())\
                  +[('uuid','random_uuid_1')])

m_point_list = point_api.model('PointList', {
    'point_list': fields.List(fields.Nested(m_point),
        example=[model_to_json(m_point)])
    })

m_message = point_api.model('Message',{
    'success': fields.Boolean(example=True),
    'reason': fields.String(example='reason_string'),
    'uuid': fields.String(example='random_uuid_1')
    })
示例#31
0
        'country': fields.String(required=True, description='Country'),
        'state_id': fields.Integer(required=True, description='State Id'),
        'totalcases': fields.Integer(required=True, description='Total cases'),
        'deaths': fields.Integer(required=True, description='Deaths')
    })

city_cases_response_list = data_endpoints.model(
    'City Cases Response List', {
        'cases':
        fields.Nested(
            city_cases, required=True, as_list=True, description='Cases')
    })

city_cases_response_paginated_list = data_endpoints.inherit(
    'City Cases Response List Paginated', city_cases_response_list, {
        'pagination':
        fields.Nested(
            pagination, required=False, description='Pagination info')
    })

city_cases_response_report = data_endpoints.model(
    'City Cases Response Report', {
        'totalCases': fields.Integer(required=True, description='Total cases'),
        'deaths': fields.Integer(required=True, description='Deaths')
    })

city_cases_filtered_response_report = data_endpoints.model(
    'City Cases Filtered Response Report', {
        'city':
        fields.String(required=True, description='City'),
        'state':
        fields.String(required=True, description='State'),
示例#32
0
    'compression_enabled': fields.Boolean(),
    'inline_compression': fields.Boolean(),
    'caching_policy': fields.String(),
    })

volume_create_model = api.inherit('VolumeCreate', volume_write_model, {
    'name': fields.String(
        min_length=1,
        description="The internal name of the volume",
        example="volume_name",
    ),
    'size_total': fields.Integer(
        description=("The total size of the volume, "
                     " in bytes. If creating, the size"
                     " of the volume.")
    ),
    'aggregate_name': fields.String(
        min_length=1, required=False,
        description=("If applicable, the"
                     " aggregate to place the volume in"
                     " (NetApp only). If not provided, will"
                     " use the one with the most free"
                     " space.")
    ),
    'junction_path': fields.String(min_length=1),
})

volume_read_model = api.inherit('VolumeRead', volume_create_model, {
    'size_used': fields.Integer(),
    'uuid': fields.String(min_length=1),
    'state': fields.String(min_length=1),
示例#33
0
                                  help="User role")

# Models

user_model = users_ns.model(
    "User", {
        "id": fields.Integer,
        "username": fields.String,
        "email": fields.String,
        "name": fields.String,
        "is_active": fields.Boolean,
        "role": fields.String(attribute="role.name")
    })

users_model = users_ns.inherit(
    "Users", pagination_model,
    {"users": fields.List(fields.Nested(user_model), attribute="items")})

# Resources


@users_ns.route("/")
class Users(Resource):
    @jwt_required
    @users_ns.marshal_with(users_model)
    def get(self):
        abort(HTTPStatus.NOT_IMPLEMENTED)

    @jwt_required
    @users_ns.marshal_with(user_model)
    @users_ns.expect(post_user_parser)
    "Repository", {
        'name': fields.String(required=True,
                              description='The Repository Name'),
        'url': fields.Url(required=True, description='The Repository URL')
    })

ws = namespace.model(
    "Workspace", {
        'name': fields.String(required=True, description='The Workspace Name'),
        "catalogues": fields.List(fields.Nested(rep)),
        "platforms": fields.List(fields.Nested(rep))
    })

ws_response = namespace.inherit(
    "WorkspaceResponse", ws, {
        "path": fields.String(description='The Physical Workspace location'),
        "id": fields.Integer(description='The Workspace ID')
    })

descriptor_content = namespace.model("Descriptor Content", {})

descriptor = namespace.model(
    "Descriptor", {
        "id": fields.Integer(description="The descriptor id"),
        "descriptor": fields.Nested(descriptor_content)
    })


@namespace.route('/')
class Workspaces(Resource):
    """Methods for the workspace resource directory"""
示例#35
0
    # gpio_pins = mm_fields.List(mm_fields.Dict())


validate_color = api.model(
    "LED",
    {
        "color":
        fields.String(required=True, example="red", description="LED Color"),
        "mode":
        fields.String(example="solid", description="['solid', 'blink']"),
    },
)

led_attributes = api.inherit(
    "LED attributes",
    validate_color,
    {"id": fields.Integer(readOnly=True, description="LED Number")},
)

led_arguments = reqparse.RequestParser()
led_arguments.add_argument("id", type=int, choices=[1, 2, 3])


def set_led(id):
    for led_obj in leds:
        if led_obj.id == id:
            led = led_obj
            return led


@api.route("/")
示例#36
0
文件: build.py 项目: CermakM/osiris
            required=False,
            description="URL to the OCP pod.",
        ),
        'build_log_url':
        fields.Url(
            required=False,
            description="URL to build logs.",
        ),
        'ocp_info':
        fields.Raw(
            required=False,
            description="OCP build-related information.",
        ),
    })

build_response = api.inherit('build_response', response,
                             {'payload': fields.Nested(build_fields)})

build_log_fields = api.model(
    'build_log_fields', {
        'data': fields.String(required=True, description="Build log data."),
        'metadata': fields.Raw(required=False,
                               description="Build log metadata.")
    })

build_log_response = api.inherit('build_response', response,
                                 {'payload': fields.Nested(build_log_fields)})

# status


@api.route('/status/<string:build_id>')
示例#37
0
    delete_user,
)

users_namespace = Namespace("users")

user = users_namespace.model(
    "User",
    {
        "id": fields.Integer(readOnly=True),
        "username": fields.String(required=True),
        "email": fields.String(required=True),
        "created_date": fields.DateTime,
    },
)

user_post = users_namespace.inherit("User post", user,
                                    {"password": fields.String(required=True)})


class UsersList(Resource):
    @users_namespace.marshal_with(user, as_list=True)
    def get(self):
        """Returns all users"""
        return get_all_users(), 200

    @users_namespace.expect(user_post, validate=True)
    @users_namespace.response(201, "<user_email> was added!")
    @users_namespace.response(400, "Sorry. That email already exists")
    def post(self):
        """Creates a new user"""
        post_data = request.get_json()
        username = post_data.get("username")
示例#38
0
base_user = api.model(
    'BaseUser', {
        'first_name':
        fields.String(
            example='Jimmy', description='Users first name', default=''),
        'last_name':
        fields.String(
            example='Smith', description='Users last name', default=''),
        'username':
        fields.String(example='jsmith', description='Identification string')
    })

registration = api.inherit(
    'Registration', base_user, {
        'password':
        fields.String(example='jimsmith123',
                      description='Authentication string')
    })

user = api.inherit(
    'User', base_user, {
        'id': fields.Integer(),
        'created': fields.DateTime(),
        'updated': fields.DateTime(),
        'is_admin': fields.Boolean
    })

user_list = api.model(
    'UserList', {
        'per_page': fields.Integer(example='20'),
        'pages': fields.Integer(),