Now, of course, when we look at the message content view, it displays the number of entries in the message, including reply messages and attachments (files and images). It is a good idea to display the size field with "X-reply, y-attachment." A very simple adapter to handle the size output, the adapter isized will be modified by imessage.
Step I: Implementation of the adapter
An adapter is usually a simple class that treats an object as a constructor parameter. This class must provide a "from" interface, which is also often listed in the ' Used_for ' attribute of the class. Add the following code to your message.py file:
#!python From zope.app.size.interfaces import isized
def sizeforsorting (self): "" "Isized" "" Return (' Item ', Len (self._message)) def sizeforhttp://www.aliyun.com/zixun/aggregation/16502.html ">display (self): "" "Isized" "" Messages = 0 For obj in Self._message.values (): If Imessage.providedby (obj): Messages + 1
Attachments = Len (self._message)-messages
If messages = = 1:size = = U ' 1 reply ' else:size = U '%i replies '%messages
If attachments = = 1:size + u ', 1 attachment ' else:size = U ',%i attachments '%attachments
return size
The Isized interface specifies two methods:
10–12 line: sizeforstring () must return a tuple with the first element being unit and the second value (value). Select a format that provides a common size representation comparison. 第14-19 line: Sizefordisplay () returns a Unicode string representing any kind of object size. The output should not be too long (my already very long). As we promised to display the replies and attachments separately.
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.