Inclusion tag to show new activity,
    either since user was last seen or today (if not last_seen).

    Note that passing in last_seen is up to you.

    Usage: {% show_new_activity %}
    Or, to show since last seen: {% show_new_activity last_seen %}

    Can also cap the number of items returned. Default is 1000.

    Usage: {% show_new_activity last_seen 50 %}

    Allows passing template, controlling level of detail.
    Template choices are:
    * 'plain': simple list
    * 'grouped': items are grouped by content type
    * 'detailed': items are grouped and can use custom template snippets

    Usage: {% show_new_activity last_seen 50 'plain' %}

    If no template choice argument is passed, 'grouped' will be used.

    Also accepts "include" and "exclude" options to control which activities are returned.
    Content types should be passed in by name.

    * 'include' will **only** return passed content types
    * 'exclude' will **not** return passed content types

    Include is evaluated before exclude.

    Usage: {% show_new_activity last_seen 50 'plain' exclude="comment,post" %}

def show_new_activity(last_seen=None, cap=1000, template='grouped', include=None, exclude=None):
    """
    Inclusion tag to show new activity,
    either since user was last seen or today (if not last_seen).

    Note that passing in last_seen is up to you.

    Usage: {% show_new_activity %}
    Or, to show since last seen: {% show_new_activity last_seen %}

    Can also cap the number of items returned. Default is 1000.

    Usage: {% show_new_activity last_seen 50 %}

    Allows passing template, controlling level of detail.
    Template choices are:
    * 'plain': simple list
    * 'grouped': items are grouped by content type
    * 'detailed': items are grouped and can use custom template snippets

    Usage: {% show_new_activity last_seen 50 'plain' %}

    If no template choice argument is passed, 'grouped' will be used.

    Also accepts "include" and "exclude" options to control which activities are returned.
    Content types should be passed in by name.

    * 'include' will **only** return passed content types
    * 'exclude' will **not** return passed content types

    Include is evaluated before exclude.

    Usage: {% show_new_activity last_seen 50 'plain' exclude="comment,post" %}

    """
    if not last_seen or last_seen is '':
        last_seen = datetime.date.today()
    actions = Activity.objects.filter(timestamp__gte=last_seen)

    if include:
        include_types = include.split(',')
        actions = actions.filter(content_type__model__in=include_types)

    if exclude:
        exclude_types = exclude.split(',')
        actions = actions.exclude(content_type__model__in=exclude_types)

    # Now apply cap
    actions = actions[:cap]

    if template=='detailed':
        template = 'activity_monitor/includes/detailed.html'
        actions = group_activities(actions)
    elif template=='grouped':
        template = 'activity_monitor/includes/grouped_list.html'
        actions = group_activities(actions)
    else:
        template = 'activity_monitor/includes/activity_list.html'


    return {'actions': actions, 'selected_template': template}