<commit_before>from collections import namedtuple

from couchdbkit.ext.django.schema import *

from mygpo.core.models import Podcast, SubscriptionException
from mygpo.log import log
from mygpo.db.couchdb.podcast import podcasts_to_dict


GroupedDevices = namedtuple('GroupedDevices', 'is_synced devices')



class SyncedDevicesMixin(DocumentSchema):
    """ Contains the device-syncing functionality of a user """

    sync_groups = ListProperty()


    def get_grouped_devices(self):
        """ Returns groups of synced devices and a unsynced group """

        indexed_devices = dict( (dev.id, dev) for dev in self.active_devices )

        for group in self.sync_groups:

            yield GroupedDevices(
                    True,
                    [indexed_devices.pop(device_id) for device_id in group]
                )

        # un-synced devices
        yield GroupedDevices(
                False,
                indexed_devices.values()<commit_msg>fix exception when iterating grouped devices<commit_after>from collections import namedtuple

from couchdbkit.ext.django.schema import *

from mygpo.core.models import Podcast, SubscriptionException
from mygpo.log import log
from mygpo.db.couchdb.podcast import podcasts_to_dict


GroupedDevices = namedtuple('GroupedDevices', 'is_synced devices')



class SyncedDevicesMixin(DocumentSchema):
    """ Contains the device-syncing functionality of a user """

    sync_groups = ListProperty()


    def get_grouped_devices(self):
        """ Returns groups of synced devices and a unsynced group """

        indexed_devices = dict( (dev.id, dev) for dev in self.active_devices )

        for group in self.sync_groups:

            devices = [indexed_devices.pop(device_id, None) for device_id in group]
            devices = filter(None, devices)
            if not devices:
                continue

            yield GroupedDevices(
                    True,
                    devices
                )

        # un-synced devices
        yield GroupedDevices(
                False,
                indexed_devices.values()
{'fraction_non_alphanumeric': 0.0692785475394171, 'fraction_numerical': 0.0, 'mean_word_length': 2.4958263772954923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178358', 'n_tokens_mistral': 590, 'n_tokens_neox': 556, 'n_words': 158}