Changeset 7511 for main/waeup.sirp/trunk
- Timestamp:
- 25 Jan 2012, 14:25:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/students/utils.py
r7369 r7511 55 55 return tag1 + '%s:</font>' 56 56 57 def formatted_text(color=FONT_COLOR, size=FONT_SIZE): 58 tag1 ='<font color=%s size=%d>' % (color, size) 59 return tag1 + '%s</font>' 57 def formatted_text(text, color=FONT_COLOR, size=FONT_SIZE): 58 """Turn `text`, `color` and `size` into an HTML snippet. 59 60 The snippet is suitable for use with reportlab and generating PDFs. 61 Wraps the `text` into a ``<font>`` tag with passed attributes. 62 63 Also non-strings are converted. Raw strings are expected to be 64 utf-8 encoded (usually the case for widgets etc.). 65 66 The returned snippet is unicode type. 67 """ 68 if not isinstance(text, unicode): 69 if isinstance(text, basestring): 70 text = text.decode('utf-8') 71 else: 72 text = unicode(text) 73 tag1 = u'<font color="%s" size="%d">' % (color, size) 74 return tag1 + u'%s</font>' % text 60 75 61 76 def generate_student_id(students,letter): … … 104 119 f_label = formatted_label() % widget.label.strip() 105 120 f_label = Paragraph(f_label, style["Normal"]) 106 f_text = formatted_text( ) % widget()121 f_text = formatted_text(widget()) 107 122 f_text = Paragraph(f_text, style["Normal"]) 108 123 data_right.append([f_label,f_text]) … … 120 135 style = getSampleStyleSheet() 121 136 for element in tableheader: 122 field = formatted_text( color='white') % element[0]137 field = formatted_text(element[0], color='white') 123 138 field = Paragraph(field, style["Normal"]) 124 139 line.append(field) … … 127 142 line = [] 128 143 for element in tableheader: 129 field = formatted_text( ) % str(getattr(ticket,element[1],u' '))144 field = formatted_text(getattr(ticket,element[1],u' ')) 130 145 field = Paragraph(field, style["Normal"]) 131 146 line.append(field) … … 261 276 f_label = formatted_label() % widget.label.strip() 262 277 f_label = Paragraph(f_label, style["Normal"]) 263 f_text = formatted_text( ) % str(widget())278 f_text = formatted_text(widget()) 264 279 f_text = Paragraph(f_text, style["Normal"]) 265 280 data.append([f_label,f_text]) … … 291 306 data.append([f_label,doc_img]) 292 307 else: 293 f_text = formatted_text( ) % viewlet.title308 f_text = formatted_text(viewlet.title) 294 309 f_text = Paragraph(f_text, style["Normal"]) 295 310 data.append([f_label,f_text])
Note: See TracChangeset for help on using the changeset viewer.