(history)
return subscribe, unsubscribe
Calculates a diff of subscriptions based on a history (sub/unsub)
Calculates a diff of subscriptions based on a history (sub/unsub)
Calculates a diff of subscriptions based on a history ( sub / unsub )
def subscription_diff(history):
    """Calculates a diff of subscriptions based on a history (sub/unsub)"""

    # 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

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

    subscribe = [podcast for (podcast, value) in subscriptions.items() if value > 0]
    unsubscribe = [podcast for (podcast, value) in subscriptions.items() if value < 0]

    return subscribe, unsubscribe
def subscription_diff ( 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 elif entry . action == HistoryEntry . UNSUBSCRIBE : subscriptions [ entry . podcast ] -= 1 subscribe = [ podcast for ( podcast , value ) in subscriptions . items ( ) if value > 0 ] unsubscribe = [ podcast for ( podcast , value ) in subscriptions . items ( ) if value < 0 ] return subscribe , unsubscribe