Exemplo n.º 1
0
 def render_question(self, question):
     question_type = question.get('type')
     if question_type == 'RadioButton' or question_type == 'Checkbox':
         choices = []
         answer_ids = question.get('answer')
         # RadioButton answers need to be stored as single int to keep edit working
         if answer_ids and question_type == 'RadioButton':
             answer_ids = [answer_ids]
         answers = []
         for idx, choice in enumerate(question.get('choices')):
             choices.append(choice.get('choice_text'))
             if str(choice.get('id')) in answer_ids:
                 answers.append(idx)
         extra = question.get('extra')
         if extra:
             choices.append("<i>{0}</i>: {1}".format(
                 extra.get('extra_text'), extra.get('answer')))
         self.add_multiple_choice(question.get('question_text'),
                                  choices,
                                  answers,
                                  last_is_free_text=bool(extra))
     elif question_type == 'SingleLineText' or question_type == 'Date' or question_type == 'MultiLineText':
         self.add_question(question.get('question_text'))
         answer = question.get('answer').replace(
             '\n', '<br />\n') or '<i>Not answered</i>'
         self.add_answer_list([self.format_answer(answer, self.free_text)],
                              keep_together=False)
     elif question_type == 'FormSet':
         forms = question.get('answers')
         prompt = question.get('prompt').capitalize()
         if forms:
             for idx, form in enumerate(forms):
                 title = prompt
                 if len(forms) > 1:
                     title = title + " " + str(idx + 1)
                 self.add_question(title)
                 self.pdf_elements.append(Indenter(left=12))
                 for q in form:
                     self.render_question(q)
                 self.pdf_elements.append(Indenter(left=-12))
         else:
             self.add_question(prompt)
             self.pdf_elements.append(Indenter(left=12))
             self.add_question('<i>None added</i>')
             self.pdf_elements.append(Indenter(left=-12))
Exemplo n.º 2
0
 def test1(self):
     '''Ilpo Nyyss\xf6nen posted this broken test'''
     normalStyle = ParagraphStyle(name='normal')
     keepStyle = ParagraphStyle(name='keep', keepWithNext=True)
     content = [
         Paragraph("line 1", keepStyle),
         Indenter(left=1 * cm),
         Paragraph("line 2", normalStyle),
     ]
     doc = SimpleDocTemplate(outputfile('test_platypus_breaking1.pdf'))
     doc.build(content)
Exemplo n.º 3
0
def go():
        Story=[]
        ts=TableStyle([('GRID',(0,0),(-1,-1),0.25,"black"),
                      ('BOX',(0,0),(-1,-1),0.25,"black")]
                     )
        styles = getSampleStyleSheet()
        doc = SimpleDocTemplate("phello.pdf")
        
        cell=[Paragraph('This is not indented',styles['Normal']),
              Indenter(100,100),
              Paragraph('This should be indented',styles['Normal'])]
        
        Story=cell+[Table([[cell]],style=ts)]
        doc.build(Story)
