Inline editing

The user will be able to modify records directly from the website in edit mode. The data loaded with the t-field node will be editable by default. If the user changes the value in such a node and saves the page, the values will also be updated in the backend. Don't worry; in order to update the record, a user will need write permissions on the record. Note that t-field only works on a recordset. To display other types of data, you can use t-esc. This works exactly like t-field, but the only difference is that t-esc is not editable and can be used with any type of data.

If you want to enable snippet drag and drop support on the page, you can use the oe_structure class. In our example, we have added this at the top of the template. Using oe_structure will enable editing and snippet drag and drop support.

If you want to disable the website editing feature on some block, then you can use the contenteditable=False attribute. This makes an element read-only. In step 1, we have used this attribute in the last <section> tag.

Note that editing a view through the website editor sets the noupdate flag on this view. This means that subsequent code changes will never make it into your customer's database. In order to also get the ease of use of inline editing and the possibility of updating your HTML code in subsequent releases, create one view that contains the semantic HTML elements and a second one that injects editable elements. Then, only the latter view will be noupdate, and you can still change the former.

For the other CSS classes used here, consult Bootstrap's documentation, as linked in this recipe's See also section.

In step 2, we have declared the route to render the template. If you noticed, we have used the website=True parameter in route(), which will pass some extra context in the template, like menus, user language, company, and so on. This will be used in website.layout to render the menus and footers. The website=True parameter also enables multilanguage support in a website. It also displays exceptions in a better way.

At the function end, we returned the result by rendering the template; we then passed the recordset of all books that are being used in the template. For more information about updating existing routes, refer to the Modifying an existing handler recipe in Chapter 14, Web Server Development.

..................Content has been hidden....................

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