Example #1
0
def write_to_db(lesson_name,
                description,
                section_name,
                url,
                slug="",
                modified_date="Empty",
                url_description="Empty",
                type="text"):

    if "добро" in section_name.lower():
        check_columns_list = [lesson_name, description]
        if "Windows" in check_columns_list or "Mac OS" in check_columns_list or "Linux" in check_columns_list:
            return False

    url_exist = Content.query.filter(Content.url == url).count()
    if type == "text":
        url_description_exist = Content.query.filter(
            Content.url_description == url_description).count()
        print(f"description exist is {bool(url_description_exist)}")
        print(f"url_exist is {bool(url_exist)}")
        if not url_description_exist and not url_exist:
            content = Content(lesson_name=lesson_name,
                              description=description,
                              section_name=section_name,
                              type=type,
                              url_description=url_description,
                              url=url,
                              modified_date=modified_date,
                              slug=slug)
            db.session.add(content)
            db.session.commit()
    else:
        print(f"url_exist is {bool(url_exist)}")
        if not url_exist:
            content = Content(lesson_name=lesson_name,
                              description=description,
                              section_name=section_name,
                              type=type,
                              url_description=url_description,
                              url=url,
                              modified_date=modified_date,
                              slug=slug)
            db.session.add(content)
            db.session.commit()
        else:
            print(lesson_name + " | " + slug + " | " + url)
Example #2
0
    def common(page_slug):
        get_user_id = current_user.get_id()
        user_by_id = Users.query.filter_by(id=get_user_id).first()

        g.username = user_by_id.username
        g.role = user_by_id.role
        g.avatar = user_by_id.avatar

        page_content = Content.query.with_entities(
            Content.description, Content.type, Content.url,
            Content.lesson_name,
            Content.url_description).filter(Content.slug != "").filter(
                (or_(Content.section_name.ilike('%первой%'),
                     Content.section_name.ilike('%2 недели%'),
                     Content.section_name.ilike('%окружение%')))).filter(
                         Content.slug == page_slug).distinct()

        page = Content.query.with_entities(
            Content.slug).filter(Content.slug == page_slug).first()
        if not page:
            return 'Not found', 404

        return render_template(f'/common/{page.slug}.html',
                               page_content=page_content,
                               username=g.username,
                               role=g.role,
                               common_menu=Content.common_menu(),
                               web_menu=Content.web_menu(),
                               ds_menu=Content.ds_menu(),
                               bot_menu=Content.bot_menu(),
                               deploy_menu=Content.deploy_menu(),
                               add_menu=Content.add_menu())
Example #3
0
    def start():
        get_user_id = current_user.get_id()
        user_by_id = Users.query.filter_by(id=get_user_id).first()

        g.username = user_by_id.username
        g.role = user_by_id.role
        g.avatar = user_by_id.avatar
        return render_template('start.html',
                               username=g.username,
                               role=g.role,
                               common_menu=Content.common_menu(),
                               web_menu=Content.web_menu(),
                               ds_menu=Content.ds_menu(),
                               bot_menu=Content.bot_menu(),
                               deploy_menu=Content.deploy_menu(),
                               add_menu=Content.add_menu())
Example #4
0
    def add(page_slug):
        get_user_id = current_user.get_id()
        user_by_id = Users.query.filter_by(id=get_user_id).first()

        g.username = user_by_id.username
        g.role = user_by_id.role
        g.avatar = user_by_id.avatar

        page = Content.query.with_entities(
            Content.slug).filter(Content.slug == page_slug).first()
        if not page:
            return 'Not found', 404

        return render_template(f'/add/{page.slug}.html',
                               username=g.username,
                               role=g.role,
                               page_content=Content.page_content(page_slug),
                               common_menu=Content.common_menu(),
                               web_menu=Content.web_menu(),
                               ds_menu=Content.ds_menu(),
                               bot_menu=Content.bot_menu(),
                               deploy_menu=Content.deploy_menu(),
                               add_menu=Content.add_menu())
Example #5
0
    def index():
        get_user_id = current_user.get_id()
        user_by_id = Users.query.filter_by(id=get_user_id).first()

        g.username = user_by_id.username
        g.role = user_by_id.role
        g.avatar = user_by_id.avatar

        news_list = News.query.order_by(News.published.desc()).all()
        habr_list = Articles.query.filter_by(source="habr").all()
        tproger_list = Articles.query.filter_by(source="tproger").all()

        return render_template('index.html',
                               news_list=news_list,
                               habr_list=habr_list,
                               tproger_list=tproger_list,
                               username=g.username,
                               role=g.role,
                               common_menu=Content.common_menu(),
                               web_menu=Content.web_menu(),
                               ds_menu=Content.ds_menu(),
                               bot_menu=Content.bot_menu(),
                               deploy_menu=Content.deploy_menu(),
                               add_menu=Content.add_menu())