Example #1
0
 def get(self):
     try:
         all_notifs = NotificacionTemplateModel.objects.raw({})
     except NotificacionTemplateModel.DoesNotExist:
         return {'message': f"No se encontró ninguna notificación"}, 404
     # TODO: Agregar el URL para la solicitud al API de la notificacion, el link a la notificacion
     # TODO: Buscar en Google TODO Python vsCode
     return  NotificacionTemplateSchema(
                 only=(
                 "_id",
                 "titulo",
                 "fecha",
                 "tipo_notificacion",
                 "filtros"
                 ), many=True).dump(all_notifs),200
Example #2
0
 def get(self, id):
     print("Admin")
     n = NotificacionTemplateModel.find_by_id(id)
     if not n:
         print("no se encontro")
         return {"message": "No se encontro el la notificación!"}, 404
     return NotificacionTemplateSchema(
         only=(
         "_id",
         "titulo",
         "mensaje",
         "fecha",
         "imagenIcon",
         "bar_text",
         "tipo_notificacion",
         "link",
         "filtros"
         )).dump(n), 200
Example #3
0
 def patch(self, id):
     n = NotificacionTemplateModel.find_by_id(id)
     if not n:
         return {"message": "No se encontro la notificación!"}, 404
     noti_json = request.get_json()
     # print(user_json)
     noti = not_schema_template.load(noti_json)
     try:
         if "tipo_notificacion" in noti:
             n.tipo_notificacion=noti["tipo_notificacion"]
         if "imagenIcon" in noti:
             n.imagenIcon=noti["imagenIcon"]
         if "imagenDisplay" in noti:
             n.imagenDisplay=noti["imagenDisplay"]
         if "titulo" in noti:
             n.titulo=noti["titulo"]
         if "fecha" in noti:
             n.fecha=noti["fecha"]
         if "bar_text" in noti:
             n.bar_text=noti["bar_text"]
         if "mensaje" in noti:
             n.mensaje=noti["mensaje"]
         if "link" in noti:
             n.link=noti["link"]
         n.save()
     except ValidationError as exc:
         print(exc.message)
         return {"message": "No se pudo actualizar la notificación."}, 404
     return NotificacionTemplateSchema(
         only=(
         "_id",
         "titulo",
         "mensaje",
         "fecha",
         "imagenIcon",
         "imagenDisplay",
         "bar_text",
         "tipo_notificacion",
         "link",
         )).dump(n), 200
Example #4
0
 def get(self, id):
 #Participante id = part_id
     try:
         """
         Dependiendo del id que se consulta Pymodm genera
         una respuesta específica: 
         -Un query a el _id de la notificacion (_id) regresa:
             [
                 {
                     "_id": "5dfb4cbf23acb0be88ff5e9b",
                     "id_participante": "<ParticipanteModel object>",
                     "titulo": "Bienvenido al programa"
                 }
             ]
         
         -Un query a el _id del participante (id_participante) regresa:
         NotificacionModel(id_participante=ParticipanteModel(paterno='Martinez', email='*****@*****.**', fecha_nacimiento=datetime.datetime(1997, 6, 6, 21, 0), _id=ObjectId('5dfb2779272294ec0c7052fc'), fecha_antiguedad=datetime.datetime(2019, 12, 19, 1, 32, 9, 278000), foto='https://estaticos.muyinteresante.es/media/cache/760x570_thumb/uploads/images/article/5536592a70a1ae8d775df846/dia-del-mono.jpg', tarjeta_sellos=TarjetaSellosModel(num_sellos=1, _id=ObjectId('5dfb3be68989a2f1e2918008')), nombre='Emmanuel3', password='******', sexo='Masculino'), titulo='Bienvenido al programa', _id=ObjectId('5dfb4cbf23acb0be88ff5e9b'))
         NotificacionModel(id_participante=ParticipanteModel(paterno='Martinez', email='*****@*****.**', fecha_nacimiento=datetime.datetime(1997, 6, 6, 21, 0), _id=ObjectId('5dfb2779272294ec0c7052fc'), fecha_antiguedad=datetime.datetime(2019, 12, 19, 1, 32, 9, 278000), foto='https://estaticos.muyinteresante.es/media/cache/760x570_thumb/uploads/images/article/5536592a70a1ae8d775df846/dia-del-mono.jpg', tarjeta_sellos=TarjetaSellosModel(num_sellos=1, _id=ObjectId('5dfb3be68989a2f1e2918008')), nombre='Emmanuel3', password='******', sexo='Masculino'), titulo='Bienvenido al programa', _id=ObjectId('5dfb4d0268032c30e8e9fd00'))
         i,e. 
             [
                 {
                     "id_participante": "<ParticipanteModel object>",
                     "titulo": "Bienvenido al programa",
                     "_id": "5dfb4cbf23acb0be88ff5e9b"
                 },
                 {
                     "id_participante": "<ParticipanteModel object>",
                     "titulo": "Bienvenido al programa",
                     "_id": "5dfb4d0268032c30e8e9fd00"
                 }
             ]
         NOTE: Nice! :), en este caso, el primero es el que queremos.
         """
         part_id = ObjectId(id)
         participante_notifs_id = NotificacionModel.objects.raw({'id_participante': part_id, 'estado': 0})
         notifsList=[]
         for n in participante_notifs_id:
             pprint(n.id_notificacion)
             notifsList.append(n.id_notificacion)
         #for item in notifs:
         #    pprint(item)
         total_notifs = len(notifsList)
     except NotificacionModel.DoesNotExist:
         return {'message': f"No sellos_card in participante with id{ id }"}, 404
     # TODO: Agregar el URL para la solicitud al API de la notificacion, el link a la notificacion
     # TODO: Buscar en Google TODO Python vsCode
     return {"Notificaciones":
                 NotificacionTemplateSchema(
                 only=(
                 "_id",
                 "titulo",
                 # "id_participante"
                 "mensaje",
                 "fecha",
                 "imagenIcon",
                 "bar_text",
                 "tipo_notificacion",
                 "link",
                 # "estado"
                 ), many=True).dump(notifsList),
             "Total": total_notifs    
             },200
