Ver Mensaje Individual
  #5 (permalink)  
Antiguo 19/06/2012, 11:52
Onsterion
 
Fecha de Ingreso: octubre-2010
Mensajes: 73
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Python 2.7 + PyQt4 - Pasar HTML a tabla SQL

Cita:
Iniciado por razpeitia Ver Mensaje
Lo que pasa es que el Richtext que maneja QTextEdit es básicamente es un subconjunto de html + el atributo style. Ver mas aquí.

Entonces lo que haces es guardar ese html en la base de datos y después ponerlo con el método setHTML.

Eso si, por favor no te olvides de parametrizar tu query por que si no vas a tener problemas.
Insertandolo manualmente en la tabla

Código:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">holatextooaaa</p></body></html>
Y al traerlo se imprime perfecto sin usar SetHTML

Código:
    def traer_anotacion(self):
        self.main_program.combo_box_texto_seleccionado = self.main_program.comboBox_anotaciones.currentText()
        print self.main_program.combo_box_texto_seleccionado
        
        self.main_program.mostrar_la_anotacion = QtSql.QSqlQuery()
        self.main_program.mostrar_la_anotacion.exec_("SELECT texto FROM os_anotaciones where nombre='"+ str (self.main_program.combo_box_texto_seleccionado)+"'")
        print (self.main_program.mostrar_la_anotacion.numRowsAffected())
        
        while(self.main_program.mostrar_la_anotacion.next()):
            self.main_program.resultado_del_query_al_linedit = self.main_program.mostrar_la_anotacion.value(0).toString()
            self.main_program.textEdit_ver_anotaction.setText(str (self.main_program.resultado_del_query_al_linedit))



No encuentro la forma de insertar el HTML en la tabla

Y que seria parametrizar el query?




Gracias.-
__________________
Página Principal: http://www.almightysystem.com.ar/