Moya Comments

Moya Comments enable threaded comments to be added to any page. You can get notification emails regarding comments, and replies. User's may unsubscribe from these emails at any point.


Moya Comments is built in to Moya, and may be imported via its Python path as follows:

<import py="moya.libs.comments"/>

You can install Moya Comments with the following:

<install name="comments" lib="moya.comments" mount="/comments/" />

The mount URL is used for few forms and the inner workings of the comments system, users will be able to make comments on any page.


email_from = <EMAIL ADDRESS>

This sets the email address that emails regarding notifications will be sent from.

recaptcha = <yes/no>

If yes, Moya Comments will require a CAPTCHA to post anonymously. See Moya Google Recaptcha.

Comment Widget

To enable comments on a page add a comment to your content, where you want the comments to appear (typically near the end of the page).

The <comments> widget needs two pieces of information in order to associate comments with the comment topic; these are topic and namespace. The topic attribute is a string which should be unique to type of topic. Since the comment topic is likely a database object of some kind, a sensible choice would be name of the object type and its primary key. For example post-${}. The namespace is a similar string, which can be any format you like, as long as the combination of namespace and topic is unique in your website. If your topic is a database object, then a namespace that includes the application name should be enough to make the combination unique.

You can also supply a url attribute, which is used to redirect back to the page containing the topic when a comment is posted. It is also stored along with the comments, so you can reference it in the admin view. If you don't supply a url, Moya Comments will use the current url being processed.

Here's an example of how to enable comments:

<comments:comments namespace="app-${}" topic="post-${}"/>

Note that the namespace plus topic scheme ensures that even if you change your URL structures, Moya will be able to keep track of the comments on that page.

Comment Counts

Moya Comments also supplies the <get-count> tag to get the number of comments on a particular topic. You would use this if you want to display the number of comments in some kind of summary page. Here's an example:

<for src="posts" dst="post">
    <comments:get-count namespace="app-post" topic="post-${}" dst="count"/>
    <html:p>${count} comment(s)</html:p>

This would be used in a content definition to add a <h1> tag for each post, followed by the number of comments on the post.

To avoid doing a database query for every object you want to get the comment counts for, you can use <get-counts> which gets the counts for a group of topics (in a single query). It returns a dictionary that maps the topic on to the number of comments.

The following does the same thing as the preceding example, but uses a single call to <get-counts>, rather than multiple <get-count> calls:

<comments:get-counts namespace="app-post" dst="counts" />
<for src="posts" dst="post">
    <html:p>${counts['post-' +]} comment(s)</html:p>