示例#1
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")
示例#2
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"
                )
示例#3
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
示例#4
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")
示例#5
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"
            )
示例#6
0
文件: py3o.py 项目: Kilya/autonomie
def get_template_output(request, template, context):
    """
    Compile the template/datas and generate the output file

    Workflow :

        - The context (model) is serialized to a dict
        - py3o is used to compile the template using the given dict

    :param obj request: The current request object
    :param obj template: A Template object
    :param obj context: The context to use for templating (must be an instance
    inheriting from Node)
    :returns: The request object
    :returns: StringIO.StringIO
    """
    additionnal_context = get_userdatas_py3o_stage_datas(context)
    additionnal_context.update(request.config)
    return py3o.compile_template(
        context,
        template.data_obj,
        additionnal_context=additionnal_context,
    )
示例#7
0
def get_template_output(request, template, context):
    """
    Compile the template/datas and generate the output file

    Workflow :

        - The context (model) is serialized to a dict
        - py3o is used to compile the template using the given dict

    :param obj request: The current request object
    :param obj template: A Template object
    :param obj context: The context to use for templating (must be an instance
    inheriting from Node)
    :returns: The request object
    :returns: StringIO.StringIO
    """
    additionnal_context = get_userdatas_py3o_stage_datas(context)
    additionnal_context.update(get_userdatas_company_datas(context))
    additionnal_context.update(request.config)
    return py3o.compile_template(
        context,
        template.data_obj,
        additionnal_context=additionnal_context,
    )