Пример #1
0
def write_pdf(request, filename, html):
    """
        Write a pdf in a pyramid request
    """
    result = buffer_pdf(html)
    write_file_to_request(request, filename, result)
    return request
Пример #2
0
def py3o_view(context, request):
    """
    py3o view :

        compile the template provided as argument using the current view
        context for templating
    """
    log.debug(u"Asking for a template compilation")
    doctemplate_id = request.GET.get('template_id')

    if doctemplate_id:
        template = files.Template.get(doctemplate_id)
        if template:
            log.debug(" + Templating (%s, %s)" % (template.name, template.id))
            try:
                output = py3o.compile_template(context, template.data_obj,
                                               request.config)
                write_file_to_request(
                    request,
                    template.name,
                    output,
                )
                record_compilation(context, request, template)
                return request.response
            except Exception, err:
                print_exc()
                log.exception(
                    u"Une erreur est survenue à la compilation du template %s avec un contexte \
de type %s et d'id %s" % (template.id, context.__class__, context.id))
                request.session.flash(
                    u"Erreur à la compilation du modèle, merci de contacter \
votre administrateur", "error")
        else:
            request.session.flash(
                u"Impossible de mettre la main sur ce modèle", "error")
Пример #3
0
def write_pdf(request, filename, html):
    """
        Write a pdf in a pyramid request
    """
    result = buffer_pdf(html)
    write_file_to_request(request, filename, result)
    return request
Пример #4
0
    def _build_return_value(self, schema, appstruct, query):
        writer = self._init_writer()
        participants, conseillers = self._format_datas_for_export(query)
        for name, activities in participants.items():
            writer.add_row({
                'name': name,
                'date': '',
                'title': '',
                'duration': '',
                'conseillers': ''
            })
            for activity in activities:
                writer.add_row({
                    'name':
                    '',
                    'date':
                    activity.datetime,
                    'title':
                    self._activity_title(activity),
                    'duration':
                    activity.duration,
                    'conseillers':
                    ','.join([
                        render_api.format_account(conseiller)
                        for conseiller in activity.conseillers
                    ])
                })

        sheet_writer = self._init_next_sheet(writer)
        for name, activities in conseillers.items():
            sheet_writer.add_row({
                'name': name,
                'date': '',
                'title': '',
                'duration': '',
                'participants': ''
            })
            for activity in activities:
                sheet_writer.add_row({
                    'name':
                    '',
                    'date':
                    activity.datetime,
                    'title':
                    self._activity_title(activity),
                    'duration':
                    activity.duration,
                    'participants':
                    ','.join([
                        render_api.format_account(user)
                        for user in activity.participants
                    ])
                })

        if hasattr(sheet_writer, '_populate'):
            sheet_writer._populate()

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #5
0
    def _build_return_value(self, schema, appstruct, query):
        """
        Return the streamed file object
        """
        writer = self._init_writer()
        for item in self._stream_rows(query):
            writer.add_row(item)

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #6
0
    def __call__(self):
        query_factory = SheetQueryFactory(UserDatas, self.context,
                                          get_inspector())

        writer = csv.CsvExporter()
        writer.set_headers(query_factory.headers)
        for row in query_factory.rows:
            writer.add_row(row)

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #7
0
def file_dl_view(context, request):
    """
    download view for a given file
    """
    write_file_to_request(
            request,
            context.name,
            context,
            context.mimetype,
            )
    return request.response
Пример #8
0
def file_dl_view(context, request):
    """
    download view for a given file
    """
    write_file_to_request(
        request,
        context.name,
        context,
        context.mimetype,
    )
    return request.response
Пример #9
0
 def _build_return_value(self, schema, appstruct, query):
     """
     Return the streamed file object
     """
     writer = self._init_writer()
     self.logger.debug(u" + Streaming rows")
     for item in self._stream_rows(query):
         writer.add_row(item)
     self.logger.debug(u" + Writing the file to the request")
     write_file_to_request(self.request, self.filename, writer.render())
     return self.request.response
Пример #10
0
    def __call__(self):
        filename = self._get_filename()
        pdf_datas = self.get_pdf_buffer(filename)

        write_file_to_request(
            self.request,
            filename,
            pdf_datas,
            'application/pdf'
        )
        return self.request.response
Пример #11
0
 def _build_return_value(self, schema, appstruct, query):
     writer = self._init_writer()
     writer._datas = []
     for type_, row in self._stream_rows(query):
         row_datas = [type_.label]
         row_datas.extend(row)
         if type_.is_total:
             writer.add_highlighted_row(row_datas)
         else:
             writer.add_row(row_datas)
     write_file_to_request(self.request, self.filename, writer.render())
     return self.request.response
