def testSetProgramming(self): collection = Collection(name='test') collection.put() media1 = fake_video(collection, 100) media2 = fake_video(collection, 360) channel = Channel.add('test') ChannelCollection.add(channel=channel, collection=collection) duration = media1[0].duration + 5 programs = Programming.set_programming(channel.id, duration=duration) self.assertEquals(len(programs), 1) self.assertEquals(programs[0].media.last_programmed, programs[0].time) self.assertEquals(programs[0].media.id, media2[0].id) # Check memcache programming = memcache.get('programming') or {} next_programs = Programming.next_programs(programming.get(channel.id), duration=1200, prelude=120) self.assertEquals(len(next_programs), 1) # Schedule second program memcache.set('programming', []) # Sidestep next_program check programs = Programming.set_programming(channel.id, duration=1200) self.assertEquals(len(programs), 1) self.assertEquals(programs[0].media.id, media1[0].id) # Clear memcache memcache.set('programming', []) print programs[0].media.last_programmed programs = Programming.set_programming(channel.id) print programs[0].time
def post(self, cid): channel = Channel.get_by_key_name(cid) if self.current_user.id in SUPER_ADMINS or self.current_user in channel.admins.fetch(None): channel.online = (self.request.get('online') == '1' or self.request.get('online') == 'true') channel.put() if channel.online: Programming.set_programming(channel.id, queue='programming', fetch_twitter=(not constants.DEVELOPMENT)) self.response.out.write(simplejson.dumps(channel.toJson()))
def get(self): channel_name = self.request.get('channel') twitter = self.request.get('fetch') == 'true' duration = self.request.get('duration') or 600 if channel_name: channels = Channel.all().filter('name =', channel_name).fetch(1) else: channels = Channel.get_public() for channel in channels: Programming.set_programming(channel.id, duration=int(duration), fetch_twitter=(not constants.DEVELOPMENT and twitter)) self.response.out.write('done')
def post(self): if self.current_user.id in SUPER_ADMINS and self.request.get('uid'): channel = Channel.get_by_key_name(self.request.get('channel_id')) admin = User.get_by_key_name(self.request.get('uid')) ca = ChannelAdmin(channel=channel, admin=admin) ca.put() self.response.out.write('done') elif self.current_user.id in SUPER_ADMINS: name = self.request.get('name') if name: channel = Channel.get_or_insert(key_name=Channel.make_key(name), name=name) if channel.online: Programming.set_programming(channel.id, queue='programming', fetch_twitter=(not constants.DEVELOPMENT)) self.response.out.write(simplejson.dumps(channel.toJson()))
def post(self): if self.request.get('channel_id'): channel = Channel.get_by_key_name(self.request.get('channel_id')) if self.current_user.id in constants.SUPER_ADMINS or self.current_user in channel.admins.fetch(None): Programming.set_programming(channel.id, queue='programming', schedule_next=False, fetch_twitter=(not constants.DEVELOPMENT))