Exemple #1
0
    def get_latest_changes(self):

        from mygpo.db.couchdb.podcast_state import podcast_states_for_device

        podcast_states = podcast_states_for_device(self.id)
        for p_state in podcast_states:
            actions = filter(lambda x: x.device == self.id, reversed(p_state.actions))
            if actions:
                yield (p_state.podcast, actions[0])
Exemple #2
0
    def get_subscription_changes(self, since, until):
        """
        Returns the subscription changes for the device as two lists.
        The first lists contains the Ids of the podcasts that have been
        subscribed to, the second list of those that have been unsubscribed
        from.
        """

        from mygpo.db.couchdb.podcast_state import podcast_states_for_device
        podcast_states = podcast_states_for_device(self.id)
        return subscription_changes(self.id, podcast_states, since, until)
Exemple #3
0
def delete_permanently(request, device):

    states = podcast_states_for_device(device.id)
    for state in states:
        remove_device_from_podcast_state(state, device)

    @repeat_on_conflict(['user'])
    def _remove(user, device):
        user.remove_device(device)
        user.save()

    _remove(user=request.user, device=device)

    return HttpResponseRedirect(reverse('devices'))
Exemple #4
0
    def get_subscription_changes(self, device, since, now, domain):
        """ gets new, removed and current subscriptions """

        # DB: get all podcast states for the device
        podcast_states = podcast_states_for_device(device.id)

        add, rem = subscription_changes(device.id, podcast_states, since, now)

        subscriptions = filter(lambda s: s.is_subscribed_on(device), podcast_states)
        # DB get podcast objects for the subscribed podcasts
        subscriptions = podcasts_for_states(subscriptions)

        podcasts = dict( (p.url, p) for p in subscriptions )
        add = [podcast_data(podcasts.get(url), domain) for url in add ]

        return add, rem, subscriptions
Exemple #5
0
    def get_subscription_history(self, device_id=None, reverse=False, public=None):
        """ Returns chronologically ordered subscription history entries

        Setting device_id restricts the actions to a certain device
        """

        from mygpo.db.couchdb.podcast_state import podcast_states_for_user, \
            podcast_states_for_device

        def action_iter(state):
            for action in sorted(state.actions, reverse=reverse):
                if device_id is not None and device_id != action.device:
                    continue

                if public is not None and state.is_public() != public:
                    continue

                entry = HistoryEntry()
                entry.timestamp = action.timestamp
                entry.action = action.action
                entry.podcast_id = state.podcast
                entry.device_id = action.device
                yield entry

        if device_id is None:
            podcast_states = podcast_states_for_user(self)
        else:
            podcast_states = podcast_states_for_device(device_id)

        # create an action_iter for each PodcastUserState
        subscription_action_lists = [action_iter(x) for x in podcast_states]

        action_cmp_key = lambda x: x.timestamp

        # Linearize their subscription-actions
        return linearize(action_cmp_key, subscription_action_lists, reverse)