Source

django-fitlog / fitlog / templatetags / fitlog_tags.py

Full commit
from django.template import Library

from fitlog.models import FitLog
from django.contrib.auth.models import User

register = Library()

@register.inclusion_tag('fitlog/tags/list_logs.html',takes_context=True)
def list_recent_logs(context):
    fit_logs = FitLog.objects.latest()   
    return { 'fit_logs' : fit_logs,"request":context['request'] }

@register.inclusion_tag('fitlog/tags/list_logs.html',takes_context=True)
def list_user_logs(context,username):
    try:
        user = User.objects.get(username=username)
        fit_logs = FitLog.objects.by_member(user)   
        return { 'fit_logs' : fit_logs,"request":context['request'] }
    except User.DoesNotExist:
        pass
    return {"request":context['request']}

@register.inclusion_tag('fitlog/tags/stats.html',takes_context=True)
def stats(context):
    num_logs = FitLog.objects.number_of_logs()
    num_members = User.objects.filter(is_active=True).count()  
    return { 'num_logs' : num_logs,'num_members':num_members, "request":context['request'] }

@register.inclusion_tag('fitlog/tags/weight_training_list.html')
def weight_training_list(fitlog): 
    return { 'fitlog' : fitlog}

@register.inclusion_tag('fitlog/tags/cardio_list.html')
def cardio_list(fitlog): 
    return { 'fitlog' : fitlog}

@register.inclusion_tag('fitlog/tags/fitlog_detail.html')
def view_fitlog_detail(fitlog): 
    return { 'fitlog' : fitlog}