Exemplo n.º 1
0
    def publish(self, request):
        """ Publishes the issue.

        This ensures that every accepted notice of this issue is published. It
        then creates the PDF while assigning the publications numbers (it uses
        the highest publication number of the last issue of the same year as a
        starting point.

        """

        for notice in self.notices('accepted'):
            notice.publish(request)

        from onegov.gazette.pdf import IssuePdf  # circular
        self.pdf = IssuePdf.from_issue(
            issue=self,
            request=request,
            first_publication_number=self.first_publication_number,
            links=request.app.principal.links)
Exemplo n.º 2
0
def test_issues_pdf_from_issue(gazette_app):
    session = gazette_app.session()
    principal = gazette_app.principal

    for _issues, organization_id, category_id, attachments, meta in (
        ({
            '2017-40': '1',
            '2017-41': '4'
        }, '100', '10', [], None),
        ({
            '2017-40': '2',
            '2017-41': '3'
        }, '200', '10', ['-a-'], {}),
        ({
            '2017-40': '3',
            '2017-41': '2'
        }, '100', '10', [], {
            'print_only': True
        }),
        ({
            '2017-40': '4',
            '2017-41': '1'
        }, '410', '11', ['-c-', '-d-'], {
            'print_only': False
        }),
        ({
            '2017-41': '5',
            '2017-42': '1'
        }, '420', '11', [], {
            'print_only': None
        }),
    ):
        notice = GazetteNotice(title='{}-{}'.format(organization_id,
                                                    category_id),
                               text=', '.join([
                                   '{}-{}'.format(issue, _issues[issue])
                                   for issue in sorted(_issues)
                               ]),
                               _issues=_issues,
                               organization_id=organization_id,
                               category_id=category_id,
                               state='published',
                               meta=meta)
        for content in attachments:
            notice.files.append(pdf_attachment(content))

        session.add(notice)
    session.flush()

    with freeze_time("2017-01-01 12:00"):
        issue = session.query(Issue).filter_by(number=40).one()
        file = IssuePdf.from_issue(issue, DummyRequest(session, principal), 5)
        reader = PdfFileReader(file)
        assert [page.extractText() for page in reader.pages] == [
            # page 1
            'onegov.ch\n© 2017 Govikon\n1\nGazette No. 40, 06.10.2017\n'
            'The electronic official gazette is available at '
            'www.amtsblattzug.ch.\n'
            '1 publication(s) with particularly sensitive data are not '
            'available online. They are available in\npaper form from the '
            'State Chancellery, Seestrasse 2, 6300 Zug, or can be subscribed '
            'to at\[email protected].\n'
            'State Chancellery\n'
            'Complaints\n'
            '5\n100-10\n2017-40-1, 2017-41-4\n'
            '6\nThis official notice is only available in the print version.\n'
            'Civic Community\n'
            'Complaints\n'
            '7\n200-10\n2017-40-2, 2017-41-3\n',
            # page 2 (-a-)
            'Gazette No. 40, 06.10.2017\n© 2017 Govikon\n2\n',
            # page 3
            'Gazette No. 40, 06.10.2017\n© 2017 Govikon\n3\n'
            'Churches\n'
            'Evangelical Reformed Parish\n'
            'Education\n'
            '8\n410-11\n2017-40-4, 2017-41-1\n',
            # page 4 (-c-)
            'Gazette No. 40, 06.10.2017\n© 2017 Govikon\n4\n',
            # page 5 (-d-)
            'Gazette No. 40, 06.10.2017\n© 2017 Govikon\n5\n'
        ]

        issue = session.query(Issue).filter_by(number=41).one()
        file = IssuePdf.from_issue(issue, DummyRequest(session, principal), 5)
        reader = PdfFileReader(file)
        test_issues_pdf_from_issue
        assert [page.extractText() for page in reader.pages] == [
            # page 1
            'onegov.ch\n© 2017 Govikon\n1\nGazette No. 41, 13.10.2017\n'
            'The electronic official gazette is available at '
            'www.amtsblattzug.ch.\n'
            '1 publication(s) with particularly sensitive data are not '
            'available online. They are available in\npaper form from the '
            'State Chancellery, Seestrasse 2, 6300 Zug, or can be subscribed '
            'to at\[email protected].\n'
            'State Chancellery\n'
            'Complaints\n'
            '5\nThis official notice is only available in the print version.\n'
            '6\n100-10\n2017-40-1, 2017-41-4\n'
            'Civic Community\n'
            'Complaints\n'
            '7\n200-10\n2017-40-2, 2017-41-3\n',
            # page 2 (-a-)
            'Gazette No. 41, 13.10.2017\n© 2017 Govikon\n2\n',
            # page 3
            'Gazette No. 41, 13.10.2017\n© 2017 Govikon\n3\n'
            'Churches\n'
            'Evangelical Reformed Parish\n'
            'Education\n'
            '8\n410-11\n2017-40-4, 2017-41-1\n',
            # page 4 (-c-)
            'Gazette No. 41, 13.10.2017\n© 2017 Govikon\n4\n',
            # page 5 (-d-)
            'Gazette No. 41, 13.10.2017\n© 2017 Govikon\n5\n',
            # page 6
            'Gazette No. 41, 13.10.2017\n© 2017 Govikon\n6\n'
            'Sikh Community\n'
            'Education\n'
            '9\n420-11\n2017-41-5, 2017-42-1\n'
        ]

    with freeze_time("2018-01-01 12:00"):
        issue = session.query(Issue).filter_by(number=42).one()
        file = IssuePdf.from_issue(issue, DummyRequest(session, principal), 5)
        reader = PdfFileReader(file)
        test_issues_pdf_from_issue
        assert [page.extractText() for page in reader.pages] == [
            'onegov.ch\n© 2018 Govikon\n1\nGazette No. 42, 20.10.2017\n'
            'The electronic official gazette is available at '
            'www.amtsblattzug.ch.\n'
            'Churches\n'
            'Sikh Community\n'
            'Education\n'
            '5\n420-11\n2017-41-5, 2017-42-1\n'
        ]