Beispiel #1
0
from models import Usuario
from restful.formatResponse import formatOutput


class RegisterAPI(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('email',
                                   type=str,
                                   required=True,
                                   help='No email provided',
                                   location='json')
        self.reqparse.add_argument('password',
                                   type=str,
                                   required=True,
                                   help='No password provided',
                                   location='json')
        super(RegisterAPI, self).__init__()

    def post(self):
        args = self.reqparse.parse_args()
        email = args['email']
        password = args['password']
        nuevo_usuario = Usuario(email, password)
        db.session.add(nuevo_usuario)
        db.session.commit()
        return formatOutput(1003), 201


api.add_resource(RegisterAPI, '/registration', endpoint='registration')
Beispiel #2
0
}


class UsuarioAPI(Resource):
    decorators = [jwt_required()]

    def get(self, usuario_id):
        usuario = Usuario.query.filter_by(id_usuario=usuario_id).first()
        if usuario is not None:
            content = {'user': marshal(usuario, users_fields)}
            return formatOutput(1001, content)
        else:
            return formatOutput(1002)


api.add_resource(UsuarioAPI, '/users/<int:usuario_id>', endpoint='user')


class UsuariosAPI(Resource):

    # decorators = [jwt_required()]

    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('email',
                                   type=str,
                                   required=True,
                                   help='No email provided',
                                   location='json')
        self.reqparse.add_argument('password',
                                   type=str,
Beispiel #3
0
    'timediff_m': fields.String,
    'creado_en': fields.DateTime(dt_format='iso8601'),
    'actualizado_en': fields.DateTime(dt_format='iso8601')
}


class EventoAPI(Resource):
    def get(self, evento_id):
        evento = Evento.query.filter_by(id_evento=evento_id).first()
        if evento is not None:
            content = { 'event': marshal(evento, events_fields) }
            return formatOutput(3000,content)
        else:
            return formatOutput(3001)

api.add_resource(EventoAPI, '/events/<int:evento_id>')


class EventosAPI(Resource):

    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('id_tabla', type = str, required = True, help = 'No id_tabla provided', location = 'json')
        self.reqparse.add_argument('fecha', type = str, required = True, help = 'No fecha provided', location = 'json')
        self.reqparse.add_argument('privacidad', type = int, required = True, help = 'No privacidad provided', location = 'json')
        self.reqparse.add_argument('color', type = str, required = True, help = 'No color provided', location = 'json')
        self.reqparse.add_argument('comienza', type = str, required = True, help = 'No comienza provided', location = 'json')
        self.reqparse.add_argument('finaliza', type = str, required = True, help = 'No finaliza provided', location = 'json')
        self.reqparse.add_argument('titulo', type = str, required = True, help = 'No titulo provided', location = 'json')
        self.reqparse.add_argument('descripcion', type = str, required = True, help = 'No descripcion provided', location = 'json')
        self.reqparse.add_argument('url_imagen', type = str, location = 'json')
Beispiel #4
0
    'creado_en': fields.DateTime(dt_format='iso8601'),
    'actualizado_en': fields.DateTime(dt_format='iso8601'),
    'ultima_conexion': fields.DateTime(dt_format='iso8601')
}

class UsuarioAPI(Resource):
    decorators = [jwt_required()]
    def get(self, usuario_id):
        usuario = Usuario.query.filter_by(id_usuario=usuario_id).first()
        if usuario is not None:
            content = { 'user': marshal(usuario, users_fields) }
            return formatOutput(1001,content)
        else:
            return formatOutput(1002)

api.add_resource(UsuarioAPI, '/users/<int:usuario_id>', endpoint = 'user')


class UsuariosAPI(Resource):

    # decorators = [jwt_required()]

    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('email', type = str, required = True, help = 'No email provided', location = 'json')
        self.reqparse.add_argument('password', type = str, required = True, help = 'No password provided', location = 'json')
        super(UsuariosAPI, self).__init__()

    def get(self):
        lista_usuarios = Usuario.query.all()
        content = { 'users': list(map(lambda t: marshal(t, users_fields), lista_usuarios)) }