Example #5
0
 def put(self, id, accion):
     if accion == 'ninguna':
         n = NotificacionTemplateModel.find_by_id(id)
         if not n:
             return {"message": "No se encontro la notificación!"}, 404
         noti_json = request.get_json()
         # pprint(noti_json["notificacion"])
         noti = not_schema_template.load(noti_json["notificacion"])
         try:
             if "tipo_notificacion" in noti:
                 n.tipo_notificacion=noti["tipo_notificacion"]
             if "imagenIcon" in noti:
                 n.imagenIcon=noti["imagenIcon"]
             if "titulo" in noti:
                 n.titulo=noti["titulo"]
             if "fecha" in noti:
                 n.fecha=noti["fecha"]
             if "bar_text" in noti:
                 n.bar_text=noti["bar_text"]
             if "mensaje" in noti:
                 n.mensaje=noti["mensaje"]
             if "link" in noti:
                 n.link=noti["link"]
             n.save()
         except ValidationError as exc:
             print(exc.message)
             return {"message": "No se pudo actualizar la notificación."}, 404
         return {"notificacion": NotificacionTemplateSchema(
             only=(
             "_id",
             "titulo",
             "mensaje",
             "fecha",
             "imagenIcon",
             "bar_text",
             "tipo_notificacion",
             "link",
             )).dump(n)}, 200
         # /admin/notificaciones/<string:id> patch! ya existe!
     elif accion == 'premio':
         n = NotificacionTemplateModel.find_by_id(id)
         pprint(n)
         if not n:
             return {"message": "No se encontro la notificacion"}, 404
         noti_json = request.get_json()
         # pprint(noti_json["notificacion"])
         noti = not_schema_template.load(noti_json["notificacion"])
         # pprint(noti)
         try:
             if "tipo_notificacion" in noti:
                 n.tipo_notificacion=noti["tipo_notificacion"]
             if "imagenIcon" in noti:
                 n.imagenIcon=noti["imagenIcon"]
             if "titulo" in noti:
                 n.titulo=noti["titulo"]
             if "fecha" in noti:
                 n.fecha=noti["fecha"]
             if "bar_text" in noti:
                 n.bar_text=noti["bar_text"]
             if "mensaje" in noti:
                 n.mensaje=noti["mensaje"]
             if "link" in noti:
                 n.link=noti["link"] # link no se debe actualizar, pero bueno! jaja
             n.save()
         except ValidationError as exc:
             print(exc.message)
             return {"message": "No se pudo actualizar la notificación."}, 404
         p = PremioModel.find_by_id(n.link)
         if not p:
             return {"message": "No se encontro el premio"}, 404
         # p_req = request.get_json()
         # pprint(p_req)
         premio = premio_schema.load(noti_json["premio"])
         # pprint(p_req["premio"])
         pprint(premio)
         try:
             if "nombre" in premio:
                 p.nombre = premio["nombre"] 
             if "puntos" in premio:
                 p.puntos = premio["puntos"] 
             if "codigo_barras" in premio:
                 p.codigo_barras = premio["codigo_barras"] 
             if "codigo_qr" in premio:
                 p.codigo_barras = premio["codigo_barras"] 
             if "imagen_icon" in premio:
                 p.imagen_icon = premio["imagen_icon"] 
             if "imagen_display" in premio:
                 p.imagen_icon = premio["imagen_icon"] 
             if "fecha_creacion" in premio:
                 p.imagen_icon = premio["imagen_icon"] 
             if "fecha_vigencia" in premio:
                 p.fecha_vigencia = premio["fecha_vigencia"] 
             if "fecha_redencion" in premio:
                 p.fecha_redencion = premio["fecha_redencion"] 
             p.save()
         except ValidationError as exc:
             print(exc.message)
             return {"message": "No se pudo actualizar el premio."}, 400
         return {"notificacion": NotificacionTemplateSchema(
             only=(
             "_id",
             "titulo",
             "mensaje",
             "fecha",
             "imagenIcon",
             "bar_text",
             "tipo_notificacion",
             "link",
             )).dump(n),
          "premio":  PremioSchema(
                 only=(
                     "_id",
                     "nombre", 
                     "puntos", 
                     "codigo_barras", 
                     "codigo_qr",
                     "imagen_icon",
                     "imagen_display",
                     "fecha_creacion", 
                     "fecha_vigencia", 
                     # "fecha_redencion",
                     # "id_producto",
                     "id_participante"
                 )).dump(p)
         }, 200               
     elif accion == 'encuesta':
         n = NotificacionTemplateModel.find_by_id(id)
         if not n:
             return {"message": "No se encontro la notificación!"}, 404
         e = EncuestaModel.find_by_id(n.link)
         if not e:
             return {"message": "No se encontro la encuesta"}, 404
         noti_json = request.get_json()
         noti = not_schema_template.load(noti_json["notificacion"])
         # encuesta_json = request.get_json()
         encuesta = EncuestaSchema().load(noti_json["encuesta"])
         try:
             if "tipo_notificacion" in noti:
                 n.tipo_notificacion=noti["tipo_notificacion"]
             if "imagenIcon" in noti:
                 n.imagenIcon=noti["imagenIcon"]
             if "titulo" in noti:
                 n.titulo=noti["titulo"]
             if "fecha" in noti:
                 n.fecha=noti["fecha"]
             if "bar_text" in noti:
                 n.bar_text=noti["bar_text"]
             if "mensaje" in noti:
                 n.mensaje=noti["mensaje"]
             if "link" in noti:
                 n.link=noti["link"]
             # Encuesta
             if "titulo" in encuesta:
                 e.titulo=encuesta["titulo"]
             if "categoria" in encuesta:
                 e.categoria=encuesta["categoria"]
             e.fecha_creacion=dt.datetime.now()
             if "metrica" in encuesta:
                 e.metrica=encuesta["metrica"]
             if "puntos" in encuesta:
                 e.puntos=encuesta["puntos"]
             if "paginas" in encuesta:
                 e.paginas=encuesta["paginas"]
                 pprint(e.paginas)
                 # for pagina in e.paginas:
                 #     print(1)
             e.save()
             n.save()
         except ValidationError as exc:
             print(exc.message)
             return {"message": "No se pudo actualizar la notificación."}, 404
         return {
             "notificacion": NotificacionTemplateSchema(
                 only=(
                 "_id",
                 "titulo",
                 "mensaje",
                 "fecha",
                 "imagenIcon",
                 "bar_text",
                 "tipo_notificacion",
                 "link"
                 )).dump(n),
             "encuesta": EncuestaSchema(
                     only=(
                         "_id",
                         "titulo",
                         "categoria",
                         "fecha_creacion",
                         "fecha_respuesta",
                         "metrica",
                         "puntos",
                         "paginas",
                     )).dump(e)
         }, 200
