Changeset 8091 for main/waeup.kofa/trunk/src/waeup/kofa/applicants/pdf.py
- Timestamp:
- 10 Apr 2012, 10:43:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/applicants/pdf.py
r8059 r8091 56 56 ar_translation, self.context.application_number) 57 57 58 def _setUpWidgets(self):59 """Setup simple display widgets.60 61 Returns the list of widgets.62 """63 request = TestRequest()64 return setUpEditWidgets(65 self.form_fields, 'form', self.context, request, {},66 for_display=True, ignore_request=True67 )68 69 58 def _getCourseAdmittedLink(self, view): 70 59 """Return link, title and code in html format to the certificate … … 79 68 return '' 80 69 81 def _ addPassportImage(self, data):82 """ Add passport image to data stream.70 def _getDeptAndFaculty(self): 71 """Return long titles of department and faculty. 83 72 84 If no image exists yet the default image is added. 73 Returns a list [department_title, faculty_title] 74 75 If the context applicant has no course admitted or dept. and 76 faculty cannot be determined, ``None`` is returned. 85 77 """ 86 img = getUtility(IExtFileStore).getFileByContext(self.context)87 if img is None:88 img = open(DEFAULT_PASSPORT_IMAGE_PATH, 'rb')89 doc_img = Image(img.name, width=4*cm, height=3*cm, kind='bound')90 data.append([doc_img])91 data.append([Spacer(1, 18)])92 return data93 94 def _addDeptAndFaculty(self, data):95 """If we have a valid course admitted, add dept. and faculty to data96 stream.97 """98 style = getSampleStyleSheet()99 78 course_admitted = self.context.course_admitted 100 79 dept = getattr( 101 80 getattr(course_admitted, '__parent__', None), 102 81 '__parent__', None) 103 if dept is None:104 return data105 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE106 dp_translation = translate(_('Department:'),107 'waeup.kofa', target_language=portal_language)108 f_label = '<font size=12>%s</font>' % dp_translation109 f_text = '<font size=12>%s</font>' % dept.longtitle()110 f_label = Paragraph(f_label, style["Normal"])111 f_text = Paragraph(f_text, style["Normal"])112 data.append([f_label,f_text])113 114 82 faculty = getattr(dept, '__parent__', None) 115 if faculty is None: 116 return data 117 fc_translation = translate(_('Faculty:'), 118 'waeup.kofa', target_language=portal_language) 119 f_label = '<font size=12>%s</font>' % fc_translation 120 f_text = '<font size=12>%s</font>' % faculty.longtitle() 121 f_label = Paragraph(f_label, style["Normal"]) 122 f_text = Paragraph(f_text, style["Normal"]) 123 data.append([f_label,f_text]) 124 return data 125 126 def _getWidgetsTable(self, view): 127 """Return a reportlab table buildt of widgets. 128 """ 129 style = getSampleStyleSheet() 130 table_data = [] 131 table_style = [('LEFTPADDING', (0,0), (0,-1), 0), 132 ('VALIGN', (0,0), (-1,-1), 'TOP'), 133 ] 134 row_num = 0 135 widgets = self._setUpWidgets() 136 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 137 for widget in widgets: 138 separators = getUtility(IApplicantsUtils).SEPARATORS_DICT 139 if separators and separators.get(widget.name): 140 f_headline = ('<font size=12><strong>%s</strong></font>' 141 % translate(separators[widget.name], 'waeup.kofa', 142 target_language=portal_language)) 143 f_headline = Paragraph(f_headline, style["Normal"]) 144 table_data.append([f_headline ]) 145 table_style.append(('SPAN', (0,row_num), (-1,row_num)),) 146 table_style.append( 147 ('TOPPADDING', (0,row_num), (-1,row_num), 12),) 148 row_num += 1 149 f_label = '<font size=12>%s</font>:' % translate( 150 widget.label.strip(), 'waeup.kofa', 151 target_language=portal_language) 152 f_label = Paragraph(f_label, style["Normal"]) 153 f_text = '<font size=12>%s</font>' % widget() 154 # Add br tag if widgets contain div tags 155 # which are not supported by reportlab 156 f_text = f_text.replace('</div>', '</div><br />') 157 f_text = f_text.replace('\n', '') 158 f_text = Paragraph(f_text, style["Normal"]) 159 table_data.append([f_label,f_text]) 160 row_num += 1 161 adm_translation = translate(_('Admitted Course of Study:'), 162 'waeup.kofa', target_language=portal_language) 163 f_label = '<font size=12>%s</font>' % adm_translation 164 f_text = '<font size=12>%s</font>' % ( 165 self._getCourseAdmittedLink(view),) 166 f_label = Paragraph(f_label, style["Normal"]) 167 f_text = Paragraph(f_text, style["Normal"]) 168 table_data.append([f_label,f_text]) 169 row_num += 1 170 171 # Add dept. and faculty if applicable 172 table_data = self._addDeptAndFaculty(table_data) 173 174 # Create table 175 table = Table(table_data,style=table_style) 176 table.hAlign = 'LEFT' 177 return table 83 return [x is not None and x.longtitle() or x for x in dept, faculty] 178 84 179 85 def _addComments(self, data): … … 205 111 principal. 206 112 """ 207 doc_title = self.title.replace('-', '\n')113 doc_title = '\n'.join([x.strip() for x in self.title.split('-')]) 208 114 style = getSampleStyleSheet() 209 115 data = [] 116 portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE 117 separators = getUtility(IApplicantsUtils).SEPARATORS_DICT 118 creator = getUtility(IPDFCreator) 210 119 211 120 # append history 212 for msg in self.context.history.messages: 213 f_msg = '<font face="Courier" size=10>%s</font>' % msg 214 data.append(Paragraph(f_msg, style["Normal"])) 215 data.append(Spacer(1, 20)) 121 data.extend(creator.fromStringList(self.context.history.messages)) 216 122 217 123 # append photograph … … 219 125 getUtility(IExtFileStore).getFileByContext(self.context), 220 126 'name', DEFAULT_PASSPORT_IMAGE_PATH) 221 doc_img = Image(img_path, width=4*cm, height=3*cm, kind='bound') 222 doc_img.hAlign='LEFT' 223 data.append(doc_img) 127 data.append(creator.getImage(img_path)) 128 data.append(Spacer(1, 12)) 224 129 225 130 # append widgets 226 data.append(self._getWidgetsTable(view)) 131 dept, faculty = self._getDeptAndFaculty() 132 data.append(creator.getWidgetsTable( 133 self.form_fields, self.context, view, lang=portal_language, 134 domain='waeup.kofa', separators=separators, 135 course_label='Admitted Course of Study:', 136 course_link=self._getCourseAdmittedLink(view), 137 dept=dept, faculty=faculty)) 227 138 228 139 # append comments 229 140 data = self._addComments(data) 230 231 creator = getUtility(IPDFCreator)232 141 return creator.create_pdf(data, None, doc_title)
Note: See TracChangeset for help on using the changeset viewer.