当前位置: 首页>>代码示例>>Python>>正文


Python Topic.get_by_id方法代码示例

本文整理汇总了Python中models.Topic.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.get_by_id方法的具体用法?Python Topic.get_by_id怎么用?Python Topic.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Topic的用法示例。


在下文中一共展示了Topic.get_by_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: recreate_topic_list_structure

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
def recreate_topic_list_structure():
    import topics_list
    logging.info("recreating topic_list structure")

    version = TopicVersion.get_edit_version()
    root = Topic.get_by_id("root", version)
    delete_topics = recursive_copy_topic_list_structure(root, topics_list.PLAYLIST_STRUCTURE)
    for topic in delete_topics.values():
        topic.delete_tree()
开发者ID:di445,项目名称:server,代码行数:11,代码来源:topics.py

示例2: render_signup

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
 def render_signup(self, topic_id):
     topic = Topic.get_by_id(int(topic_id))
     topic_slots = topic.slots
     user_rsvps = [rsvp.slot.id for rsvp in TopicRSVP.get_for_user(users.get_current_user())]
     slots = []
     for slot in topic_slots:
         slot.rsvp_count = slot.rsvps.count() or 0
         slot.user_rsvped = (slot.id in user_rsvps)
         slots.append(slot)
     slots = sorted(slots, key=lambda slot: slot.start)
     template_values = self.get_template_values()
     template_values['topic'] = topic
     template_values['topic_slots'] = slots
     self.render('signup.html', template_values)
开发者ID:djensenius,项目名称:hangout-scheduler,代码行数:16,代码来源:pages.py

示例3: hide_topics

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
def hide_topics(version):
    from topics_list import topics_list
    logging.info("hiding topics")

    root = Topic.get_by_id("root", version)
    topics = Topic.all().ancestor(root).fetch(10000)
    for topic in topics:
        if topic.title not in topics_list:
            topic.hide = True
            topic.put()
        else:
            topic.hide = False
            topic.put()

    logging.info("hid topics")
    deferred.defer(recreate_topic_list_structure)
开发者ID:di445,项目名称:server,代码行数:18,代码来源:topics.py

示例4: GET

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
    def GET(self, pk=None):
        if pk:
            topic = Topic.get_by_id(pk)
            return json.dumps(topic)

        topics = Topic.get_all()
        result = []
        for t in topics:
            topic = dict(t)
            try:
                user = CACHE_USER[t.owner_id]
            except KeyError:
                user = User.get_by_id(t.owner_id)
                CACHE_USER[t.owner_id] = user
            topic['owner_name'] = user.username
            result.append(topic)
        return json.dumps(result)
开发者ID:fatfan,项目名称:mychat,代码行数:19,代码来源:handlers.py

示例5: load_videos

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
def load_videos(version, title=None):
    root = Topic.get_by_id("root", version)
                    
    if title is None:
        playlist = Playlist.all().order('title').get()
    else:
        playlist = Playlist.all().filter('title = ', title).get()
    
    title = playlist.title
    
    nextplaylist = Playlist.all().filter('title >', title).order('title').get()
    if nextplaylist:
        next_title = nextplaylist.title

    playlists = [playlist]
    # playlists = Playlist.all().order('title').fetch(100000)
    for i, p in enumerate(playlists):
        videos = p.get_videos()
        content_keys = [v.key() for v in videos]
        added = 0
        for i, v in enumerate(videos):
            for e in v.related_exercises():
                if e.key() not in content_keys:
                    content_keys.insert(i + added, e.key())
                    added += 1

        topic = Topic.insert(title=p.title,
                     parent=root,
                     description=p.description,
                     tags=p.tags,
                     child_keys=content_keys)
    
    logging.info("loading " + title)
    
    if nextplaylist:
        deferred.defer(load_videos, version, next_title)
    else:
        deferred.defer(hide_topics, version)
