Beispiel #1
0
        return {'msg': str(e)}, 400
    return make_response({'msg': 'ticket succesfully booked'}, 200)


@main.errorhandler(422)
def handle_error(err):
    headers = err.data.get('headers', None)
    messages = err.data.get('messages', ['Invalid Request.'])
    logger.warning(f'Invalid input params: {messages}')
    if headers:
        return jsonify({'message': messages}), 400, headers
    else:
        return jsonify({'message': messages}), 400


docs.register(get_schedules, blueprint="main")
docs.register(place_ticket, blueprint="main")
docs.register(book_ticket, blueprint='main')
docs.register(get_empty_places, blueprint='main')
docs.register(get_cities, blueprint='main')


def get_fit_routes(routes_info):
    routes = []
    for i in range(len(routes_info)):
        train_struc, wagon_types = get_seats_info(routes_info[i][0],
                                                  routes_info[i][2],
                                                  routes_info[i][1])
        seats_info = get_empty_train_seats_info(train_struc, wagon_types)
        if seats_info != {}:
            routes.append(serialize_fit_route(routes_info[i], seats_info))
Beispiel #2
0
from app import docs
from views import (add_comment, add_post, delete_comment, delete_post,
                   get_comments, get_posts, registration, update_comment,
                   update_post, get_users)

docs.register(registration)
docs.register(get_posts)
docs.register(add_post)
docs.register(update_post)
docs.register(delete_post)
docs.register(get_comments)
docs.register(add_comment)
docs.register(update_comment)
docs.register(delete_comment)
docs.register(get_users)
        return {'message': str(e)}, 400
    return {'access_token': token , 'firstname': user.firstname, 'lastname': user.lastname, 'role': user.role}

@users.route('/logout', methods=['DELETE'])
@jwt_required
@marshal_with(StatusMessageSchema)
def logout():
    try:
        jti = get_raw_jwt()['jti']
        blacklist.add(jti)
    except Exception as e:
        logger.warning(
            f'logout failed with errors: {e}')
        return {'message': str(e)}, 400
    return {"msg": "Successfully logged out"}, 200

@users.errorhandler(422)
def handle_error(err):
    headers = err.data.get('headers', None)
    messages = err.data.get('messages', ['Invalid Request.'])
    logger.warning(f'Invalid input params: {messages}')
    if headers:
        return jsonify({'message': messages}), 400, headers
    else:
        return jsonify({'message': messages}), 400

docs.register(logout, blueprint='users')
docs.register(register, blueprint='users')
docs.register(login, blueprint='users')

Beispiel #4
0
def verify_ticket(**kwargs):
    manager_id = get_jwt_identity()
    try:
        ticket_id = kwargs.get('ticket_id')
        kwargs.get('ticket_id')
        session.query(Ticket).filter(Ticket.id == ticket_id). \
            update({'is_booked': False, 'book_end_date': None}, synchronize_session='evaluate')
        session.commit()
        logger.info(f'manager {manager_id} verified ticket {ticket_id}')
    except Exception as e:
        logger.warning(
            f'manager: {manager_id} - failed to verify ticket: {e}')
        return {'message': str(e)}, 400
    return {"msg": "Successfully verified ticket"}, 200


docs.register(verify_ticket, blueprint='profile')
docs.register(delete_ticket, blueprint='profile')
docs.register(search_tickets, blueprint='profile')
UserInfoView.register(profile, docs, '/profile', 'userinfoview')
UsersTickets.register(profile, docs, '/user_tickets', 'userstickets')


def get_tickets(**kwargs):
    if (kwargs.get('usr_email') is not None):
        return session.query(Ticket).join(User, User.id == Ticket.user_id). \
            filter(User.email == kwargs.get('usr_email')).all()
    if (kwargs.get('ticket_id') is not None):
        return [session.query(Ticket).get(kwargs.get('ticket_id'))]
    return []
Beispiel #5
0
from app import api, db, docs
from flask import redirect, request

from flask_apispec import use_kwargs, marshal_with, doc
from flask_apispec.views import MethodResource

from marshmallow import fields, Schema


class TemplateModel(db.Model):
    __tablename__ = 'template'
    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.String(64), index=True)


@doc(tags=['Template'])
class Template(MethodResource):
    def get(self):
        """ Template route

        """
        pass


api.add_resource(Template, '/api/template')

docs.register(Template)