Пример #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
Пример #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
Пример #3
0
def export_votes_xlsx(self, request):
    return Response(
        request.app.get_cached_dataset('xlsx'),
        content_type=(
            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
        ),
        content_disposition='inline; filename=dataset.xlsx')
Пример #4
0
 def log_in(self, request):
     response = Response()
     generic.remember_identity(response, request,
                               Identity(userid='user',
                                        payload='Amazing'),
                               lookup=request.lookup)
     return response
Пример #5
0
 def default(self, request):
     # will not actually do anything as it's a no-op for basic
     # auth, but at least won't crash
     response = Response()
     generic.remember_identity(response, request, Identity('foo'),
                               lookup=request.lookup)
     return response
Пример #6
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
Пример #7
0
def vcard_export_membership(self, request):
    """ Returns the memberships vCard. """

    exclude = request.app.org.excluded_person_fields(request) + ['notes']

    return Response(self.vcard(exclude),
                    content_type='text/vcard',
                    content_disposition='inline; filename=card.vcf')
Пример #8
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
Пример #9
0
 def log_in(self, request):
     response = Response()
     with pytest.deprecated_call():
         generic.remember_identity(response,
                                   request,
                                   Identity(userid='user',
                                            payload='Amazing'),
                                   lookup=request.lookup)
     return response
Пример #10
0
def preview_notice_pdf(self, request):
    """ Preview the notice as PDF. """

    pdf = NoticesPdf.from_notice(self, request)

    filename = normalize_for_url('{}-{}-{}'.format(
        request.translate(_("Gazette")), request.app.principal.name,
        self.title))

    return Response(pdf.read(),
                    content_type='application/pdf',
                    content_disposition=f'inline; filename={filename}.pdf')
Пример #11
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
Пример #12
0
def get_root_pdf(self, request):

    if not request.app.root_pdf_exists:
        return Response(status='503 Service Unavailable')

    @request.after
    def cache_headers(response):
        last_modified = request.app.root_pdf_modified
        if last_modified:
            max_age = 1 * 24 * 60 * 60
            expires = datetime.now() + timedelta(seconds=max_age)
            fmt = '%a, %d %b %Y %H:%M:%S GMT'

            response.headers.add('Cache-Control', f'max-age={max_age}, public')
            response.headers.add('ETag', last_modified.isoformat())
            response.headers.add('Expires', expires.strftime(fmt))
            response.headers.add('Last-Modified', last_modified.strftime(fmt))

    return Response(request.app.root_pdf,
                    content_type='application/pdf',
                    content_disposition='inline; filename={}.pdf'.format(
                        normalize_for_url(request.app.org.name)))
Пример #13
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
Пример #14
0
def create_invoices(self, request, form):
    """ Create invoices and download them as CSV. """

    layout = InvoiceLayout(self, request)

    if form.submitted(request):
        form.update_model(self)

        response = Response(
            content_type='text/csv',
            content_disposition='inline; filename=rechnungen.csv')
        self.export(response.body_file)
        return response

    return {
        'layout': layout,
        'form': form,
        'button_text': _("Create invoice"),
        'cancel': layout.cancel_url
    }
Пример #15
0
def view_notices_index(self, request):
    """ Export the index to the notices as PDF.

    This view is only visible by a publisher.

    """

    pdf = IndexPdf.from_notices(self, request)

    filename = normalize_for_url(
        '{}-{}'.format(
            request.translate(_("Gazette")),
            request.app.principal.name
        )
    )

    return Response(
        pdf.read(),
        content_type='application/pdf',
        content_disposition=f'inline; filename={filename}.pdf'
    )
Пример #16
0
 def view(self, request):
     return Response('Hello world!')
Пример #17
0
 def view(request, model):
     return Response('Hello world!')
Пример #18
0
 def default(self, request):
     # will not actually do anything as it's a no-op for basic
     # auth, but at least won't crash
     response = Response(content_type='text/plain')
     generic.forget_identity(response, request, lookup=request.lookup)
     return response
Пример #19
0
 def log_out(self, request):
     response = Response()
     generic.forget_identity(response, request, lookup=request.lookup)
     return response
Пример #20
0
def export_votes_csv(self, request):
    return Response(request.app.get_cached_dataset('csv'),
                    content_type='text/csv',
                    content_disposition='inline; filename=dataset.csv')
Пример #21
0
 def log_out(self, request):
     response = Response()
     request.app.forget_identity(response, request)
     return response
Пример #22
0
 def log_in(self, request):
     response = Response()
     request.app.remember_identity(
         response, request, Identity(userid="user", payload="Amazing")
     )
     return response
Пример #23
0
def view_attendee_calendar(self, request):
    return Response(self.calendar(request),
                    content_type='text/calendar',
                    content_disposition=f'inline; filename={self.name}.ics')