Example #6
0
 def get(self, id, accion):
     if accion == 'ninguna':
         n = NotificacionTemplateModel.find_by_id(id)
         if not n:
             return {"message": "No se encontro la notificación"}, 404
         return {"notificacion": NotificacionTemplateSchema(
             only=(
             "_id",
             "titulo",
             "mensaje",
             "fecha",
             "imagenIcon",
             "bar_text",
             "tipo_notificacion",
             "link",
             "filtros"
             )).dump(n)}, 200
     elif accion == 'premio':
         n = NotificacionTemplateModel.find_by_id(id)
         pprint(n)
         if not n:
             return {"message": "No se encontro el premio"}, 404
         p = PremioModel.find_by_id(n.link)
         if not p:
             return {"message": "No se encontro el premio"}, 404
         return {"notificacion": NotificacionTemplateSchema(
             only=(
             "_id",
             "titulo",
             "mensaje",
             "fecha",
             "imagenIcon",
             "bar_text",
             "tipo_notificacion",
             "link",
             "filtros"
             )).dump(n),
          "premio":  PremioSchema(
                 only=(
                     "_id",
                     "nombre", 
                     "puntos", 
                     "codigo_barras", 
                     "codigo_qr",
                     "imagen_icon",
                     "imagen_display",
                     "fecha_creacion", 
                     "fecha_vigencia", 
                     # "fecha_redencion",
                     # "id_producto",
                     "id_participante"
                 )).dump(p)
         }, 200               
     elif accion == 'encuesta':
         n = NotificacionTemplateModel.find_by_id(id)
         pprint(n)
         if not n:
             return {"message": "No se encontro la notificacion"}, 404
         en = EncuestaModel.find_by_id(n.link)
         if not en:
             return {"message": "No se encontro la encuesta"}, 404
         return {
             "notificacion": NotificacionTemplateSchema(
                 only=(
                 "_id",
                 "titulo",
                 "mensaje",
                 "fecha",
                 "imagenIcon",
                 "bar_text",
                 "tipo_notificacion",
                 "link",
                 "filtros"
                 )).dump(n),
             "encuesta": EncuestaSchema(
                     only=(
                         "_id",
                         "titulo",
                         "categoria",
                         "fecha_creacion",
                         "fecha_respuesta",
                         "metrica",
                         "puntos",
                         "paginas",
                     )).dump(en)
         }, 200
