def addConsultationBox(self, section, document): """ Add the consultation box that needs to be signed by the employer and workers. """ ss = document.StyleSheet styles = document.StyleSheet.ParagraphStyles thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE) t = lambda txt: "".join([ "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request) ]) table = Table(9500) thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE) no_edge = BorderPropertySet(width=0, colour=ss.Colours.White) p = Paragraph( styles.Heading3, ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER), t( _("header_oira_report_consultation", default="Consultation of workers"))) c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge)) table.AddRow(c) p = Paragraph( styles.Normal, ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT), t( _("paragraph_oira_consultation_of_workers", default="The undersigned hereby declare that the workers " "have been consulted on the content of this " "document.")), LINE) c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge)) table.AddRow(c) p = Paragraph( styles.Normal, ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT), ) employer = t( _("oira_consultation_employer", default="On behalf of the employer:")) workers = t( _("oira_consultation_workers", default="On behalf of the workers:")) p.append(employer, TAB, TAB, TAB, TAB, workers, LINE, LINE) c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge)) table.AddRow(c) p = Paragraph( ParagraphPropertySet(alignment=ParagraphPropertySet.LEFT), t(_("oira_survey_date", default="Date:")), LINE, LINE) c = Cell(p, FramePropertySet(no_edge, thin_edge, thin_edge, thin_edge)) table.AddRow(c) section.append(table)
def make_tableMarginInCell(): doc, section, styles = RTFTestCase.initializeDoc() cell_margins0 = MarginsPropertySet(top=0, right=0, bottom=0, left=0) cell_margins1 = MarginsPropertySet(top=500, right=500, bottom=500, left=500) cell_margins2 = MarginsPropertySet(top=1000, right=1000, bottom=1000, left=1000) section.append('Table with Margin in Cells') table = Table(TableTestCase.col1, TableTestCase.col2, TableTestCase.col3) table.AddRow(Cell(cell_margins0, 'Marign 0'), Cell( cell_margins1, 'Margin 500', ), Cell(cell_margins2, 'Margin 1000')) table.AddRow(Cell(cell_margins0, 'Marign 0'), Cell( cell_margins1, 'Margin 500', ), Cell(cell_margins2, 'Margin 1000')) table.AddRow(Cell(cell_margins0, 'Marign 0'), Cell( cell_margins1, 'Margin 500', ), Cell(cell_margins2, 'Margin 1000')) section.append(table) return doc
def createSection(document, survey, request, first_page_number=1): t = lambda txt: "".join( ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)]) section = Section(break_type=Section.PAGE, first_page_number=first_page_number) footer_txt = t( _("report_survey_revision", default=u"This report was based on the OiRA Tool '${title}' "\ u"of revision date ${date}.", mapping={"title": survey.published[1], "date": formatDate(request, survey.published[2])})) header = Table(4750, 4750) c1 = Cell( Paragraph(document.StyleSheet.ParagraphStyles.Footer, survey.published[1])) pp = ParagraphPropertySet header_props = pp(alignment=pp.RIGHT) c2 = Cell( Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props, formatDate(request, datetime.today()))) header.AddRow(c1, c2) section.Header.append(header) footer = Table(9000, 500) # rtfng does not like unicode footers c1 = Cell( Paragraph(document.StyleSheet.ParagraphStyles.Footer, pp(alignment=pp.LEFT), footer_txt)) c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER)) footer.AddRow(c1, c2) section.Footer.append(footer) document.Sections.append(section) return section
def createIdentificationReportSection(document, survey, request): t = lambda txt: "".join( ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)]) section = Section() footer_txt = t( _("report_identification_revision", default=u"This document was based on the OiRA Tool '${title}' of " u"revision date ${date}.", mapping={ "title": survey.published[1], "date": formatDate(request, survey.published[2]) })) header = Table(4750, 4750) c1 = Cell( Paragraph(document.StyleSheet.ParagraphStyles.Footer, SessionManager.session.title)) pp = ParagraphPropertySet header_props = pp(alignment=pp.RIGHT) c2 = Cell( Paragraph(document.StyleSheet.ParagraphStyles.Footer, header_props, formatDate(request, datetime.today()))) header.AddRow(c1, c2) section.Header.append(header) footer = Table(9000, 500) c1 = Cell( Paragraph(document.StyleSheet.ParagraphStyles.Footer, pp(alignment=pp.LEFT), footer_txt)) c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER)) footer.AddRow(c1, c2) section.Footer.append(footer) section.SetBreakType(section.PAGE) document.Sections.append(section) return section
def test_tableAddRow(self): table = Table(1000) self.assertRaises(Exception, table.AddRow) # no params at all table.AddRow(Cell('1')) # one cell, ok self.assertRaises(Exception, table.AddRow, Cell('1'), Cell('1')) # 2 cells, error self.assertRaises(Exception, table.AddRow, 1) # height but no cell, error table.AddRow(1, Cell('1')) # height plus one cell, ok self.assertRaises(Exception, table.AddRow, 1, Cell('1'), Cell('1')) # height with 2 cells, error
def test_tableAddRow(self): table = Table(1000) with pytest.raises(Exception): table.AddRow() # no params at all table.AddRow(Cell('1')) # one cell, ok with pytest.raises(Exception): table.AddRow(Cell('1'), Cell('1')) # 2 cells, error with pytest.raises(Exception): table.AddRow(1) # height but no cell, error table.AddRow(1, Cell('1')) # height plus one cell, ok with pytest.raises(Exception): table.AddRow(1, Cell('1'), Cell('1')) # height with 2 cells, error
def test_cell(self): cell = Cell('one') cell = Cell( MarginsPropertySet(top=1000, left=1200, bottom=1000, right=1200), 'one')
p.append('PHS 398/2590 (Rev. 06/09)', TAB, 'Page ', PAGE_NUMBER, TAB, "Biographical Sketch Format Page") section.Footer.append(p) # Put in the top table table = Table(5310, 270, 1170, 1440, 2610) p1 = Paragraph(ss.ParagraphStyles.Title, "BIOGRAPHICAL SKETCH") p2 = Paragraph(ss.ParagraphStyles.Subtitle) p2.append('Provide the following information for the Senior/key personnel ' \ 'and other significant contributors in the order listed on Form Page 2.') p3 = Paragraph(ss.ParagraphStyles.Subtitle) p3.append("Follow this format for each person. ", B("DO NOT EXCEED FOUR PAGES.")) c = Cell(p1, p2, p3, topBottom, span=5) table.AddRow(c) c = Cell(Paragraph(ss.ParagraphStyles.Subtitle, ' '), bottom_frame, span=5) table.AddRow(c) p1 = Paragraph(ss.ParagraphStyles.SubtitleLeft, 'NAME') p2 = Paragraph(ss.ParagraphStyles.Normal, person['first_name'], ' ', person['last_name']) c1 = Cell(p1, p2, bottom_right_frame, span=2) c2 = Cell(Paragraph(ss.ParagraphStyles.SubtitleLeft, 'POSITION TITLE'), span=3) table.AddRow(c1, c2) p1 = Paragraph(ss.ParagraphStyles.SubtitleLeft, 'eRA COMMONS USER NAME (credential, e.g., agency login)') p2 = Paragraph(ss.ParagraphStyles.Normal, person['era_commons'])
def generateReport(window, plot, evals, lagranges): """Save session report to rtf document """ fileName = Qt.QFileDialog.getSaveFileName(window, u'Сохранить отчет', '.', 'Word (*.doc)') if not fileName.isNull(): doc = Document() #ss = doc.StyleSheet section = Section() doc.Sections.append(section) minX, maxX, minY, maxY = plot.getBounds() section.append(u'Полотно растеризации:') section.append('') table = Table(TabPropertySet.DEFAULT_WIDTH, \ TabPropertySet.DEFAULT_WIDTH * 3, \ TabPropertySet.DEFAULT_WIDTH * 3) table.AddRow(Cell(Paragraph(u'ось')), Cell(Paragraph(u'от')), Cell(Paragraph(u'до'))) table.AddRow(Cell(Paragraph('x')), Cell(Paragraph(str(minX))), Cell(Paragraph(str(maxX)))) table.AddRow(Cell(Paragraph('y')), Cell(Paragraph(str(minY))), Cell(Paragraph(str(maxY)))) section.append(table) section.append(u'Детализация: %d %s на график' % (plot.width(), langMorph(plot.width(), (u'точек', u'точка', u'точки')))) section.append(Paragraph(getPlotImage(plot))) section.append('') section.append(u'%d %s:' % (len(evals), langMorph(len(evals), (u'функций', u'функция', u'функции')))) #for s in evals: # section.append('f(x) = %s' % s) for i in evals: section.append('f(x) = %s' % i.getExpression()) section.append('') section.append(u'%d %s Лагранжа' % (len(lagranges), langMorph(len(lagranges), (u'полиномов', u'полином', u'полинома')))) for i in lagranges: points = i.count() section.append(ur'\u2014' * 30) section.append( u'%d %s:' % (points, langMorph(points, (u'точек', u'точка', u'точки')))) table = Table(TabPropertySet.DEFAULT_WIDTH / 2, \ TabPropertySet.DEFAULT_WIDTH * 3, \ TabPropertySet.DEFAULT_WIDTH * 3) for j in xrange(points): table.AddRow(Cell(Paragraph('%d' % j)), Cell(Paragraph('%g' % i.pointX[j])), Cell(Paragraph('%g' % i.pointY[j]))) section.append(table) section.append(u'L(x) = %s' % i.toString()) Renderer().Write(doc, file(unicode(fileName), 'w'))
def addMeasure(self, document, heading, section, measure): """ Requirements for how the measure section should be displayed are in #2611 """ t = lambda txt: "".join([ "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request) ]) ss = document.StyleSheet styles = ss.ParagraphStyles table = Table(9500) thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE) no_edge = BorderPropertySet(width=0, colour=ss.Colours.White) p = Paragraph(styles.MeasureHeading, ParagraphPropertySet(left_indent=300, right_indent=300), t(_("header_measure_single", default=u"Measure"))) c = Cell(p, FramePropertySet(thin_edge, thin_edge, no_edge, thin_edge)) table.AddRow(c) ss = document.StyleSheet styles = document.StyleSheet.ParagraphStyles headings = [ t( _("label_measure_action_plan", default=u"General approach (to " u"eliminate or reduce the risk)")), t( _("label_measure_prevention_plan", default=u"Specific action(s) " u"required to implement this approach")), t( _("label_measure_requirements", default=u"Level of expertise " u"and/or requirements needed")), t( _("label_action_plan_responsible", default=u"Who is " u"responsible?")), t(_("label_action_plan_budget", default=u"Budget")), t(_("label_action_plan_start", default=u"Planning start")), t(_("label_action_plan_end", default=u"Planning end")), ] m = measure values = [ m.action_plan, m.prevention_plan, m.requirements, m.responsible, m.budget and str(m.budget) or '', m.planning_start and formatDate(self.request, m.planning_start) or '', m.planning_end and formatDate(self.request, m.planning_end) or '', ] for heading, value in zip(headings, values): p = Paragraph(styles.MeasureField, heading) c = Cell(p, FramePropertySet(no_edge, thin_edge, no_edge, thin_edge)) table.AddRow(c) if headings.index(heading) == len(headings) - 1: frame = FramePropertySet(no_edge, thin_edge, thin_edge, thin_edge) else: frame = FramePropertySet(no_edge, thin_edge, no_edge, thin_edge) p = Paragraph( styles.Normal, ParagraphPropertySet(left_indent=600, right_indent=600), value) c = Cell(p, frame) table.AddRow(c) section.append(table)
def createItalianIntro(document, survey, request): t = lambda txt: "".join( ["\u%s?" % str(ord(e)) for e in translate(txt, context=request)]) ss = document.StyleSheet pp = ParagraphPropertySet section = Section(break_type=Section.PAGE, first_page_number=1) footer_txt = t( u"1) Il documento deve essere munito di “data certa” o attestata dalla " "sottoscrizione del documento, ai soli fini della prova della data, " "da parte del RSPP, RLS o RLST, e del medico competente, ove nominato. In " "assenza di MC o RLS o RLST, la data certa va documentata con PEC o altra " "forma prevista dalla legge.") section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append( Paragraph( ss.ParagraphStyles.ITTitle, pp(alignment=pp.CENTER), t(u"Azienda ....................."), )) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) dots = u"……………………………………" section.append( Paragraph( ss.ParagraphStyles.ITSubtitle, pp(alignment=pp.CENTER), t(u"DOCUMENTO DI VALUTAZIONE DEI RISCHI"), )) section.append(Paragraph(LINE)) section.append( Paragraph( ss.ParagraphStyles.ITSubSubtitle, pp(alignment=pp.CENTER), t(u"(artt. 17, 28 D.Lgs. 81/08)"), )) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) section.append(Paragraph(LINE)) data1 = Table(4750, 4750) c1 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(u"Data (1), {}".format(dots)))) c2 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(u""))) data1.AddRow(c1, c2) c1 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(u"Datore di lavoro:"))) c2 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(dots))) data1.AddRow(c1, c2) section.append(data1) section.append(Paragraph(LINE)) section.append( Paragraph( ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.CENTER), t(u"Se necessario, ai soli fini della prova della data:"), )) section.append(Paragraph(LINE)) data2 = Table(4750, 4750) c1 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(u"RSPP"))) c2 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(dots))) data2.AddRow(c1, c2) c1 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(u"Medico Competente (ove nominato)"))) c2 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(dots))) data2.AddRow(c1, c2) c1 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(u"RLS/RLST"))) c2 = Cell( Paragraph(ss.ParagraphStyles.ITNormalBold, pp(alignment=pp.LEFT), t(dots))) data2.AddRow(c1, c2) section.append(data2) footer = Table(9500) # rtfng does not like unicode footers c1 = Cell( Paragraph(ss.ParagraphStyles.Footer, pp(alignment=pp.LEFT), footer_txt)) # c2 = Cell(Paragraph(pp(alignment=pp.RIGHT), PAGE_NUMBER)) footer.AddRow(c1) section.Footer.append(footer) document.Sections.append(section) return section