max_pages for other printouts

Hi folks,

I am looking for a method to use “max_pages” and “num_page” in a non-standard printout type.

Especially I have build a macro where I want to use it:

{%- macro bottom(max_pages, page_num) -%}

{{ page }}
		 <p class="text-right">{{ _("Seite {0} von {1}").format(page_num, max_pages) }}</p>

{%- endmacro -%}

But when I include/import the macro, it gives me the error, that render.py and print.py cannot build the side.

Best,
Daniel

What is the error? Hard to guess without seeing the trace!

rmehta: I copied and pasted the code

Traceback (innermost last):
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/app.py", line 49, in application
    response = frappe.handler.handle()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 66, in handle
    execute_cmd(cmd)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 89, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 531, in call
    return fn(*args, **newargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 86, in get_html
    html = template.render(args, filters={"len": len})
  File "/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "

This is how I try to call the macro:

{%- from "templates/print_formats/standard_macros_modified.html" import add_header,
     render_field, bottom -%}
{{ bottom(doc, page_num, max_pages) }}

Best,
Daniel

Anyone can reproduce the error??

the trace is incomplete - can you share the trace from your bench console?

How to Do that :frowning:
Daniel

Well, basically everything is finished…but I need to get the page_num and max_pages into every macro and not only add_header…is this somehow possible @rmehta?

As you can see in the screenshot: everything is working except the macro for page_num and max_pages.

Best,
Daniel

@daniel can’t help if you neither share the code or the trace!

@rmehta, thank you for your message.

Here is the code of the macro:
Pastebin Macro - daniel

Line 12: Calls num_page and max_pages
Line 139 & 140: Tried to display num_pages

Pastebin HTML Template - daniel

Here you can see how I want to call the standard-functions in the HTML Template.

This is the Error it gives me

Best regards,
Daniel

@daniel - I am repeating myself - please don’t give the trace you see on your page (it is incomplete). Give the trace from your terminal.

Hi @rmehta, I really feel ashamed now to ask you this silly question, but I feel somehow stuck in a tunnel with no exit…how can I produce this traceback for you?

What is your development environment?

Are you doing bench start on your terminal?

you can also don bench frappe --serve

Hi, some strange things happening…maybe this is why my last trace was not complete? For your information…have not modified the OS itself…only some DocTypes. Basically the only thing I’ve done is that I have set developer mode like described on frappe.io

 root@erpnext-vm:~# bench frappe --serve
    frappe app is not installed. Run the following command to install frappe
    bench get-app frappe https://github.com/frappe/frappe.git
    Traceback (most recent call last):
      File "/usr/local/bin/bench", line 9, in <module>
        load_entry_point('bench==0.1', 'console_scripts', 'bench')()
      File "/home/erpnext/bench-repo/bench/cli.py", line 28, in cli
        return frappe()
      File "/home/erpnext/bench-repo/bench/cli.py", line 33, in frappe
        os.chdir(os.path.join(bench, 'sites'))
    OSError: [Errno 2] No such file or directory: './sites'
    root@erpnext-vm:~# bench get-app frappe https://github.com/frappe/frappe.git
    Traceback (most recent call last):
      File "/usr/local/bin/bench", line 9, in <module>
        load_entry_point('bench==0.1', 'console_scripts', 'bench')()
      File "/home/erpnext/bench-repo/bench/cli.py", line 29, in cli
        return bench()
      File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 610, in __call__
        return self.main(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 590, in main
        rv = self.invoke(ctx)
      File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 936, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 782, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 416, in invoke
        return callback(*args, **kwargs)
      File "/home/erpnext/bench-repo/bench/cli.py", line 75, in get_app
        _get_app(name, git_url)
      File "/home/erpnext/bench-repo/bench/app.py", line 27, in get_app
        exec_cmd("git clone {git_url} {shallow_clone} --origin upstream {app}".format(git_url=git_url, app=app, shallow_clone=shallow_clone), cwd=os.path.join(bench, 'apps'))
      File "/home/erpnext/bench-repo/bench/utils.py", line 59, in exec_cmd
        subprocess.check_call(cmd, cwd=cwd, shell=True)
      File "/usr/lib/python2.7/subprocess.py", line 506, in check_call
        retcode = call(*popenargs, **kwargs)
      File "/usr/lib/python2.7/subprocess.py", line 493, in call
        return Popen(*popenargs, **kwargs).wait()
      File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
        errread, errwrite)
      File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
        raise child_exception
    OSError: [Errno 2] No such file or directory: './apps'
    root@erpnext-vm:~#

And this one here:

    root@erpnext-vm:~# bench start
ERROR: Procfile does not exist or is not a file
root@erpnext-vm:~#

Hi,
i got this one here:

erpnext@erpnext-vm:~/frappe-bench$ bench frappe --serve
 * Running on http://0.0.0.0:8000/
Traceback (most recent call last):
  File "/home/erpnext/frappe-bench/env/bin/frappe", line 9, in <module>
    load_entry_point('frappe==4.0.0', 'console_scripts', 'frappe')()
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py", line 53, in main
    return run(fn, parsed_args)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py", line 83, in run
    out = globals().get(fn)(**args)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py", line 67, in new_fn
    return fn(*args, **new_kwargs)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/cli.py", line 812, in serve
    frappe.app.serve(port=port, profile=profile, site=frappe.local.site, sites_path=sites_path)
  File "/home/erpnext/frappe-bench/apps/frappe/frappe/app.py", line 144, in serve
    use_debugger=True, use_evalex=True, threaded=True)
  File "/home/erpnext/frappe-bench/env/local/lib/python2.7/site-packages/werkzeug/serving.py", line 706, in run_simple
    test_socket.bind((hostname, port))
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use