Example #7
0
from pymongo.errors import DuplicateKeyError

#from schemas.participante import ParticipanteSchema 
from models.participante import ParticipanteModel 
from models.premio import PremioModel, PremioParticipanteModel

from models.encuesta import EncuestaModel, EncuestaPaginaModel, EncuestaOpcionesModel, ParticipantesEncuestaModel
from schemas.encuesta import EncuestaSchema, EncuestaPaginaSchema, EncuestaOpcionesSchema, ParticipanteEncuestaSchema

from schemas.notificacion import NotificacionSchema, NotificacionTemplateSchema
from schemas.premio import PremioSchema, PremioParticipanteSchema
from models.notificacion import NotificacionModel, NotificacionTemplateModel  
from marshmallow import pprint

not_schema = NotificacionSchema()
not_schemas_template = NotificacionTemplateSchema(many=True)
not_schema_template = NotificacionTemplateSchema()
not_schemas = NotificacionSchema(many=True)

premio_schema = PremioSchema()

# Establish a connection to the database.
connect("mongodb://localhost:27017/ej1")

class NotificacionList(Resource):

    #Devolver aquellas en el estado sin eliminar

    @classmethod
    def get(self, id):
    #Participante id = part_id
Example #8
0
from pymongo.errors import DuplicateKeyError

#from schemas.participante import ParticipanteSchema 
from models.participante import ParticipanteModel 
from models.premio import PremioModel, PremioParticipanteModel

from models.encuesta import EncuestaModel, EncuestaPaginaModel, EncuestaOpcionesModel, ParticipantesEncuestaModel
from schemas.encuesta import EncuestaSchema, EncuestaPaginaSchema, EncuestaOpcionesSchema, ParticipanteEncuestaSchema

from schemas.notificacion import NotificacionSchema, NotificacionSchemaExtended, NotificacionTemplateSchema
from schemas.premio import PremioSchema, PremioParticipanteSchema
from models.notificacion import NotificacionModel, NotificacionTemplateModel  
from marshmallow import pprint

not_schema = NotificacionSchema()
not_schemas_template = NotificacionTemplateSchema(many=True)
not_schema_template = NotificacionTemplateSchema()
not_schemas = NotificacionSchema(many=True)

premio_schema = PremioSchema()

# Establish a connection to the database.
connect("mongodb://localhost:27017/ej1")

class NotificacionList(Resource):
    #Devolver aquellas en el estado sin eliminar
    # 30/04/04 Modificacion para enviar el _id de la notificacion
    #   en lugar de el del template
    @classmethod
    def get(self, id):
    #Participante id = part_id