예제 #1
0
def get_videos_model_in_channel(channel_id):
    key = _channel_key(channel_id)
    q = VideoModel.all()
    q.ancestor(key)
    q.order("-final_score")
    videos = q.fetch(limit=MAX_CHANNEL_SIZE)
    return models.to_dict_array(videos)
예제 #2
0
    def get(self):
        channel_id = self.request.get("channel_id")
        
        values = {}

        if channel_id:
            offset, limit = handlers.parse_offset_and_limit(self)
            videos = data_source.get_videos_model_in_channel(channel_id, offset, limit)
            channel = data_source.get_channel(channel_id)
            if channel:
                values["channel"] = channel

                # If delete is set we will delete all the channel as well as its videos.
                delete = self.request.get("delete")
                if delete == "true":
                    q = VideoModel.all()
                    q.ancestor(channel)
                    for video in q:
                        video.delete()
                    channel.delete()
                    self.redirect(router_path["admin_channel_list"])
                    return


            if videos:
                values["videos"] = videos
            values["offset"] = offset
            values["limit"] = limit
        self.render("ChannelUpdate.html", values)
예제 #3
0
def get_video_by_external_id(source, external_id):
    q = VideoModel.all()
    q.filter("external_id =", external_id)
    q.filter("source =", source)
    result = q.fetch(1)
    if result:
        return result[0]
    return None
예제 #4
0
 def post(self):
     channel_id = self.request.get("channel_id")
     video_id = self.request.get("video_id")
     channel = data_source.get_channel(channel_id)
     video = data_source.get_video(channel_id, video_id)
     if channel:
         title = self.request.get("title")
         cover_img = self.request.get("cover_img")
         video_url = self.request.get("video_url")
         editor_score = int(self.request.get("editor_score"))
         if not video:
             video = VideoModel(parent = channel, title = title, cover_img = cover_img, video_url = video_url, editor_score = editor_score)
         else:
             video.title = title
             video.cover_img = cover_img
             video.video_url = video_url
             video.editor_score = editor_score
         video.calculate_score()
         video.put()
         self.redirect(router_path["admin_channel_update"] + "?channel_id=%s" % (channel_id))
         return self.get()
     else:
         self.response.out.write("channel not exist")