Beispiel #5
0
            return formatOutput(2002)

        # from datetime import datetime
        # from pytz import timezone
        # fmt = "%Y-%m-%d %H:%M:%S %Z%z"
        # now_time = datetime.now(timezone('Europe/Madrid'))

        # return    {
        #           str(usuario_id) :   usuarios[usuario_id],
        #           tabla_fecha     :   tablas[tabla_fecha],
        #           'timezone'      :   now_time.strftime(fmt),
        #           'week_of_year'  :   int(now_time.strftime("%U"))
        #       }


api.add_resource(TablaEventosAPI, '/<int:usuario_id>/<string:tabla_fecha>')


class TablasAPI(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('id_usuario',
                                   type=int,
                                   required=True,
                                   help='No id_usuario provided',
                                   location='json')
        self.reqparse.add_argument('descripcion',
                                   type=str,
                                   required=True,
                                   help='No descripcion provided',
                                   location='json')
Beispiel #6
0
from myglobal import db,api
from flask_restful import Resource, reqparse, fields, marshal
from models import Usuario
from restful.formatResponse import formatOutput



class RegisterAPI(Resource):

    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('email', type = str, required = True, help = 'No email provided', location = 'json')
        self.reqparse.add_argument('password', type = str, required = True, help = 'No password provided', location = 'json')
        super(RegisterAPI, self).__init__()

    def post(self):
        args = self.reqparse.parse_args()
        email = args['email']
        password = args['password'];
        nuevo_usuario = Usuario(email,password)
        db.session.add(nuevo_usuario)
        db.session.commit()
        return formatOutput(1003), 201


api.add_resource(RegisterAPI, '/registration', endpoint = 'registration')

Beispiel #7
0
            return formatOutput(2002)

        # from datetime import datetime
        # from pytz import timezone
        # fmt = "%Y-%m-%d %H:%M:%S %Z%z"
        # now_time = datetime.now(timezone('Europe/Madrid'))

        # return    {
        #           str(usuario_id) :   usuarios[usuario_id],
        #           tabla_fecha     :   tablas[tabla_fecha],
        #           'timezone'      :   now_time.strftime(fmt),
        #           'week_of_year'  :   int(now_time.strftime("%U"))
        #       }


api.add_resource(TablaEventosAPI, '/<int:usuario_id>/<string:tabla_fecha>')


class TablasAPI(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('id_usuario', type = int, required = True, help = 'No id_usuario provided', location = 'json')
        self.reqparse.add_argument('descripcion', type = str, required = True, help = 'No descripcion provided', location = 'json')
        self.reqparse.add_argument('fecha', type = str, required = True, help = 'No fecha provided', location = 'json')
        super(TablasAPI, self).__init__()

    def get(self):
        lista_tablas = Tabla.query.all()
        content = { 'tables': list(map(lambda t: marshal(t, tables_fields), lista_tablas)) }
        return formatOutput(2003,content)
Beispiel #8
0
    'creado_en': fields.DateTime(dt_format='iso8601'),
    'actualizado_en': fields.DateTime(dt_format='iso8601')
}


class EventoAPI(Resource):
    def get(self, evento_id):
        evento = Evento.query.filter_by(id_evento=evento_id).first()
        if evento is not None:
            content = {'event': marshal(evento, events_fields)}
            return formatOutput(3000, content)
        else:
            return formatOutput(3001)


api.add_resource(EventoAPI, '/events/<int:evento_id>')


class EventosAPI(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument('id_tabla',
                                   type=str,
                                   required=True,
                                   help='No id_tabla provided',
                                   location='json')
        self.reqparse.add_argument('fecha',
                                   type=str,
                                   required=True,
                                   help='No fecha provided',
                                   location='json')