How it works...

In step 1, we created a QWeb template with the book_return_reminder_qweb ID. If you check in the template, we are not using the format_date() data field method anymore. This is because the QWeb rendering engine handles this automatically and displays the date based on the user's language. For the same reason, you are not required to use the format_amount() method to display the currency symbols. The QWeb rendering engine will manage this automatically. If you want to learn more about QWeb templates, refer to the Creating or modifying templates – QWeb recipe from Chapter 15, CMS Website Development.

In step 2, we added a button in the form view to invoke the book_return_reminder_qweb() method, which sends email to the followers.

In step 3, we added the book_return_reminder_qweb() method, which will be invoked by a button click. The message_post_with_view() method is used to send email. The message_post_with_view() method is inherited in the model through mail.thread inheritance. To send the email, you just need to pass the web template's XML ID as the parameter.

Sending mail with the QWeb template works exactly the same as the previous recipe, but there are some subtle differences between the QWeb mail template and the Jinja mail template. Here is a quick comparison between both templates:

  • There is no simple way to send extra parameters in the email templates. You have to use a recordset in the object variable to fetch dynamic data. On the other hand, with QWeb mail templates you can pass extra values in the renderer context through the values parameter:
self.message_post_with_view(
'my_library.book_return_reminder_qweb',
values={'extra_data': 'test'}
)
  • To manage the date format, time zone, and amount with currency symbols, in the Jinja template you have to use the format_date, format_tz, and format_amount functions, while in QWeb templates it is managed automatically.
  • It is not possible to modify an existing template for other modules in Jinja, whereas in QWeb templates you can modify the mail template through inheritance. If you want to learn more about QWeb inheritance, refer to the Creating or modifying templates QWeb recipe in Chapter 15, CMS Website Development.
  • You can select and use a Jinja template directly from the message composer. In the following screenshot, the drop-down menu in the bottom-right corner is used to select a Jinja template:

  • Using QWeb, selecting a template directly from the message composer is not an option.
..................Content has been hidden....................

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