Beispiel #1
0
def view_notices_statistics_xlsx(self, request):
    """ View the statistics as XLSX. """

    output = BytesIO()
    workbook = Workbook(output)
    for title, row, content in (
        (_("Organizations"), _("Organization"), self.count_by_organization),
        (_("Categories"), _("Category"), self.count_by_category),
        (_("Groups"), _("Group"), self.count_by_group),
        (_("Rejected"), _("Name"), self.count_rejected),
    ):
        worksheet = workbook.add_worksheet()
        worksheet.name = request.translate(title)
        worksheet.write_row(0, 0, (
            request.translate(row),
            request.translate(_("Count"))
        ))
        for index, row in enumerate(content()):
            worksheet.write_row(index + 1, 0, row)
    workbook.close()
    output.seek(0)

    response = Response()
    response.content_type = (
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    )
    response.content_disposition = 'inline; filename={}-{}-{}.xlsx'.format(
        request.translate(_("Statistics")).lower(),
        normalize_for_url(request.translate(TRANSLATIONS.get(self.state, ''))),
        datetime.utcnow().strftime('%Y%m%d%H%M')
    )
    response.body = output.read()

    return response
Beispiel #2
0
def print_only_pdf(self, request):
    """ Creates the PDF with all the print only notices of an issue. """

    response = Response()
    response.content_type = 'application/pdf'
    response.content_disposition = 'inline; filename={}-{}.pdf'.format(
        self.name,
        request.translate(_("Print only")).lower().replace(' ', '-')
    )
    response.body = IssuePrintOnlyPdf.from_issue(self, request).read()
    return response
Beispiel #3
0
def export_issue(self, request):
    """ Export all issues as XLSX. The exported file can be re-imported
    using the import-issues command line command.

    """

    output = BytesIO()
    workbook = Workbook(output, {
        'default_date_format': 'dd.mm.yy'
    })
    datetime_format = workbook.add_format({'num_format': 'dd.mm.yy hh:mm'})

    worksheet = workbook.add_worksheet()
    worksheet.name = request.translate(_("Issues"))
    worksheet.write_row(0, 0, (
        request.translate(_("Year")),
        request.translate(_("Number")),
        request.translate(_("Date")),
        request.translate(_("Deadline"))
    ))

    timezone = request.app.principal.time_zone
    for index, issue in enumerate(self.query()):
        worksheet.write(index + 1, 0, issue.date.year)
        worksheet.write(index + 1, 1, issue.number)
        worksheet.write(index + 1, 2, issue.date)
        worksheet.write_datetime(
            index + 1, 3,
            to_timezone(issue.deadline, timezone).replace(tzinfo=None),
            datetime_format
        )

    workbook.close()
    output.seek(0)

    response = Response()
    response.content_type = (
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    )
    response.content_disposition = 'inline; filename={}-{}.xlsx'.format(
        request.translate(_("Issues")).lower(),
        datetime.utcnow().strftime('%Y%m%d%H%M')
    )
    response.body = output.read()

    return response
Beispiel #4
0
def export_organizations(self, request):
    """ Export all organizations as XLSX. The exported file can be re-imported
    using the import-organizations command line command.

    """

    output = BytesIO()
    workbook = Workbook(output)

    worksheet = workbook.add_worksheet()
    worksheet.name = request.translate(_("Organizations"))
    worksheet.write_row(
        0, 0, (request.translate(_("ID")), request.translate(_("Name")),
               request.translate(_("Title")), request.translate(
                   _("Active")), request.translate(_("External ID")),
               request.translate(_("Parent Organization"))))

    index = 0
    for root in self.roots:
        index += 1
        worksheet.write_row(
            index, 0,
            (root.id or '', root.name or '', root.title or '', root.active,
             root.external_name or '', root.parent_id or ''))
        for organization in root.children:
            index += 1
            worksheet.write_row(
                index, 0,
                (organization.id or '', organization.name
                 or '', organization.title
                 or '', organization.active, organization.external_name
                 or '', organization.parent_id or ''))

    workbook.close()
    output.seek(0)

    response = Response()
    response.content_type = (
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    response.content_disposition = 'inline; filename={}-{}.xlsx'.format(
        request.translate(_("Organizations")).lower(),
        datetime.utcnow().strftime('%Y%m%d%H%M'))
    response.body = output.read()

    return response
Beispiel #5
0
def export_categories(self, request):
    """ Export all categories as XLSX. The exported file can be re-imported
    using the import-categories command line command.

    """

    output = BytesIO()
    workbook = Workbook(output)

    worksheet = workbook.add_worksheet()
    worksheet.name = request.translate(_("Categories"))
    worksheet.write_row(0, 0, (
        request.translate(_("ID")),
        request.translate(_("Name")),
        request.translate(_("Title")),
        request.translate(_("Active"))
    ))

    for index, category in enumerate(self.query()):
        worksheet.write_row(index + 1, 0, (
            category.id or '',
            category.name or '',
            category.title or '',
            category.active,
        ))

    workbook.close()
    output.seek(0)

    response = Response()
    response.content_type = (
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    )
    response.content_disposition = 'inline; filename={}-{}.xlsx'.format(
        request.translate(_("Categories")).lower(),
        datetime.utcnow().strftime('%Y%m%d%H%M')
    )
    response.body = output.read()

    return response
Beispiel #6
0
def export_users(self, request):
    """ Export all users as XLSX. The exported file can be re-imported
    using the import-editors command line command.

    """
    output = BytesIO()
    workbook = Workbook(output)

    for role, name in (('member', request.translate(_("Editors"))),
                       ('editor', request.translate(_("Publishers")))):
        worksheet = workbook.add_worksheet()
        worksheet.name = name
        worksheet.write_row(
            0, 0, (request.translate(_("Group")), request.translate(
                _("Name")), request.translate(_("E-Mail"))))

        editors = self.query().filter(User.role == role)
        editors = editors.join(User.group, isouter=True)
        editors = editors.order_by(UserGroup.name, User.realname,
                                   User.username)
        for index, editor in enumerate(editors.all()):
            worksheet.write_row(index + 1, 0,
                                (editor.group.name if editor.group else '',
                                 editor.realname or '', editor.username or ''))

    workbook.close()
    output.seek(0)

    response = Response()
    response.content_type = (
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
    response.content_disposition = 'inline; filename={}-{}.xlsx'.format(
        request.translate(_("Users")).lower(),
        datetime.utcnow().strftime('%Y%m%d%H%M'))
    response.body = output.read()

    return response