예제 #1
0
    def get(self):

        libro = Libro.recuperar(self.request)

        escritores = Escritor.query()
        editoriales = Editorial.query()

        escritor = Escritor.get_by_id(int(libro.escritor.id()))
        libro.nombreEscritor = escritor.nombre
        libro.apellidosEscritor = escritor.apellidos
        editorial = Editorial.get_by_id(int(libro.editorial.id()))
        libro.nombreEditorial = editorial.nombre

        if not escritores or not editoriales:
            self.response.write(
                "Debe introducir primero un escritor y una editorial")
        else:
            valoresPlantilla = {
                "escritores": escritores,
                "editoriales": editoriales,
                "libro": libro
            }

            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(
                jinja.render_template("modificarLibro.html",
                                      **valoresPlantilla))
예제 #2
0
    def post(self):
        nombre = self.request.get("edNombre", "")
        str_codigo = self.request.get("edCodigo", "")
        print(nombre, str_codigo)
        try:
            codigo = int(str_codigo)
        except ValueError:
            codigo = -1

        if codigo < 0 or not nombre:
            self.response.write("Error wachin")
        else:
            editorial = Editorial(nombre=nombre, codigoEditorial=codigo)
            editorial.put()
            time.sleep(1)
            return self.redirect("/editorial/editoriales")
예제 #3
0
    def post(self):
        libro = Libro.get_by_id(int(self.request.get("edLibro", "")))
        titulo = self.request.get("edTitulo", "")
        escritor = Escritor.get_by_id(int(self.request.get("edEscritor", "")))
        str_ISBN = self.request.get("edISBN", "")
        editorial = Editorial.get_by_id(
            int(self.request.get("edEditorial", "")))
        print
        try:
            ISBN = int(str_ISBN)
        except ValueError:
            ISBN = -1

        if ISBN < 0 or not titulo or not escritor or not editorial:
            self.response.write("Error wachin")
        else:
            print(libro)
            libro.titulo = titulo
            libro.escritor = escritor.key
            libro.ISBN = ISBN
            libro.editorial = editorial.key
            print(libro)
            libro.put()
            time.sleep(1)
            return self.redirect("/")
예제 #4
0
    def post(self):
        titulo = self.request.get("edTitulo", "")
        escritor = Escritor.get_by_id(int(self.request.get("edEscritor", "")))
        str_ISBN = self.request.get("edISBN", "")
        editorial = Editorial.get_by_id(int(self.request.get("edEditorial", "")))
        try:
            ISBN = int(str_ISBN)
        except ValueError:
            ISBN = -1

        def comprobarISBN(ISBN):
            if(len(str(ISBN)) != 13 ):
                errorISBN = True
            else:
                errorISBN = False
            return errorISBN

        errorISBN = comprobarISBN(ISBN)

        if not titulo or not escritor or not editorial:
            self.response.write("Error al crear el libro")
        elif errorISBN:
            self.response.write("El ISBN no tiene el formato adecuado")
        else:
            libro = Libro(titulo=titulo, editorial=editorial.key, escritor=escritor.key, ISBN=ISBN)
            libro.put()
            time.sleep(1)
            return self.redirect("/")
예제 #5
0
    def get(self):

        editorial = Editorial.recuperar(self.request)

        valoresPlantilla = {"editorial": editorial}

        jinja = jinja2.get_jinja2(app=self.app)
        self.response.write(
            jinja.render_template("modificarEditorial.html",
                                  **valoresPlantilla))
예제 #6
0
    def get(self):

        escritores = Escritor.query().fetch(50)
        editoriales = Editorial.query().fetch(50)

        valoresPlantilla = {
            "escritores": escritores,
            "editoriales": editoriales
        }

        jinja = jinja2.get_jinja2(app=self.app)
        self.response.write(
            jinja.render_template("nuevoEditorial.html", **valoresPlantilla))
예제 #7
0
    def get(self):

        escritores = Escritor.query()
        editoriales = Editorial.query()

        if  not escritores or not editoriales:
            self.response.write("Debe introducir primero un escritor y una editorial")
        else:
            valoresPlantilla = {
                "escritores": escritores,
                "editoriales": editoriales,
            }

            jinja = jinja2.get_jinja2(app=self.app)
            self.response.write(jinja.render_template("nuevoLibro.html", **valoresPlantilla))
예제 #8
0
    def get(self):
        borrar = True
        editorial = Editorial.recuperar(self.request)
        libros = Libro.query()
        for libro in libros:
            if libro.editorial == editorial.key and borrar:
                borrar = False

        if borrar:
            editorial.key.delete()
            time.sleep(1)
            return self.redirect("/editorial/editoriales")
        else:
            self.response.write(
                "No puedes borrar una editorial habiendo libros en la biblioteca de esta editorial"
            )
예제 #9
0
    def post(self):
        editorial = Editorial.get_by_id(
            int(self.request.get("edEditorial", "")))
        nombre = self.request.get("edNombre", "")
        str_codigoEditorial = self.request.get("edCodigo", "")
        try:
            codigoEditorial = int(str_codigoEditorial)
        except ValueError:
            codigoEditorial = -1

        if codigoEditorial < 0 or not nombre:
            self.response.write("Error en la modificación")
        else:
            editorial.nombre = nombre
            editorial.codigoEditorial = codigoEditorial
            editorial.put()
            time.sleep(1)
            return self.redirect("/editorial/editoriales")
예제 #10
0
    def get(self):
        usr = users.get_current_user()

        if usr:
            url_usr = users.create_logout_url("/")

        else:
            url_usr = users.create_login_url("/")

        libros = Libro.query().order(Libro.titulo)
        if libros.count() > 0:
            for libro in libros:

                escritor = Escritor.get_by_id(int(libro.escritor.id()))
                libro.nombreEscritor = escritor.nombre
                libro.apellidosEscritor = escritor.apellidos
                libro.escritor = escritor.key
                editorial = Editorial.get_by_id(int(libro.editorial.id()))
                libro.nombreEditorial = editorial.nombre
                libro.editorial = editorial.key
            if usr:
                nickname = usr.nickname()
                valoresPlantilla = {
                    "libros": libros,
                    "escritor": escritor,
                    "editorial": editorial,
                    "url_usr": url_usr,
                    "nickname": nickname,
                    "usr": usr
                }

                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("index.html", **valoresPlantilla))
            else:
                valoresPlantilla = {
                    "libros": libros,
                    "escritor": escritor,
                    "editorial": editorial,
                    "url_usr": url_usr
                }

                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("index.html", **valoresPlantilla))

        else:
            if usr:
                nickname = usr.nickname()
                valoresPlantilla = {
                    "libros": libros,
                    "url_usr": url_usr,
                    "nickname": nickname,
                    "usr": usr
                }

                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("index.html", **valoresPlantilla))
            else:
                valoresPlantilla = {"libros": libros, "url_usr": url_usr}

                jinja = jinja2.get_jinja2(app=self.app)
                self.response.write(
                    jinja.render_template("index.html", **valoresPlantilla))