The post content provider

The post content provider is used to render a single message. It provides an interface, which is used by the XML that generates the page.

Interface

The post content provider implements the interface IPostContentProvider. The various attributes are filled by the XML provided by the calling code.

class gs.group.messages.post.base.interfaces.IPostContentProvider
post

(Required) The email message instance that is being displayed.

position

The position of the post in the list of posts, as an integer (int) above 0 (a cardinal value). Defaults to 1.

topicName

(Required) The name of the topic that the post appears in, as a Unicode sequence (str in Python 3, unicode in Python 2). While the post could figure this out, it is faster to have this information provided (see Design requirements).

showPhoto

Whether the photo of the author should be shown, as a Boolean (bool, defaulting to True). On both the Topic and Post page sequential posts by the same author have the profile photo dropped.

isPublic

(Required) Whether the post is public, as a Boolean (bool, with no default). While the post could figure this out, it is faster to have this information provided (see Design requirements).

showRemainder

Whether to show the snipped bottom-quoting and signature on the post, as a Boolean (bool, defaulting to False).

XML

The XML that uses the content provider is in two parts. First, the parameters — as defined by IPost — are set up by the TAL of the calling code, using the tal:define attribute. Second the content provider is called using the provider: expression.

For example, the code used by the Topic page looks similar to the following.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<tal:block
  define="topicName view/topicName;
          isPublic view/isPublic;">
  <tal:block repeat="post view/topic">
    <tal:block
      define="position repeat/post/number;
              currAuth python:view.topic[position-1]['author_id'];
              prevAuth python:view.topic[position-2]['author_id'];
              rptAuth python: currAuth == prevAuth;
              showPhoto python:(position==1) or not(rptAuth);"
      replace="structure provider:groupserver.Post">
      This is replaced by the body of the post
    </tal:block>
  </tal:block>
</tal:block>

Initially, the IPost.topicName and IPost.isPublic attributes are set up (lines 2–3). The the topic iterates across all the posts in the topic, setting the IPost.position accordingly (line 6). The IPost.showPhoto is calculated (line 10), while the IPost.showRemainder is left as its default (False). Finally, the content provider is called using structure provider:groupserver.Post, replacing the content of the <tal:block> element (line 11).