Пример #12
0
    def write_file(self, expenses, form_name, appstruct):
        from autonomie.interfaces import ITreasuryExpenseWriter
        writer = self.request.find_service(ITreasuryExpenseWriter)

        datas = self._collect_export_datas(expenses, appstruct)
        writer.set_datas(datas)
        write_file_to_request(
            self.request,
            get_timestamped_filename(u"export_ndf", writer.extension),
            writer.render(),
            headers="application/csv",
        )
        return self.request.response
Пример #13
0
 def write_csv(self, invoices):
     """
         Write the exported csv file to the request
     """
     exporter = ComputeSageExport(self.request.config)
     writer = SageCsvWriter(exporter.get_book_entries(invoices))
     write_file_to_request(
             self.request,
             self.filename,
             writer.render(),
             headers="application/csv")
     self.record_invoices_exported(invoices)
     return self.request.response
Пример #14
0
 def write_file(self, payments, form_name, appstruct):
     """
     Write the exported csv file to the request
     """
     exporter = ExpensePaymentExport(self.context, self.request)
     writer = SageExpensePaymentCsvWriter()
     writer.set_datas(exporter.get_book_entries(payments))
     write_file_to_request(self.request,
                           get_timestamped_filename(u"export_paiement_ndf",
                                                    writer.extension),
                           writer.render(),
                           headers="application/csv")
     return self.request.response
Пример #15
0
 def write_file(self, payments, form_name, appstruct):
     """
     Write the exported csv file to the request
     """
     exporter = ExpensePaymentExport(self.context, self.request)
     writer = SageExpensePaymentCsvWriter(self.context, self.request)
     writer.set_datas(exporter.get_book_entries(payments))
     write_file_to_request(
         self.request,
         get_timestamped_filename(u"export_paiement_ndf", writer.extension),
         writer.render(),
         headers="application/csv")
     return self.request.response
Пример #16
0
    def _build_return_value(self, schema, appstruct, query):
        """
        Return the streamed file object
        """
        writer = self._init_writer()
        writer = add_o2m_headers_to_writer(writer, query)
        writer = add_custom_datas_headers(writer, query)
        for item in self._stream_rows(query):
            writer.add_row(item)
            self.add_code_compta(writer, item)

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #17
0
 def write_csv(self, expenses):
     """
     Write the exported csv file to the request
     """
     exporter = ExpenseExport(self.request.config)
     writer = SageExpenseCsvWriter()
     writer.set_datas(exporter.get_book_entries(expenses))
     write_file_to_request(self.request,
                           self.filename,
                           writer.render(),
                           headers="application/csv")
     self.record_exported(expenses)
     return self.request.response
Пример #18
0
    def write_file(self, expenses, form_name, appstruct):
        from autonomie.interfaces import ITreasuryExpenseWriter
        writer = self.request.find_service(ITreasuryExpenseWriter)

        datas = self._collect_export_datas(expenses, appstruct)
        writer.set_datas(datas)
        write_file_to_request(
            self.request,
            get_timestamped_filename(u"export_ndf", writer.extension),
            writer.render(),
            headers="application/csv",
        )
        return self.request.response
Пример #19
0
    def _build_return_value(self, schema, appstruct, query):
        """
        Return the streamed file object
        """
        writer = self._init_writer()
        writer = add_o2m_headers_to_writer(writer, query)
        writer = add_custom_datas_headers(writer, query)
        for item in self._stream_rows(query):
            writer.add_row(item)
            self.add_code_compta(writer, item)

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #20
0
def py3o_view(context, request):
    """
    py3o view :

        compile the template provided as argument using the current view
        context for templating
    """
    logger.debug(u"Asking for a template compilation")
    doctemplate_id = request.GET.get('template_id')

    if doctemplate_id:
        template = files.Template.get(doctemplate_id)
        if template:
            logger.debug(
                " + Templating (%s, %s)" % (template.name, template.id)
            )
            try:
                output = py3o.compile_template(
                    context,
                    template.data_obj,
                    request.config
                )
                write_file_to_request(
                    request,
                    template.name,
                    output,
                )
                record_compilation(context, request, template)
                store_compiled_file(context, request, output, template)
                return request.response
            except UndefinedError, err:
                key = get_key_from_genshi_error(err)
                msg = u"""Erreur à la compilation du modèle la clé {0}
n'est pas définie""".format(key)
                logger.exception(msg)

                request.session.flash(msg, "error")
            except Exception:
                logger.exception(
                    u"Une erreur est survenue à la compilation du template \
%s avec un contexte de type %s et d'id %s" % (
                        template.id,
                        context.__class__,
                        context.id,
                    )
                )
                request.session.flash(
                    u"Erreur à la compilation du modèle, merci de contacter \
votre administrateur",
                    "error"
                )
