コード例 #1
0
ファイル: search.py プロジェクト: RTNelo/dev_blog
    def post(self, *args):
        try:
            keywords = self.get_argument('keywords')
        except:
            keywords = None

        if keywords is not None:
            Calculate.search_add_keyword(keywords)
            try:
                categories = Category.get()
                cate_result = Category.find_by_name(keywords)
                tag_result = Tag.find_by_name(keywords)
            except Exception as e:
                self.send_error(404)
                send_error_email('Search Error', str(e))

            try:
                C = cate_result['diaries']
            except:
                C = []

            try:
                T = tag_result['diaries']
            except:
                T = []

            real_result = list(C+T)

            """
                To combine tag_result and category_result
                first make an empty list to save filtered_result
                and to make faster, make another empty list to save diary_id to ensure not append repeat diary
            """

            filtered_result = []
            cache_did = []

            for i in real_result:
                if cache_did == []:
                    cache_did.append(i['did'])
                    filtered_result.append(i)
                else:
                    if i['did'] not in cache_did:
                        cache_did.append(i['did'])
                        filtered_result.append(i)

            profile = Account.get()

            if filtered_result != []:
                self.render('Search/result.html', detail=filtered_result, categories=categories, profile=profile)
            else:
                filtered_result = None
                self.render('Search/result.html', detail=filtered_result, categories=categories, profile=profile)
        else:
            self.redirect('/')
コード例 #2
0
ファイル: tag.py プロジェクト: Daniel7725/Dev_Blog
    def get(self, name):
        try:
            categories = Category.get()
            detail = Tag.find_by_name(name)
        except Exception as e:
            self.send_error(404)
            send_error_email('Tag List Error', str(e))

        L = detail['diaries']
        sorted_diaries = sorted(L, key=itemgetter('did'), reverse=True)
        if detail is not None:
            profile = Account.get()
            self.render('Tag/list.html', detail=detail, categories=categories, profile=profile, sorted_diaries=sorted_diaries)
        else:
            self.send_error(404)