(history)
Actions that added/removed podcasts from the subscription list

    Returns an iterator of all subscription actions that either
     * added subscribed a podcast that hasn't been subscribed directly
       before the action (but could have been subscribed) earlier
     * removed a subscription of the podcast is not longer subscribed
       after the action

    This method assumes, that no subscriptions exist at the beginning of
    ``history``.
Actions that added/removed podcasts from the subscription list
Actions that added / removed podcasts from the subscription list
def get_subscription_change_history(history):
    """Actions that added/removed podcasts from the subscription list

    Returns an iterator of all subscription actions that either
     * added subscribed a podcast that hasn't been subscribed directly
       before the action (but could have been subscribed) earlier
     * removed a subscription of the podcast is not longer subscribed
       after the action

    This method assumes, that no subscriptions exist at the beginning of
    ``history``.
    """

    # django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
    from mygpo.history.models import HistoryEntry

    subscriptions = collections.defaultdict(int)

    for entry in history:
        if entry.action == HistoryEntry.SUBSCRIBE:
            subscriptions[entry.podcast] += 1

            # a new subscription has been added
            if subscriptions[entry.podcast] == 1:
                yield entry

        elif entry.action == HistoryEntry.UNSUBSCRIBE:
            subscriptions[entry.podcast] -= 1

            # the last subscription has been removed
            if subscriptions[entry.podcast] == 0:
                yield entry
def get_subscription_change_history ( history ) : # django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. from mygpo . history . models import HistoryEntry subscriptions = collections . defaultdict ( int ) for entry in history : if entry . action == HistoryEntry . SUBSCRIBE : subscriptions [ entry . podcast ] += 1 # a new subscription has been added if subscriptions [ entry . podcast ] == 1 : yield entry elif entry . action == HistoryEntry . UNSUBSCRIBE : subscriptions [ entry . podcast ] -= 1 # the last subscription has been removed if subscriptions [ entry . podcast ] == 0 : yield entry