Zope3 custom model fields and form parts

Source: Internet
Author: User
Keywords We custom form
Tags code content created creating custom domain html it is

So far we've created enviable content components and have a pretty good view of them. Now let's focus on the details; anything at the moment can be written to the message domain, including malicious HTML and JavaScript code. It is therefore useful to develop a special field (and the corresponding widget) that excludes HTML tags that are not allowed.

Creating common fields and parts is a fairly common task for end user programs, and since these systems often have very specific requirements, custom Schema/form will help us reach our design goals and easily create the interface we want through customization.

Step I: Create a domain

The purpose of a particular domain is to validate the input of the domain based on allow or disallow HTML markup. If the message text exceeds the allowed HTML tag or contains a disabled HTML tag, the value acknowledgement should fail. Note Only one of the two properties can be specified. In ZOPE3, since the introduction of a laudable collection, we do not need to write a domain from scratch, as they are universally serviced by common domains as basic classes. And it has already provided most of the functionality to us, so our HTML domain text fields also use them as our domain base.

We will expand the text field through the two new properties of Allowed_tags and Forbidden_tags. We will then modify the _validate () method to implement the constraint.

(a) interface

As usual, the first step is to define the interface. In the interface module of Messageboard ' s, add the following lines:

#!python
From Zope.schema import Tuple
From zope.schema.interfaces import IText

Class ihtml (IText):
"" "A text field that handles HTML input." "

Allowed_tags = Tuple (
Title=u "Even HTML Tags",
Description=u "" "\
Only listed tags can is used in the http://www.aliyun.com/zixun/aggregation/9541.html ">value of the field."
""",
Required=false)

Forbidden_tags = Tuple (
Title=u "Forbidden HTML Tags",
Description=u "" "\
listed tags cant be used in the value of the field.
""",
Required=false)

Line 1th: The tuple field requires a value that is a python tuple.
第2-4: We have simply expanded the Itext interface and schema.
第7-12 rows &14-19 Rows: Defining two additional properties with a field tuple

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.