Skip to content

Commit

Permalink
Add get_user_favorite_count template tag
Browse files Browse the repository at this point in the history
Add tag to get a users favorites count for the toolbar. This is a stopgap
measure to make sure the value is correct, longer-term we can implement
this as a JS callback on the dynamic updated page to prevent the query.
  • Loading branch information
mfitzp committed Aug 26, 2015
1 parent dc050eb commit 4c3be4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 1 addition & 6 deletions wooey/templates/wooey/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@

{% if request.user.is_authenticated %}
<li class="dropdown" id="job-list-user">
<a href="{% url 'wooey:scrapbook' %}" role="button" aria-haspopup="true" aria-expanded="false">Scrapbook <span class="badge scrapbook-badge" id="favorite-wooey-wooeyfile-count">0</span></a>
<a href="{% url 'wooey:scrapbook' %}" role="button" aria-haspopup="true" aria-expanded="false">Scrapbook <span class="badge scrapbook-badge" id="favorite-wooey-wooeyfile-count">{% get_user_favorite_count request.user 'wooey' 'wooeyfile' %}</span></a>
</li>

<li><a href="{% url 'wooey:profile_home' %}"><span class="glyphicon glyphicon-user"> </span> {{ request.user.username }}</a></li>
Expand Down Expand Up @@ -706,7 +706,6 @@
data.model = identifiers[1];
data.pk = identifiers[2];

console.log(data);
$.ajax({
url: '/favorite/toggle',
data: data,
Expand All @@ -715,7 +714,6 @@
cache: false,
success: function(data){
/* Act on result */
console.log('#favorite-' + identifer)
if(data.is_favorite){
$('#favorite-' + identifer).addClass('panel-warning is-favorite');
$('#favorite-' + identifer).removeClass('panel-default');
Expand All @@ -724,7 +722,6 @@
$('#favorite-' + identifer).removeClass('panel-warning is-favorite');
}

console.log('#favorite-' + data.app_label + '-' + data.model + '-count')
$('#favorite-' + data.app + '-' + data.model + '-count').text(data.count);

}
Expand All @@ -733,12 +730,10 @@
return false;
}


$(document).ready(function(){

$("a[data-favorite]").click(toggleFavorite);


$(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
event.preventDefault();
$(this).ekkoLightbox();
Expand Down
10 changes: 10 additions & 0 deletions wooey/templatetags/wooey_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@


register = template.Library()
@register.simple_tag
def get_user_favorite_count(user, app, model):
from ..models import Favorite
ctype = ContentType.objects.get(app_label=app, model=model)
# Return the current total number for UI updates
favorites_count = Favorite.objects.filter(content_type=ctype, user=user).count()
return str(favorites_count)

@register.simple_tag
def get_wooey_setting(name):
return getattr(wooey_settings, name, "")
Expand Down Expand Up @@ -96,3 +104,5 @@ def gravatar(parser, token):
raise template.TemplateSyntaxError("%r tag requires email and size arguments" % token.contents.split()[0])

return GravatarUrlNode(email, size)


0 comments on commit 4c3be4e

Please sign in to comment.