def insert_keyword(posts, r_indexes, site_id): """ キーワード情報を投稿に付与 keywordデータをDBに一括登録 :param posts: dict{int: Posted} :param r_indexes: list(KeywordReverseIndex) :param site_id: int :rtype : list(Keyword) """ # キーワード情報を投稿に付与 keywords = [] for r_index in r_indexes: r_index.insert_keyword_info() keywords.append(r_index.keyword) # DBに一括登録 keyword_records = Keyword.register(site_id, keywords) # r_indexにkeyword_idを登録 keyword_records_dict = { record.keyword: record for record in keyword_records } for r_index in r_indexes: record = keyword_records_dict[r_index.keyword] r_index.extend_keyword_record(record)
def keyword(site, keyword_id, start_keyword_id): _limit = 25 # パラメータチェック keyword_id = int(keyword_id) start_keyword_id = int(start_keyword_id) keyword = Keyword.get(keyword_id) if start_keyword_id == 100000000: keyword_relation = PageKeywordRelation.get_from_new_keyword(keyword_id, _limit=_limit) else: keyword_relation = PageKeywordRelation.get_from_keyword(keyword_id, start_keyword_id, _limit=_limit) # pageが公開可能かチェックする now = datetime.datetime.now(tz=pytz.utc) keyword_relation = [r for r in keyword_relation if r.page.is_enable(now=now)] is_end = False if len(keyword_relation) >= 2: pages = [r.page for r in keyword_relation] contents = pages[0] prev_contents = pages[1] is_next = keyword_relation[1].id relations = keyword_relation[2:] elif len(keyword_relation) == 1: pages = [r.page for r in keyword_relation] contents = pages[0] prev_contents = None is_next = None is_end = True relations = keyword_relation[2:] else: contents = None prev_contents = None is_next = None relations = None return render_template('dat/keyword.html', site=site, keyword=keyword, contents=contents, prev_contents=prev_contents, relations=relations, is_next=is_next, is_end=is_end)
def insert_keyword(posts, r_indexes, site_id): """ キーワード情報を投稿に付与 keywordデータをDBに一括登録 :param posts: dict{int: Posted} :param r_indexes: list(KeywordReverseIndex) :param site_id: int :rtype : list(Keyword) """ # キーワード情報を投稿に付与 keywords = [] for r_index in r_indexes: r_index.insert_keyword_info() keywords.append(r_index.keyword) # DBに一括登録 keyword_records = Keyword.register(site_id, keywords) # r_indexにkeyword_idを登録 keyword_records_dict = {record.keyword: record for record in keyword_records} for r_index in r_indexes: record = keyword_records_dict[r_index.keyword] r_index.extend_keyword_record(record)
def keywords(self): """ :return: list(Keyword) """ words = [Keyword.get(_id) for _id in self._keyword_ids] if not words: return [] # countが2以下のものは非表示 words = [w for w in words if w.count > 2] if not words: return [] # page relationが存在しない場合は非表示 words = [w for w in words if w.is_enable] if not words: return [] # 並び替えて6個返却 words = sorted(words, key=lambda x: x.id, reverse=True) words = sorted(words, key=lambda x: x.count, reverse=True) if words: return words[:6] return []