Snipts count for user for intercom.

master
Nick Sergeant 2012-04-16 18:52:49 -04:00
parent 8d9bdff1e2
commit 94db0dd3c9
3 changed files with 78 additions and 57 deletions

View File

@ -21,6 +21,7 @@
{% with 'true' as detail %}
{% include "snipts/snipt-list.html" %}
{% endwith %}
{% if not debug %}
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'snipt-net';
@ -37,5 +38,6 @@
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
{% endif %}
</section>
{% endblock %}

View File

@ -3,7 +3,7 @@ from django import template
from templatetag_sugar.register import tag
from templatetag_sugar.parser import Variable, Constant
from snipts.models import Favorite
from snipts.models import Favorite, Snipt
import hashlib
@ -29,6 +29,19 @@ def snipt_is_favorited_by_user(context, asvar):
return ''
@tag(register, [])
def snipts_count_for_user(context):
user = context['request'].user
if user.is_authenticated():
snipts = Snipt.objects.filter(user=user).values('id').count()
else:
snipts = 0
return snipts
@register.filter
def md5(string):
return hashlib.md5(string.lower()).hexdigest()

View File

@ -1,4 +1,4 @@
{% load compress %}
{% load compress snipt_tags %}
<!DOCTYPE html>
<html lang="en" class="{% block html-class %}{% endblock %}">
@ -263,6 +263,7 @@
{% endif %}
{% if request.user.is_authenticated %}
{% if not debug %}
<script id="IntercomSettingsScriptTag">
var intercomSettings = {
app_id: 'sajf131y',
@ -270,7 +271,11 @@
created_at: {{ request.user.date_joined|date:"U" }},
widget: {
activator: '#IntercomDefaultWidget',
label: 'Support'
label: 'Support Chat'
},
custom_data: {
'snipts count': {% snipts_count_for_user %},
'profile link': 'http://snipt.net/{{ request.user.username }}/'
}
};
</script>
@ -291,5 +296,6 @@
})();
</script>
{% endif %}
{% endif %}
</body>
</html>