开发者ID:di445,项目名称:server,代码行数:40,代码来源:topics.py

示例6: GET

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
    def GET(self, pk=None):
        if pk:
            topic = Topic.get_by_id(pk)
            topic['created_time'] = display_time(topic['created_time'])
            return json.dumps(topic)

        topics = Topic.get_all()
        result = []
        for t in topics:
            topic = dict(t)
            if 'tags' not in topic:
                topic['tags'] = ''

            try:
                user = CACHE_USER[t.owner_id]
            except KeyError:
                user = User.get_by_id(t.owner_id)
                CACHE_USER[t.owner_id] = user
            topic['owner_name'] = user.username
            topic['created_time'] = display_time(topic['created_time'])

            message = Message.get_latest_by_topic(str(t.id))
            message_count = Message.topic_count(str(t.id))
            if message:
                # 最新回复
                try:
                    user = CACHE_USER[message.user_id]
                except KeyError:
                    user = User.get_by_id(message.user_id)
                    CACHE_USER[message.user_id] = user
                message.user_name = user.username
                message.created_time = pass_time(message.created_time)
            topic['new_comment'] = message
            topic['message_count'] = message_count
            result.append(topic)
        return json.dumps(result)
开发者ID:bb-js,项目名称:bb-js.org,代码行数:38,代码来源:topic.py

示例7: get

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
    def get(self, readable_id=""):

        # This method displays a video in the context of a particular topic.
        # To do that we first need to find the appropriate topic.  If we aren't
        # given the topic title in a query param, we need to find a topic that
        # the video is a part of.  That requires finding the video, given it readable_id
        # or, to support old URLs, it's youtube_id.
        video = None
        topic = None
        video_id = self.request.get('v')
        topic_id = self.request_string('topic', default="")
        readable_id = urllib.unquote(readable_id).decode("utf-8")
        readable_id = re.sub('-+$', '', readable_id)  # remove any trailing dashes (see issue 1140)

        # If either the readable_id or topic title is missing,
        # redirect to the canonical URL that contains them
        redirect_to_canonical_url = False
        if video_id: # Support for old links
            query = Video.all()
            query.filter('youtube_id =', video_id)
            video = query.get()

            if not video:
                raise MissingVideoException("Missing video w/ youtube id '%s'" % video_id)

            readable_id = video.readable_id
            topic = video.first_topic()

            if not topic:
                raise MissingVideoException("No topic has video w/ youtube id '%s'" % video_id)

            redirect_to_canonical_url = True

        if topic_id is not None and len(topic_id) > 0:
            topic = Topic.get_by_id(topic_id)
            key_id = 0 if not topic else topic.key().id()

        # If a topic_id wasn't specified or the specified topic wasn't found
        # use the first topic for the requested video.
        if topic is None:
            # Get video by readable_id just to get the first topic for the video
            video = Video.get_for_readable_id(readable_id)
            if video is None:
                raise MissingVideoException("Missing video '%s'" % readable_id)

            topic = video.first_topic()
            if not topic:
                raise MissingVideoException("No topic has video '%s'" % readable_id)

            redirect_to_canonical_url = True

        exid = self.request_string('exid', default=None)

        if redirect_to_canonical_url:
            qs = {'topic': topic.id}
            if exid:
                qs['exid'] = exid

            urlpath = "/video/%s" % urllib.quote(readable_id)
            url = urlparse.urlunparse(('', '', urlpath, '', urllib.urlencode(qs), ''))
            self.redirect(url, True)
            return

        # If we got here, we have a readable_id and a topic, so we can display
        # the topic and the video in it that has the readable_id.  Note that we don't
        # query the Video entities for one with the requested readable_id because in some
        # cases there are multiple Video objects in the datastore with the same readable_id
        # (e.g. there are 2 "Order of Operations" videos).
        videos = Topic.get_cached_videos_for_topic(topic)
        previous_video = None
        next_video = None
        for v in videos:
            if v.readable_id == readable_id:
                v.selected = 'selected'
                video = v
            elif video is None:
                previous_video = v
            else:
                next_video = v
                break

        # If we're at the beginning or end of a topic, show the adjacent topic.
        # previous_topic/next_topic are the topic to display.
        # previous_video_topic/next_video_topic are the subtopics the videos
        # are actually in.
        previous_topic = None
        previous_video_topic = None
        next_topic = None
        next_video_topic = None

        if not previous_video:
            previous_topic = topic
            while not previous_video:
                previous_topic = previous_topic.get_previous_topic()
                if previous_topic:
                    (previous_video, previous_video_topic) = previous_topic.get_last_video_and_topic()
                else:
                    break

        if not next_video:
