From b8b96b44b838853aff16a1cbd7772fbd5450f254 Mon Sep 17 00:00:00 2001 From: Mendes Date: Wed, 3 May 2017 19:16:36 +0100 Subject: [PATCH] Add option to specify embed URL for comments feed --- docs/index.rst | 13 +++++++++++-- pybossa_discourse/globals.py | 6 ++++-- pybossa_discourse/info.json | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 4ba403c..1b5db9b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -121,8 +121,17 @@ To embed Discourse comments in your PyBossa theme: {{ discourse.comments() }} {% endif %} -The first time that someone visits each page on which the above snippet appears a new topic will be created. -When people post in that topic, their comments will show up on the page where that topic is embedded. +The above function takes a single optional parameter that specifies the URL of the page that is embedding the comment +feed. By default this is set to the URL of the current page. The first time that someone the page a new topic will be +created based on that URL. + +So, if you wanted to create a new topic for each category and embed that topic in various different places you might do this: + +.. code-block:: HTML+Django + + {% if 'pybossa_discourse' in plugins %} + {{ discourse.comments(url_for('project.project_cat_index', category=short_name)) }} + {% endif %} API variable diff --git a/pybossa_discourse/globals.py b/pybossa_discourse/globals.py index 909b0b2..3dab0bd 100644 --- a/pybossa_discourse/globals.py +++ b/pybossa_discourse/globals.py @@ -13,8 +13,10 @@ def __init__(self, app): self.api = discourse_client app.jinja_env.globals.update(discourse=self) - def comments(self): + def comments(self, embedUrl=None): """Return an HTML snippet used to embed Discourse comments.""" + if not embedUrl: + embedUrl = request.base_url return Markup("""
- """).format(self.url, request.base_url) + """).format(self.url, embedUrl) def notifications(self): """Return a count of unread notifications for the current user.""" diff --git a/pybossa_discourse/info.json b/pybossa_discourse/info.json index 643809a..d84a2dd 100644 --- a/pybossa_discourse/info.json +++ b/pybossa_discourse/info.json @@ -5,5 +5,5 @@ "website": "https://github.com/alexandermendes/pybossa-discourse", "license": "BSD", "description": "A PyBossa plugin for Discourse integration.", - "version": "0.2.1" + "version": "0.2.2" }