Chapter 6. Views – Designing the User Interface

This chapter will help you build the graphical interface for your applications. There are several different types of views and widgets available. The concepts of context and domain also play an important role for an improved user experience, and you will learn more about them.

The todo_ui module has the model layer ready, and now it needs the view layer with the user interface. We will add new elements to the UI as well as modify existing views that were added in previous chapters.

The best way to modify existing views is to use inheritance, as explained in Chapter 3, Inheritance – Extending Existing Applications. However, for the sake of clarity, we will overwrite the existing views, replacing them with completely new views. This will make the topics easier to explain and follow.

A new XML data file for our UI needs to be added to the module, so we can start by editing the __openerp__.py manifest file. We will need to use some fields from the todo_user module, so it must be set as a dependency:

{   'name': 'User interface improvements to the To-Do app',
    'description': 'User friendly features.',
    'author': 'Daniel Reis',
    'depends': ['todo_user'],
    'data': ['todo_view.xml'] }

Let's get started with the menu items and window actions.

Window actions

Window actions give instructions to the client-side user interface. When a user clicks on a menu item or a button to open a form, it's the underlying action that instructs the user interface what to do.

We will start by creating the window action to be used on the menu items, to open the to-do tasks and stages views. Create the todo_view.xml data file with the following code:

<?xml version="1.0"?>
<openerp>
  <data>
    <act_window id="action_todo_stage" name="To-Do Task Stages" res_model="todo.task.stage" view_mode="tree,form" />

    <act_window id="todo_app.action_todo_task" name=" To-Do Tasks" res_model="todo.task" view_mode="tree,form,calendar,gantt,graph" target="current " context="{'default_user_id': uid}"
        domain="[]"
        limit="80" />

    <act_window id="action_todo_task_stage" name="To-Do Task Stages" res_model="todo.task.stage" src_model="todo.task"
        multi="False"/> </data>
</openerp>

Window actions are stored in the ir.actions.act_window model, and can be defined in XML files using the <act_window> shortcut that we just used.

The first action opens the task stages model, and uses only the basic attributes for a window action.

The second action uses an ID in the todo_app namespace to overwrite the original to-do task action of the todo_app module. It uses the most relevant window actions attributes:

  • name: This is the title displayed on the views opened through this action.
  • res_model: This is the identifier of the target model.
  • view_mode: These are the view types to make available. The order is relevant and the first in the list is the view type opened by default.
  • target: If this is set to new, it will open the view in a dialog window. By default, it is current, and opens the view in the main content area.
  • context: This sets context information on the target views, which can be used to set default values on fields or activate filters, among other things. We will cover its details later in this chapter.
  • domain: This is a domain expression setting a filter for the records that will be available in the opened views.
  • limit: This is the number of records for each list view page, 80 by default.

The window action already includes the other view types that we will be exploring in this chapter: calendar, Gantt, and graph. Once these changes are installed, the corresponding buttons will be seen at the top-right corner, next to the list and form buttons. Notice that these won't work until we create the corresponding views.

The third window action demonstrates how to add an option under the More button, at the top of the view. These are the action attributes used to do so.

  • src_model: This attribute indicates the model for which this window action should be made available in the More button.
  • multi: This flag, if set to True, makes it available in the list view. Otherwise, it will be available in the form view.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset