How to create grid view or whoever can support to create grid view?


I would like to create grid view at tryton client.
Either by xml or through html. May I know how can I achieve that?
Or can get paid service for this?

Could you explain a little bit more what is exactly? What are the data to display? What is the goal of the view? etc.

Merry Christmas to All…

Thank you @ced for quick response.

I am going to make a view for displaying the Racking(Bin) status.
The model is Bank, Bay, Level, prohibited, state.
State has empty and occupied.

So the grid will show the color to determine the state.
Green is occupied, White is empty, yellow is prohibited.

1 Page is show the 1 Bank. Then user choose the bank to display the Grid status.

Best Regards

For which goal? How is it helping the user? and for which task?

There is nothing in Tryton for this purpose. At best you generate an image and display it.
We had one time a request a little bit similar based on a actual plan. Our proposal (that we did not implement) was to have a static base in SVG with XML id on places we want to color. And generate a CSS with a color rule for each id. This image would be put in a simple HTML page that is templated and served by trytond.

Hi Ced,

The main goal is to let user to visualize the actual condition. We can show the data by tree or list, however, it might hard for them to imagine the real condition in the warehouse or racking.

Regarding your proposal to generate the image and display in trytond, are you mean to diplays the svg in trytond client? Or to host to another website such as flask?

Well I still do not understand the point. Either the number of cells is small then a simple list works, either the number of cells is high then a picture is neither practical (another metric could be used like a filling rate etc.).

You do not need flask to serve HTML page. Tryton can do that (like in account_payment_stripe).

Now I have difficulties to advise on how to use such image because I do not understand the use case.

Hi @ced,

Thank you for your advice. I am doing like the account_payment_stripe using routes.
I just know that the Route can serve as a website. This is very helpful in term of for anything difficult to do in Trytond such as fancy design report.

Thank you

Hi @ced,

Sorry to trouble you again.
May I know how to set the assets (images, css, js) folder? so that the website can call

Create a route for each one.
But for css and js, I would simply embed them in the HTML.

I created a folder “images” in module and put the image in the folder.
When I embed such as html below, it cannot read the folder. My question, How you simply embed them in the html using static path?
<IMG SRC="images/arrow_lvl.gif"/>

As I said you must create a route that returns the image content.
(I created Issue 8957: Add a default static route for each module - Tryton issue tracker to ease development).

I am sorry @ced. I had tried below method to create the static folder. But not success, could you show me some code/module for example??

from os import path
from werkzeug import SharedDataMiddleware

STATIC_PATH = path.join(path.dirname(__file__), 'static')
def __call__(self, environ, start_response):
    return self.dispatch(environ, start_response)
def __init__(self, query, per_page, page, endpoint):
    self.dispatch = SharedDataMiddleware(self.dispatch, {
        '/static':  STATIC_PATH


<IMG SRC={{ url_for('static', file="arrow_lvl.gif") }}/>

Such route is not different than others.
Here is an example (not tested):

def static(request, path):
   file = tools.file_open(os.path.join('mymodule/static', path))
   headers = {…}
   return Response(wrap_file(file), headers=headers, …)

Thanks for your sample code. Below attached is working code for station folder. And maybe can be reference for others:

from os import path

STATIC_PATH = path.join(path.dirname(__file__), 'static')

def js(request, pool, model, filename):
    pp = '%s/%s/%s' % (STATIC_PATH, 'images', filename)
    f = open(pp, 'rb')
    return Response(wrap_file(request.environ,f))

Normally, you do not need of the with_pool nor with_transaction decorators. So the <database_name> can also be removed from the URL pattern.
You should use because for now you have no validation against path escape like database/booking/checkout/model/images/../../../../../../etc/password.
You may also want to put some caching header to reduce the number of requests.

Finally if you feel it, you can propose a generic solution for Issue 8957: Add a default static route for each module - Tryton issue tracker

Hi @ced,

STATIC_PATH = path.join(path.dirname(file), ‘static’)
I am using this because I am in development, if I am using tools.file_open it call the path in the trytond which currently the image file does not exist.

I will interest to make generic solution. Before that, I want to confirm below items.

Putting js, css from external such as cdn, or static folder, is not working with the method Report.html. When using in html, report generator seem like ignore or passing the wrong close tag.

Can I say it is bug? or limitation from genshi?

I am sharing my outcome but JS and CSS are written in the HTML instead get from external.

As far as I know, Genshi expect valid XML so HTML must be written as valid XML.

As i expected, so that even we created a static folder. So far, we only can import the images but js and css hardly to be imported.

Is it worth to create the generic solution?

I do not see why script and style could not be imported.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.