Make sure to kill all your benches before starting bench again.

Hi, now it says the following…restarted VM (from your homepage) AND reinstalled the new VM from your homepage:

  erpnext@erpnext-vm:~$ bench restart
frappe-worker: stopped
frappe-web: stopped
frappe-workerbeat: stopped
frappe-worker: started
frappe-web: started
frappe-workerbeat: started
erpnext@erpnext-vm:~$ bench frappe --serve
frappe app is not installed. Run the following command to install frappe
bench get-app frappe https://github.com/frappe/frappe.git
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 9, in <module>
    load_entry_point('bench==0.1', 'console_scripts', 'bench')()
  File "/home/erpnext/bench-repo/bench/cli.py", line 28, in cli
    return frappe()
  File "/home/erpnext/bench-repo/bench/cli.py", line 33, in frappe
    os.chdir(os.path.join(bench, 'sites'))
OSError: [Errno 2] No such file or directory: './sites'
erpnext@erpnext-vm:~$ bench get-app frappe https://github.com/frappe/frappe.git
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 9, in <module>
    load_entry_point('bench==0.1', 'console_scripts', 'bench')()
  File "/home/erpnext/bench-repo/bench/cli.py", line 29, in cli
    return bench()
  File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 610, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 590, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 936, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 782, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click-3.3-py2.7.egg/click/core.py", line 416, in invoke
    return callback(*args, **kwargs)
  File "/home/erpnext/bench-repo/bench/cli.py", line 75, in get_app
    _get_app(name, git_url)
  File "/home/erpnext/bench-repo/bench/app.py", line 27, in get_app
    exec_cmd("git clone {git_url} {shallow_clone} --origin upstream {app}".format(git_url=git_url, app=app, shallow_clone=shallow_clone), cwd=os.path.join(bench, 'apps'))
  File "/home/erpnext/bench-repo/bench/utils.py", line 59, in exec_cmd
    subprocess.check_call(cmd, cwd=cwd, shell=True)
  File "/usr/lib/python2.7/subprocess.py", line 506, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory: './apps'
erpnext@erpnext-vm:~$

Are you running this from the frappe-bench folder?

Yes! I am Doing that within the folder

hi @rmehta, I think we should terminate this issue…and delete the topic. I assume I should simply open a new one in order to get the right answer :wink: we are stuck like in a traffic jam now.

My original question was:
How can I use the variables “max_pages” and “num_pages” OUTSIDE of the “add_header” macro. This is the only thing that interests me at the moment…frappe is working, erpnext is working and I love what you have done.

Yeah I am lost too!

In principle, you should not add complex logic to Jinja Templates. How about identifying pages earlier while building the context and then passing the pages in the context itself.