Permalink
Browse files

initial version of django-intercom extracted from habitualist.com

  • Loading branch information...
0 parents commit c08b3b31e5c1bac7829c814b9aa6f27c38527e49 @jtauber jtauber committed Jan 24, 2012
@@ -0,0 +1,2 @@
+include README.rst
+recursive-include intercom/templates *.html
@@ -0,0 +1,5 @@
+===============
+django-intercom
+===============
+
+A pluggable app for adding `intercom.io <http://intercom.io/>`_ to your Django site.
@@ -0,0 +1,131 @@
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+PAPER =
+BUILDDIR = _build
+
+# Internal variables.
+PAPEROPT_a4 = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+PROJECT = django-intercom
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
+
+help:
+ @echo "Please use \`make <target>' where <target> is one of"
+ @echo " html to make standalone HTML files"
+ @echo " dirhtml to make HTML files named index.html in directories"
+ @echo " singlehtml to make a single large HTML file"
+ @echo " pickle to make pickle files"
+ @echo " json to make JSON files"
+ @echo " htmlhelp to make HTML files and a HTML help project"
+ @echo " qthelp to make HTML files and a qthelp project"
+ @echo " devhelp to make HTML files and a Devhelp project"
+ @echo " epub to make an epub"
+ @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+ @echo " latexpdf to make LaTeX files and run them through pdflatex"
+ @echo " text to make text files"
+ @echo " man to make manual pages"
+ @echo " changes to make an overview of all changed/added/deprecated items"
+ @echo " linkcheck to check all external links for integrity"
+ @echo " doctest to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+ -rm -rf $(BUILDDIR)/*
+
+html:
+ $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+ $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+ @echo
+ @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+ $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+ @echo
+ @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+ $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+ @echo
+ @echo "Build finished; now you can process the pickle files."
+
+json:
+ $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+ @echo
+ @echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+ $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+ @echo
+ @echo "Build finished; now you can run HTML Help Workshop with the" \
+ ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+ $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+ @echo
+ @echo "Build finished; now you can run "qcollectiongenerator" with the" \
+ ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+ @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/$(PROJECT).qhcp"
+ @echo "To view the help file:"
+ @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/$(PROJECT).qhc"
+
+devhelp:
+ $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+ @echo
+ @echo "Build finished."
+ @echo "To view the help file:"
+ @echo "# mkdir -p $$HOME/.local/share/devhelp/$(PROJECT)"
+ @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/$(PROJECT)"
+ @echo "# devhelp"
+
+epub:
+ $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+ @echo
+ @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo
+ @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+ @echo "Run \`make' in that directory to run these through (pdf)latex" \
+ "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+ $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+ @echo "Running LaTeX files through pdflatex..."
+ make -C $(BUILDDIR)/latex all-pdf
+ @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+ $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+ @echo
+ @echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+ $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+ @echo
+ @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+changes:
+ $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+ @echo
+ @echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+ $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+ @echo
+ @echo "Link check complete; look for any errors in the above output " \
+ "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+ $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+ @echo "Testing of doctests in the sources finished, look at the " \
+ "results in $(BUILDDIR)/doctest/output.txt."
@@ -0,0 +1,10 @@
+.. _changelog:
+
+ChangeLog
+=========
+
+
+0.1
+---
+
+- initial release
@@ -0,0 +1,27 @@
+import sys, os
+
+extensions = []
+templates_path = []
+source_suffix = '.rst'
+master_doc = 'index'
+project = u'django-intercom'
+copyright_holder = ''
+copyright = u'2011, %s' % copyright_holder
+exclude_patterns = ['_build']
+pygments_style = 'sphinx'
+html_theme = 'default'
+htmlhelp_basename = '%sdoc' % project
+latex_documents = [
+ ('index', '%s.tex' % project, u'%s Documentation' % project,
+ copyright_holder, 'manual'),
+]
+man_pages = [
+ ('index', project, u'%s Documentation' % project,
+ [copyright_holder], 1)
+]
+
+sys.path.insert(0, os.pardir)
+m = __import__("intercom")
+
+version = m.__version__
+release = version
@@ -0,0 +1,21 @@
+django-intercom
+===============
+
+**django-intercom** makes it easy for you to add support for **intercom.io** to your Django website.
+
+
+Development
+-----------
+
+The source repository can be found at https://github.com/eldarion/django-intercom
+
+
+Contents
+========
+
+.. toctree::
+ :maxdepth: 1
+
+ changelog
+ installation
+ usage
@@ -0,0 +1,17 @@
+.. _installation:
+
+Installation
+============
+
+* To install ::
+
+ pip install django-intercom
+
+or add ``django-intercom==0.1`` to your requirements file.
+
+* Add ``"intercom"`` to your ``INSTALLED_APPS`` setting::
+
+ INSTALLED_APPS = [
+ # other apps
+ "intercom",
+ ]
@@ -0,0 +1,46 @@
+.. _usage:
+
+Usage
+=====
+
+At the top of your base template add::
+
+ {% load intercom_tags %}
+
+
+And just before the ``</body>`` tag add::
+
+ {% intercom_js user %}
+
+
+And if you want a feedback/support link, put::
+
+ <a id="Intercom" href="#">Support</a>
+
+somewhere (e.g. in your nav bar) as explained by the **intercom.io** documentation.
+
+In your settings file set ``INTERCOM_APP_ID`` and optionally (if you use a user hash for security) ``INTERCOM_USER_HASH_KEY`` with the values
+provided by **intercom.io**.
+
+
+Custom Data
+-----------
+
+**intercom.io** lets you send custom, per-user data to its site. **django-intercom** lets individual apps contribute what custom data they want to provide.
+
+If you have an ``INTERCOM_APPS`` setting, it should be a list of apps that have an ``intercom`` module in them containing a ``custom_data`` function. This function should take a ``user`` and return a dictionary to be sent to **intercom.io** as custom data.
+
+For example, if you have an app called ``foo`` with a ``Foo`` model, you might add::
+
+ INTERCOM_APPS = [
+ "foo",
+ ]
+
+to your settings and then in ``foo/intercom.py`` have::
+
+ from foo.models import Foo
+
+ def custom_data(user):
+ return {
+ "foo_count" : Foo.objects.filter(user=user).count(),
+ }
@@ -0,0 +1 @@
+__version__ = "0.1"
@@ -0,0 +1,32 @@
+{% if email %}
+<script>
+ var intercomSettings = {
+ app_id: '{{ app_id }}',
+ email: '{{ email }}',{% if user_hash %}
+ user_hash: '{{ user_hash }}',{% endif %}
+ custom_data: {{ custom_data|safe }},
+ created_at: {{ created_at }},
+ widget: {
+ use_counter: true,
+ activator: '#Intercom',
+ activator_html: function ( obj ) {
+ return obj.activator_html_functions.brackets();
+ }
+ },
+ };
+ (function() {
+ function async_load() {
+ var s = document.createElement('script');
+ s.type = 'text/javascript'; s.async = true;
+ s.src = 'https://api.intercom.io/api/js/library.js';
+ var x = document.getElementsByTagName('script')[0];
+ x.parentNode.insertBefore(s, x);
+ }
+ if (window.attachEvent) {
+ window.attachEvent('onload', async_load);
+ } else {
+ window.addEventListener('load', async_load, false);
+ };
+ })();
+</script>
+{% endif %}
No changes.
@@ -0,0 +1,33 @@
+import time
+
+from django import template
+from django.conf import settings
+from django.utils import simplejson
+from django.utils.hashcompat import sha_constructor
+
+
+register = template.Library()
+
+
+@register.inclusion_tag("intercom/_intercom_js.html")
+def intercom_js(user):
+ if hasattr(settings, "INTERCOM_APP_ID") and user.is_authenticated():
+ if hasattr(settings, "INTERCOM_USER_HASH_KEY"):
+ user_hash = sha_constructor(settings.INTERCOM_USER_HASH_KEY + user.email).hexdigest()
+ else:
+ user_hash = None
+
+ custom_data = {}
+ for app in getattr(settings, "INTERCOM_APPS", []):
+ m = __import__(app + ".intercom", globals(), locals(), ["intercom"])
+ custom_data.update(m.custom_data(user))
+
+ return {
+ "app_id": settings.INTERCOM_APP_ID,
+ "email": user.email,
+ "user_hash": user_hash,
+ "created_at": int(time.mktime(user.date_joined.timetuple())),
+ "custom_data": simplejson.dumps(custom_data, ensure_ascii=False)
+ }
+ else:
+ return {}
Oops, something went wrong.

0 comments on commit c08b3b3

Please sign in to comment.