Exemplo n.º 1
0
    def group(self):
        """
        get a django channels Group consisting of all the
        reply_channels in the QuerySet
        """
        self._channel_names = self.values_list('channel_name', flat=True)

        if not self._channel_names:
            empty_group = Group('emptyname')
            empty_group.empty = True
            return empty_group

        # group name is the hash of all the channel_names
        combined_names = b''.join(
            i.encode('utf-8', errors='replace') for i in self._channel_names)
        group_id = md5(combined_names).hexdigest()
        combined_group = Group(name=group_id)

        for channel_name in self._channel_names:
            if channel_name.startswith('bot-'):
                continue
            combined_group.add(Channel(channel_name))
        return combined_group