Пример #1
0
    def get(self):
        channel_json = self.get_argument('channels', None)

        if (not channel_json):
            self.write("Missing channels! Error!")
            self.finish()
            return

        channel_ids = simplejson.loads(channel_json)

        username = self.get_argument('user', None)

        if (not username):
            self.write("Missing username! Error!")
            self.finish()
            return

        user = UserManager.get_user(username)

        if (len(channel_ids) == 0):
            #Disconnecting user
            user.unsubscribe()
            self.on_subscription_change("[]")
        else:
            user.set_callback(self.async_callback(self.on_subscription_change))

            for channel_id in channel_ids:
                channel = ChannelManager.get_channel(channel_id)

                channel.subscribe_user(user)
Пример #2
0
    def get(self):
        channel_json = self.get_argument('channels', None)

        if (not channel_json):
            self.write("Missing channels! Error!")
            self.finish()
            return

        channel_ids = simplejson.loads(channel_json)

        username = self.get_argument('user', None)

        if (not username):
            self.write("Missing username! Error!")
            self.finish()
            return

        user = UserManager.get_user(username)

        if (len(channel_ids) == 0):
            #Disconnecting user
            user.unsubscribe()
            self.on_subscription_change("[]")
        else:
            user.set_callback(self.async_callback(self.on_subscription_change))

            for channel_id in channel_ids:
                channel = ChannelManager.get_channel(channel_id)

                channel.subscribe_user(user)
Пример #3
0
    def get(self):
        channel_values_json = self.get_argument('channels', None)

        if (not channel_values_json):
            self.write("Missing channels! Error!")
            self.finish()
            return

        channel_values = simplejson.loads(channel_values_json)

        #print channel_values

        users_to_notify = dict()

        for channel_dict in channel_values:
            channel_id = channel_dict['id']
            channel_value = channel_dict['value']

            channel = ChannelManager.get_channel(channel_id)

            channel_users = channel.get_users()

            #Deleting users assotiated with channel!
            channel.reset()

            for user in channel_users:
                #Merging response
                user.merge_response(channel_id, channel_value)

                #Storing users to be notified!
                users_to_notify[user.username] = user

        user_keys = users_to_notify.keys()

        for user_key in user_keys:
            user = users_to_notify[user_key]

            #Deleting user subscriptions from all channels!
            user.delete_channels()

            user.notify()
Пример #4
0
    def get(self):
        channel_values_json = self.get_argument('channels', None)

        if (not channel_values_json):
            self.write("Missing channels! Error!")
            self.finish()
            return

        channel_values = simplejson.loads(channel_values_json)

        #print channel_values

        users_to_notify = dict()

        for channel_dict in channel_values:
            channel_id = channel_dict['id']
            channel_value = channel_dict['value']

            channel = ChannelManager.get_channel(channel_id)

            channel_users = channel.get_users()

            #Deleting users assotiated with channel!
            channel.reset()

            for user in channel_users:
                #Merging response
                user.merge_response(channel_id, channel_value)

                #Storing users to be notified!
                users_to_notify[user.username] = user

        user_keys = users_to_notify.keys()

        for user_key in user_keys:
            user = users_to_notify[user_key]

            #Deleting user subscriptions from all channels!
            user.delete_channels()

            user.notify()
Пример #5
0
    def subscribe(self, channel_ids):
        for channel_id in channel_ids:
            channel = ChannelManager.get_channel(id)

            self.channels.append(channel)
            channel.subscribe(self)
Пример #6
0
    def subscribe(self, channel_ids):
        for channel_id in channel_ids:
            channel = ChannelManager.get_channel(id)

            self.channels.append(channel)
            channel.subscribe(self)