Пример #21
0
 def write_csv(self, expenses):
     """
     Write the exported csv file to the request
     """
     exporter = ExpenseExport(self.request.config)
     writer = SageExpenseCsvWriter()
     writer.set_datas(exporter.get_book_entries(expenses))
     write_file_to_request(
             self.request,
             self.filename,
             writer.render(),
             headers="application/csv")
     self.record_exported(expenses)
     return self.request.response
Пример #22
0
    def __call__(self):
        query_factory = SheetQueryFactory(
            UserDatas,
            self.context,
            get_inspector()
        )

        writer = csv.CsvExporter()
        writer.set_headers(query_factory.headers)
        for row in query_factory.rows:
            writer.add_row(row)

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #23
0
 def write_csv(self, payments):
     """
     Write the exported csv file to the request
     """
     exporter = ExpensePaymentExport(self.request.config)
     writer = SageExpensePaymentCsvWriter()
     writer.set_datas(exporter.get_book_entries(payments))
     write_file_to_request(self.request,
                           get_filename(u"export_paiement_ndf",
                                        writer.extension),
                           writer.render(),
                           headers="application/csv")
     self.record_exported(payments)
     return self.request.response
Пример #24
0
 def write_csv(self, invoices):
     """
         Write the exported csv file to the request
     """
     exporter = InvoiceExport(self.request.config)
     writer = SageInvoiceCsvWriter()
     writer.set_prefix(self.request.config.get('invoice_prefix', ''))
     writer.set_datas(exporter.get_book_entries(invoices))
     write_file_to_request(self.request,
                           self.filename,
                           writer.render(),
                           headers="application/csv")
     self.record_exported(invoices)
     return self.request.response
Пример #25
0
    def _build_return_value(self, schema, appstruct, query):
        writer = self._init_writer()
        participants, conseillers = self._format_datas_for_export(query)
        for name, activities in participants.items():
            writer.add_row({
                'name': name,
                'date': '',
                'title': '',
                'duration': '',
                'conseillers': ''
            })
            for activity in activities:
                writer.add_row({
                    'name': '',
                    'date': activity.datetime,
                    'title': self._activity_title(activity),
                    'duration': activity.duration,
                    'conseillers': ','.join([
                        render_api.format_account(conseiller)
                        for conseiller in activity.conseillers])
                })

        sheet_writer = self._init_next_sheet(writer)
        for name, activities in conseillers.items():
            print("Adding a row")
            sheet_writer.add_row({
                'name': name,
                'date': '',
                'title': '',
                'duration': '',
                'participants': ''
            })
            for activity in activities:
                print(u"Adding a row")
                sheet_writer.add_row({
                    'name': '',
                    'date': activity.datetime,
                    'title': self._activity_title(activity),
                    'duration': activity.duration,
                    'participants': ','.join([
                        render_api.format_account(user)
                        for user in activity.participants])
                })

        if hasattr(sheet_writer, '_populate'):
            sheet_writer._populate()

        write_file_to_request(self.request, self.filename, writer.render())
        return self.request.response
Пример #26
0
 def write_csv(self, invoices):
     """
         Write the exported csv file to the request
     """
     exporter = InvoiceExport(self.request.config)
     writer = SageInvoiceCsvWriter()
     writer.set_prefix(self.request.config.get('invoice_prefix', ''))
     writer.set_datas(exporter.get_book_entries(invoices))
     write_file_to_request(
             self.request,
             self.filename,
             writer.render(),
             headers="application/csv")
     self.record_exported(invoices)
     return self.request.response
Пример #27
0
    def write_file(self, payments, form_name, appstruct):
        """
            Write the exported csv file to the request
        """
        from autonomie.interfaces import ITreasuryPaymentProducer
        exporter = self.request.find_service(ITreasuryPaymentProducer)
        from autonomie.interfaces import ITreasuryPaymentWriter
        writer = self.request.find_service(ITreasuryPaymentWriter)

        writer.set_datas(exporter.get_book_entries(payments))
        write_file_to_request(self.request,
                              get_timestamped_filename(u"export_encaissement",
                                                       writer.extension),
                              writer.render(),
                              headers="application/csv")
        return self.request.response