#.........这里部分代码省略.........
开发者ID:di445,项目名称:server,代码行数:103,代码来源:main.py

示例8: importIntoVersion

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_by_id [as 别名]
    def importIntoVersion(version):
        logging.info("comparing to version number %i" % version.number)
        topic = Topic.get_by_id("art-history", version)

        if not topic:
            parent = Topic.get_by_id("humanities---other", version)
            if not parent:
                raise Exception("Could not find the Humanities & Other topic to put art history into")
            topic = Topic.insert(title="Art History",
                                 parent=parent,
                                 id="art-history",
                                 standalone_title="Art History",
                                 description="Spontaneous conversations about works of art where the speakers are not afraid to disagree with each other or art history orthodoxy. Videos are made by Dr. Beth Harris and Dr. Steven Zucker along with other contributors.")
        
        urls = topic.get_urls(include_descendants=True)
        href_to_key_dict = dict((url.url, url.key()) for url in urls)
        hrefs = [url.url for url in urls]
        content = getSmartHistoryContent()
        if content is None:
            raise Exception("Aborting import, could not read from smarthistory")

        subtopics = topic.get_child_topics()
        subtopic_dict = dict((t.title, t) for t in subtopics)
        subtopic_child_keys = {}
        
        new_subtopic_keys = []

        child_keys = []
        i = 0
        for link in content:
            href = link["href"]
            title = link["title"]
            parent_title = link["parent"]

            if parent_title not in subtopic_dict:
                subtopic = Topic.insert(title=parent_title,
                                 parent=topic,
                                 standalone_title="Art History: %s" % parent_title,
                                 description="")
                subtopic_dict[parent_title] = subtopic
            else:
                subtopic = subtopic_dict[parent_title]
           
            if subtopic.key() not in new_subtopic_keys:
                new_subtopic_keys.append(subtopic.key())

            if parent_title not in subtopic_child_keys:
                 subtopic_child_keys[parent_title] = []

            if href not in hrefs:
                logging.info("adding %i %s %s to %s" % (i, href, title, parent_title))
                models.VersionContentChange.add_new_content(
                    models.Url, 
                    version,
                    {"title": title,
                     "url": href
                    },
                    ["title", "url"])

                url = Url(url=href,
                          title=title,
                          id=id)
                url.put()
                subtopic_child_keys[parent_title].append(url.key())

            else:
                subtopic_child_keys[parent_title].append(href_to_key_dict[href])

            i += 1

        logging.info("updating child_keys")
        change = False
        for parent_title, child_keys in subtopic_child_keys.iteritems():
            subtopic = subtopic_dict[parent_title]
            if subtopic.child_keys != subtopic_child_keys[parent_title]:
                change = True
                subtopic.update(child_keys=subtopic_child_keys[parent_title])
        
        if topic.child_keys != new_subtopic_keys:    
            change = True
            topic.update(child_keys=new_subtopic_keys)
        
        if change:
            logging.info("finished updating version number %i" % version.number)
        else:
            logging.info("nothing changed")

        return change
开发者ID:johnfelipe,项目名称:server,代码行数:90,代码来源:topics.py


注:本文中的models.Topic.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。