Exemplo n.º 4
0
    def test0(self):
        "This makes one long multi-page paragraph."

        # Build story.
        story = []

        styleSheet = getSampleStyleSheet()
        h1 = styleSheet['Heading1']
        h1.spaceBefore = 18
        bt = styleSheet['BodyText']
        bt.spaceBefore = 6

        story.append(Paragraph('Test of context-relative indentation', h1))

        story.append(Spacer(18, 18))

        story.append(Indenter(0, 0))
        story.append(
            Paragraph(
                "This should be indented 0 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(0, 0))

        story.append(Indenter(36, 0))
        story.append(
            Paragraph(
                "This should be indented 36 points at the left. " +
                ("spam " * 25), bt))
        story.append(Indenter(-36, 0))

        story.append(Indenter(0, 36))
        story.append(
            Paragraph(
                "This should be indented 36 points at the right. " +
                ("spam " * 25), bt))
        story.append(Indenter(0, -36))

        story.append(Indenter(36, 36))
        story.append(
            Paragraph(
                "This should be indented 36 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(36, 36))
        story.append(
            Paragraph(
                "This should be indented a FURTHER 36 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(-72, -72))

        story.append(
            Paragraph(
                "This should be back to normal at each edge. " +
                ("spam " * 25), bt))

        story.append(Indenter(36, 36))
        story.append(
            Paragraph(("""This should be indented 36 points at the left
        and right.  It should run over more than one page and the indent should
        continue on the next page. """ + (random.randint(0, 10) * 'x') + ' ') *
                      20, bt))
        story.append(Indenter(-36, -36))

        story.append(NextPageTemplate('updown'))
        story.append(FrameBreak())
        story.append(
            Paragraph('Another test of context-relative indentation', h1))
        story.append(NextPageTemplate(
            'normal'))  # so NEXT page is different template...
        story.append(
            Paragraph(
                """This time we see if the indent level is continued across
            frames...this page has 2 frames, let's see if it carries top to bottom. Then
            onto a totally different template.""", bt))

        story.append(Indenter(0, 0))
        story.append(
            Paragraph(
                "This should be indented 0 points at each edge. " +
                ("spam " * 25), bt))
        story.append(Indenter(0, 0))
        story.append(Indenter(36, 72))
        story.append(
            Paragraph(("""This should be indented 36 points at the left
        and 72 at the right.  It should run over more than one frame and one page, and the indent should
        continue on the next page. """ + (random.randint(0, 10) * 'x') + ' ') *
                      35, bt))

        story.append(Indenter(-36, -72))
        story.append(
            Paragraph(
                "This should be back to normal at each edge. " +
                ("spam " * 25), bt))
        doc = MyDocTemplate(outputfile('test_platypus_indents.pdf'))
        doc.multiBuild(story)
Exemplo n.º 5
0
    def test0(self):
        "IndentTestCase test0"
        if rl_invariant: random.seed(1479316371)

        # Build story.
        story = []
        doc = MyDocTemplate(outputfile('test_platypus_indents.pdf'))
        storyAdd = story.append

        styleSheet = getSampleStyleSheet()
        h1 = styleSheet['Heading1']
        h1.spaceBefore = 18
        bt = styleSheet['BodyText']
        bt.spaceBefore = 6

        storyAdd(Paragraph('Test of context-relative indentation', h1))

        storyAdd(Spacer(18, 18))

        storyAdd(Indenter(0, 0))
        storyAdd(
            Paragraph(
                "This should be indented 0 points at each edge. " +
                ("spam " * 25), bt))
        storyAdd(Indenter(0, 0))

        storyAdd(Indenter(36, 0))
        storyAdd(
            Paragraph(
                "This should be indented 36 points at the left. " +
                ("spam " * 25), bt))
        storyAdd(Indenter(-36, 0))

        storyAdd(Indenter(0, 36))
        storyAdd(
            Paragraph(
                "This should be indented 36 points at the right. " +
                ("spam " * 25), bt))
        storyAdd(Indenter(0, -36))

        storyAdd(Indenter(36, 36))
        storyAdd(
            Paragraph(
                "This should be indented 36 points at each edge. " +
                ("spam " * 25), bt))
        storyAdd(Indenter(36, 36))
        storyAdd(
            Paragraph(
                "This should be indented a FURTHER 36 points at each edge. " +
                ("spam " * 25), bt))
        storyAdd(Indenter(-72, -72))

        storyAdd(
            Paragraph(
                "This should be back to normal at each edge. " +
                ("spam " * 25), bt))

        storyAdd(Indenter(36, 36))
        storyAdd(
            Paragraph(("""This should be indented 36 points at the left
        and right.  It should run over more than one page and the indent should
        continue on the next page. """ + (random.randint(0, 10) * 'x') + ' ') *
                      20, bt))
        storyAdd(Indenter(-36, -36))

        storyAdd(NextPageTemplate('updown'))
        storyAdd(FrameBreak())
        storyAdd(Paragraph('Another test of context-relative indentation', h1))
        storyAdd(NextPageTemplate(
            'normal'))  # so NEXT page is different template...
        storyAdd(
            Paragraph(
                """This time we see if the indent level is continued across
            frames...this page has 2 frames, let's see if it carries top to bottom. Then
            onto a totally different template.""", bt))

        storyAdd(Indenter(0, 0))
        storyAdd(
            Paragraph(
                "This should be indented 0 points at each edge. " +
                ("spam " * 25), bt))
        storyAdd(Indenter(0, 0))
        storyAdd(Indenter(36, 72))
        storyAdd(
            Paragraph(("""This should be indented 36 points at the left
        and 72 at the right.  It should run over more than one frame and one page, and the indent should
        continue on the next page. """ + (random.randint(0, 10) * 'x') + ' ') *
                      35, bt))

        storyAdd(Indenter(-36, -72))
        storyAdd(
            Paragraph(
                "This should be back to normal at each edge. " +
                ("spam " * 25), bt))
        storyAdd(PageBreak())

        storyAdd(PageBreak())
        storyAdd(
            Paragraph(
                "Below we should colour the background lightgreen and have a red border",
                bt))
        storyAdd(
            FrameBG(start=True,
                    color=lightgreen,
                    strokeColor=toColor('red'),
                    strokeWidth=1))
        storyAdd(Paragraph("We should have a light green background here", bt))
        storyAdd(Paragraph("We should have a light green background here", bt))
        storyAdd(Paragraph("We should have a light green background here", bt))
        storyAdd(Spacer(6, 6))
        storyAdd(FrameBG(start=False))

        storyAdd(
            Paragraph("Below we should colour the background lightgreen", bt))
        storyAdd(
            FrameBG(start=True,
                    color=lightgreen,
                    strokeColor=toColor('red'),
                    strokeWidth=None))
        storyAdd(Paragraph("We should have a light green background here", bt))
        storyAdd(Paragraph("We should have a light green background here", bt))
        storyAdd(Paragraph("We should have a light green background here", bt))
        storyAdd(Spacer(6, 6))
        storyAdd(FrameBG(start=False))

        storyAdd(
            Paragraph(
                "Below we split to two new frames with dark green borders",
                bt))
        storyAdd(FrameSplitter('templateX', ['XF4', 'XF5'],
                               adjustHeight=False))
        storyAdd(
            FrameBG(start=True,
                    color=lightgreen,
                    strokeColor=toColor('red'),
                    strokeWidth=1))
        for i in range(15):
            storyAdd(
                Paragraph(
                    "We should have a light green background here %d" % i, bt))
        storyAdd(Spacer(6, 6))
        storyAdd(FrameBG(start=False))
        storyAdd(NextPageTemplate('normal'))

        storyAdd(PageBreak())
        storyAdd(
            Paragraph("Below we should colour the background lightgreen", bt))
        storyAdd(FrameBG(start="frame", color=lightgreen))
        storyAdd(Paragraph("We should have a light green background here", bt))

        storyAdd(PageBreak())
        storyAdd(Paragraph("Here we should have no background.", bt))

        storyAdd(PageBreak())
        storyAdd(FrameBG(start="frame", color=lightblue))
        storyAdd(
            Paragraph(
                "We should have a light blue background here and the whole frame should be filled in.",
                bt))

        storyAdd(PageBreak())
        storyAdd(Paragraph("Here we should have no background again.", bt))

        storyAdd(
            Paragraph("Below we should colour the background lightgreen", bt))
        storyAdd(FrameBG(start="frame-permanent", color=lightgreen))
        storyAdd(Paragraph("We should have a light green background here", bt))

        storyAdd(PageBreak())
        storyAdd(
            Paragraph("Here we should still have a lightgreen background.",
                      bt))

        storyAdd(PageBreak())
        storyAdd(FrameBG(start="frame", color=lightblue, left=36, right=36))
        storyAdd(
            Paragraph("We should have a lighgreen/lightblue background.", bt))

        storyAdd(PageBreak())
        storyAdd(
            Paragraph("Here we should have only light green background.", bt))

        doc.multiBuild(story)
Exemplo n.º 6
0
    fontSize=12,
    fontName="lato_black",
    # fontName = Helvetica,
)

style5a = ParagraphStyle(
    name="Normal",
    spaceAfter=5,
    spaceBefore=5,
    fontSize=12,
    fontName="lato_black",
)

# ts1 = [('LEFTMARGIN', (0,0), (-1, -1), 15)]

elements.append(Indenter(left=15, right=15))

questions = data["data"]["questions"]
count = 1
for a in questions:
    # rfi = []
    print(a)
    texta = Paragraph('''<b>Question{}:</b>'''.format(count), style=style5a)
    # qu = str(texta1)+str(count)+":"
    # texta = Paragraph(texta1, style=styles["Normal"])
    # elements.append(texta)
    question_date = a["question"]["createdAt"].split("T")
    questiondate = question_date[0]
    textb = Paragraph(questiondate, style=styles["Normal"])
    # elements.append(textb)
    question_msg = a["question"]["questionMsg"]