Пример #28
0
    def write_file(self, payments, form_name, appstruct):
        """
            Write the exported csv file to the request
        """
        from autonomie.interfaces import ITreasuryPaymentProducer
        exporter = self.request.find_service(ITreasuryPaymentProducer)
        from autonomie.interfaces import ITreasuryPaymentWriter
        writer = self.request.find_service(ITreasuryPaymentWriter)

        writer.set_datas(exporter.get_book_entries(payments))
        write_file_to_request(
            self.request,
            get_timestamped_filename(u"export_encaissement", writer.extension),
            writer.render(),
            headers="application/csv")
        return self.request.response
Пример #29
0
    def write_csv(self, expenses):
        """
        Write the exported csv file to the request
        """
        from autonomie.interfaces import ITreasuryExpenseProducer
        exporter = self.request.find_service(ITreasuryExpenseProducer)

        from autonomie.interfaces import ITreasuryExpenseWriter
        writer = self.request.find_service(ITreasuryExpenseWriter)

        writer.set_datas(exporter.get_book_entries(expenses))
        write_file_to_request(self.request,
                              get_filename(u"export_ndf", writer.extension),
                              writer.render(),
                              headers="application/csv")
        self.record_exported(expenses)
        return self.request.response
Пример #30
0
 def _view(request):
     """
         the dynamically built view object
     """
     filename = filename_builder(request)
     result = factory(request.context).render()
     request = write_file_to_request(request, filename, result)
     return request.response
Пример #31
0
    def write_csv(self, invoices):
        """
            Write the exported csv file to the request
        """
        from autonomie.interfaces import ITreasuryInvoiceProducer
        exporter = self.request.find_service(ITreasuryInvoiceProducer)
        from autonomie.interfaces import ITreasuryInvoiceWriter
        writer = self.request.find_service(ITreasuryInvoiceWriter)

        writer.set_datas(exporter.get_book_entries(invoices))
        write_file_to_request(
            self.request,
            get_filename(u"export_facture", writer.extension),
            writer.render(),
            headers="application/csv")
        self.record_exported(invoices)
        return self.request.response
Пример #32
0
 def _view(request):
     """
         the dynamically built view object
     """
     filename = filename_builder(request)
     result = factory(request.context).render()
     request = write_file_to_request(request, filename, result)
     return request.response
Пример #33
0
def add_response_to_request(request, template, context):
    """
    Build a templated file response, write it in the request
    and record compilation

    :param obj request: The current request object
    :param obj template: A Template object
    :param obj context: The context to use for templating
    :returns: The request object
    """
    output = py3o.compile_template(context, template.data_obj, request.config)
    write_file_to_request(
        request,
        template.name,
        output,
    )
    store_compiled_file(context, request, output, template)
    return request
Пример #34
0
    def write_file(self, invoices, form_name, appstruct):
        """
            Write the exported csv file to the request
        """
        from autonomie.interfaces import ITreasuryInvoiceProducer
        exporter = self.request.find_service(ITreasuryInvoiceProducer)
        from autonomie.interfaces import ITreasuryInvoiceWriter
        writer = self.request.find_service(ITreasuryInvoiceWriter)

        logger.debug(writer.headers)
        logger.debug(getattr(writer, 'extra_headers', ()))
        writer.set_datas(exporter.get_book_entries(invoices))
        write_file_to_request(
            self.request,
            get_timestamped_filename(u"export_facture", writer.extension),
            writer.render(),
            headers="application/csv")
        return self.request.response
Пример #35
0
def py3o_view(context, request):
    """
    py3o view :

        compile the template provided as argument using the current view
        context for templating
    """
    logger.debug(u"Asking for a template compilation")
    doctemplate_id = request.GET.get('template_id')

    if doctemplate_id:
        template = files.Template.get(doctemplate_id)
        if template:
            logger.debug(" + Templating (%s, %s)" %
                         (template.name, template.id))
            try:
                output = py3o.compile_template(context, template.data_obj,
                                               request.config)
                write_file_to_request(
                    request,
                    template.name,
                    output,
                )
                record_compilation(context, request, template)
                store_compiled_file(context, request, output, template)
                return request.response
            except UndefinedError, err:
                key = get_key_from_genshi_error(err)
                msg = u"""Erreur à la compilation du modèle la clé {0}
n'est pas définie""".format(key)
                logger.exception(msg)

                request.session.flash(msg, "error")
            except Exception:
                logger.exception(
                    u"Une erreur est survenue à la compilation du template \
%s avec un contexte de type %s et d'id %s" % (
                        template.id,
                        context.__class__,
                        context.id,
                    ))
                request.session.flash(
                    u"Erreur à la compilation du modèle, merci de contacter \
votre administrateur", "error")
Пример #36
0
    def stream_csv(context, request):
        """
        Stream resulting csv datas resulting from an import

        :param context: The csv import job instance
        """
        csv_str_datas = getattr(context, job_key, {})
        if csv_str_datas is None or len(csv_str_datas) == 0:
            raise HTTPNotFound()

        f_buf = StringIO.StringIO()
        f_buf.write(csv_str_datas.encode('utf-8'))
        write_file_to_request(
            request,
            "%s.csv" % filename,
            f_buf,
            "text/csv",
        )
        return request.response
