Example #1
0
    def list_problems_order_by_lid_asc(page, page_size, difficulty=100, is_locked=100, type=100):
        """
        根据题号升序
        :param difficulty:
        :param is_locked:
        :param type:
        :return:
        """
        if page <= 0 or page_size <= 0:
            raise ServiceException(ErrorCode.PARAM_ERROR, u'page或者page_size参数错误')
        # 过滤
        filter_list = []
        if difficulty in LeetcodeProblem.Difficulty.ALL.value:
            filter_list.append(LeetcodeProblem.difficulty == difficulty)
        if is_locked in LeetcodeProblem.IsLocked.ALL.value:
            filter_list.append(LeetcodeProblem.is_locked == is_locked)
        if type in LeetcodeProblem.Type.ALL.value:
            filter_list.append(LeetcodeProblem.type == type)

        cnt = ProblemService.count_problems_by(difficulty, is_locked, type)
        page_util = PageUtil(page, page_size, cnt)

        res = LeetcodeProblem.query.filter(*filter_list).order_by(LeetcodeProblem.lid.asc()).slice(
            page_util.get_start(), page_util.get_end()).all()

        page_util.data = models2dict(res)

        for data in page_util.data:
            del data['code_def']
            del data['desc']

        return page_util
Example #2
0
def search(content):
    companies = ProblemService.list_companies_order_by_problem_cnt()
    try:
        problem = ProblemService.get_problem_by_lid(content)
        return render_template('search.html',
                               problems=[model2dict(problem)],
                               companies=companies)
    except Exception as e:
        problems = ProblemService.search_problems_by_title(content)
        problems.extend(ProblemService.search_problems_by_content(content))
        return render_template('search.html',
                               problems=models2dict(problems),
                               companies=companies)
def list_drafts():
    posts = PostService.list_drafts()
    posts = models2dict(posts)
    for post in posts:
        del post['content']
        post['category'] = GroupService.get_category_by_id(
            post['category_id']).name
        tags_str = post['tag_ids']
        tags = tags_str.split(",")
        L = []
        if tags_str is not None and tags_str != '':
            for tag_id in tags:
                tag_id = int(tag_id)
                tag_name = GroupService.get_tag_by_id(tag_id).name
                L.append(tag_name)
        post['tags'] = L
    return jsonify(json_resp(data=posts))
Example #4
0
    def list_problems_by_company_name(name, page, page_size, difficulty=100, is_locked=100, type=100):
        """
        根据公司名称查询题目信息
        :param name:
        :param page:
        :param page_size:
        :param difficulty:
        :param is_locked:
        :param type:
        :return:
        """

        if page <= 0 or page_size <= 0:
            raise ServiceException(ErrorCode.PARAM_ERROR, u'page或者page_size参数错误')

        # 查询公司的题目信息
        problems = db.session.query(LeetcodeTagInfo.questions).filter(LeetcodeTagInfo.name == name).first()[0]
        problems = problems[1:len(problems) - 1].split(',')
        problems = map(lambda qid: int(qid), problems)

        problems.sort()
        problems = tuple(problems)
        # 过滤
        filter_list = [LeetcodeProblem.qid.in_(problems)]
        if difficulty in LeetcodeProblem.Difficulty.ALL.value:
            filter_list.append(LeetcodeProblem.difficulty == difficulty)
        if is_locked in LeetcodeProblem.IsLocked.ALL.value:
            filter_list.append(LeetcodeProblem.is_locked == is_locked)
        if type in LeetcodeProblem.Type.ALL.value:
            filter_list.append(LeetcodeProblem.type == type)

        cnt = len(LeetcodeProblem.query.filter(*filter_list).order_by(LeetcodeProblem.frequency.desc()).all())

        page_util = PageUtil(page, page_size, cnt)

        res = LeetcodeProblem.query.filter(*filter_list).order_by(LeetcodeProblem.frequency.desc()).slice(
            page_util.get_start(),
            page_util.get_end()).all()

        page_util.data = models2dict(res)

        for data in page_util.data:
            del data['code_def']
            del data['desc']

        return page_util
Example #5
0
def list_categories():
    categories = GroupService.list_categories()
    categories = models2dict(categories)

    return jsonify(json_resp(data=categories))
Example #6
0
def list_tags():
    tags = GroupService.list_tags()
    tags = models2dict(tags)
    return jsonify(json_resp(data=tags))