Пример #37
0
def py3o_view(context, request):
    """
    py3o view :

        compile the template provided as argument using the current view
        context for templating
    """
    log.debug(u"Asking for a template compilation")
    doctemplate_id = request.GET.get('template_id')

    if doctemplate_id:
        template = files.Template.get(doctemplate_id)
        if template:
            log.debug(" + Templating (%s, %s)" % (template.name, template.id))
            try:
                output = py3o.compile_template(
                    context,
                    template.data_obj,
                    request.config
                )
                write_file_to_request(
                    request,
                    template.name,
                    output,
                )
                record_compilation(context, request, template)
                return request.response
            except Exception, err:
                print_exc()
                log.exception(
u"Une erreur est survenue à la compilation du template %s avec un contexte \
de type %s et d'id %s" % (template.id, context.__class__, context.id)
                             )
                request.session.flash(
                    u"Erreur à la compilation du modèle, merci de contacter \
votre administrateur",
                    "error"
                )
        else:
            request.session.flash(
                u"Impossible de mettre la main sur ce modèle",
                "error"
            )
Пример #38
0
    def stream_csv(context, request):
        """
        Stream resulting csv datas resulting from an import

        :param context: The csv import job instance
        """
        csv_str_datas = getattr(context, job_key, {})
        if csv_str_datas is None or len(csv_str_datas) == 0:
            raise HTTPNotFound()

        f_buf = StringIO.StringIO()
        f_buf.write(csv_str_datas.encode('utf-8'))
        write_file_to_request(
            request,
            "%s.csv" % filename,
            f_buf,
            "text/csv",
        )
        return request.response
Пример #39
0
    def py3o_action_view(self, doctemplate_id):
        """
        Answer to simple GET requests
        """
        model = self.current_userdatas
        template = files.Template.get(doctemplate_id)
        if template:
            logger.debug(
                " + Templating (%s, %s)" % (template.name, template.id)
            )
            try:
                compiled_output = get_template_output(
                    self.request, template, model
                )
                write_file_to_request(
                    self.request, template.name, compiled_output
                )
                store_compiled_file(
                    model,
                    self.request,
                    compiled_output,
                    template,
                )
                record_compilation(model, self.request, template)
                return self.request.response
            except UndefinedError, err:
                key = get_key_from_genshi_error(err)
                msg = u"""Erreur à la compilation du modèle la clé {0}
n'est pas définie""".format(key)
                logger.exception(msg)

                self.session.flash(msg, "error")
            except IOError:
                logger.exception(u"Le template n'existe pas sur le disque")
                self.session.flash(
                    u"Erreur à la compilation du modèle, le modèle de fichier "
                    u"est manquant sur disque. Merci de contacter votre "
                    u"administrateur.",
                    "error",
                )
Пример #40
0
    def py3o_action_view(self, doctemplate_id):
        """
        Answer to simple GET requests
        """
        model = self.current_userdatas
        template = files.Template.get(doctemplate_id)
        if template:
            logger.debug(" + Templating (%s, %s)" %
                         (template.name, template.id))
            try:
                compiled_output = get_template_output(self.request, template,
                                                      model)
                write_file_to_request(self.request, template.name,
                                      compiled_output)
                store_compiled_file(
                    model,
                    self.request,
                    compiled_output,
                    template,
                )
                record_compilation(model, self.request, template)
                return self.request.response
            except UndefinedError, err:
                key = get_key_from_genshi_error(err)
                msg = u"""Erreur à la compilation du modèle la clé {0}
n'est pas définie""".format(key)
                logger.exception(msg)

                self.session.flash(msg, "error")
            except IOError:
                logger.exception(u"Le template n'existe pas sur le disque")
                self.session.flash(
                    u"Erreur à la compilation du modèle, le modèle de fichier "
                    u"est manquant sur disque. Merci de contacter votre "
                    u"administrateur.",
                    "error",
                )
Пример #41
0
 def __call__(self):
     writer = self.csvwriter(self.model)
     for item in self.query():
         writer.add_row(item.appstruct())
     write_file_to_request(self.request, self.filename, writer.render())
     return self.request.response