<commit_before>from flask import render_template, url_for, session, redirect

from project.admin.forms import VacancyForm, CategoryForm, CityForm, \
    PageChunkForm
from project.blueprints import admin_app
from project.pages.forms import PageBlockForm, PageForm
from project.pages.utils import PageDetail
from project.admin.utils import EntryDetail, EntryList
from project.auth.forms import RegisterForm
from project.models import Vacancy, Category, City, User, PageBlock, Page, \
    PageChunk

SECTIONS = {}  # list_name: list_endpoint


@admin_app.before_request
def check_user_logged_in():
    if 'user_id' in session:
        return

    return redirect(url_for("auth.login"))


def register_section(*, section_name, list_endpoint,
                     list_route, detail_route,
                     list_view, detail_view):
    admin_app.add_url_rule(list_route, view_func=list_view)

    admin_app.add_url_rule(
        detail_route + "<int:entry_id>/",
        view_func=detail_view,
    )

    admin_app.add_url_rule(
        detail_route,
        defaults={'entry_id': None},
        view_func=detail_view,
    )

    SECTIONS[section_name] = list_endpoint


# Vacancies
vacancy_list = EntryList.as_view(
    name='vacancy_list',
    model=Vacancy,
    template="admin/vacancies.html",
)

vacancy_detail = EntryDetail.as_view(
    name='vacancy_detail',
    create_form=VacancyForm,
    model=Vacancy,
    template="admin/vacancy.html",
    success_url="vacancy_list",
)

register_section(
    section_name="Вакансии",
    list_route="/vacancies/",
    detail_route="/vacancy/",
    list_view=vacancy_list,
    detail_view=vacancy_detail,
    list_endpoint="vacancy_list",
)


# Categories
category_list = EntryList.as_view(
    name="category_list",
    model=Category,
    template="admin/categories.html",
)

category_detail = EntryDetail.as_view(
    name='category_detail',
    create_form=CategoryForm,
    model=Category,
    success_url="category_list",
)

register_section(
    section_name="Категории",
    list_route="/categories/",
    detail_route="/category/",
    list_view=category_list,
    detail_view=category_detail,
    list_endpoint="category_list",
)


# Cities
city_list = EntryList.as_view(
    name="city_list",
    model=City,
    template="admin/cities.html",
)
city_view = EntryDetail.as_view(
    name='city_detail',
    create_form=CityForm,
    model=City,
    success_url="city_list",
)

register_section(
    section_name="Города",
    list_route="/cities/",
    detail_route="/city/",
    list_view=city_list,
    detail_view=city_view,
    list_endpoint="city_list",
)


# Users
user_list = EntryList.as_view(
    name="user_list",
    model=User,
    template="admin/users.html",
)

user_detail = EntryDetail.as_view(
    name='user_detail',
    create_form=RegisterForm,
    model=User,
    success_url="user_list",
)

register_section(
    section_name="Пользователи",
    list_route="/users/",
    detail_route="/user/",
    list_view=user_list,
    detail_view=user_detail,
    list_endpoint="user_list",
)


# PageBlocks
pageblock_list = EntryList.as_view(
    name='pageblock_list',
    model=PageBlock,
    template="admin/pageblocks.html",
)

pageblock_view = EntryDetail.as_view(
    name='pageblock_detail',
    create_form=PageBlockForm,
    model=PageBlock,
    success_url="pageblocks_list",
)

register_section(
    section_name="Блоки страниц",
    list_route="/blocks/",
    detail_route="/block/",
    list_view=pageblock_list,
    detail_view=pageblock_view,
    list_endpoint="pageblock_list",
)


# Pages
page_list = EntryList.as_view(
    name="page_list",
    model=Page,
    template="admin/pages.html",
)

page_view = PageDetail.as_view(
    name='page_detail',
    create_form=PageForm,
    model=Page,
    success_url="page_list",<commit_msg>Fixed bug with incorrect url route in admin pageblock<commit_after>from flask import render_template, url_for, session, redirect

from project.admin.forms import VacancyForm, CategoryForm, CityForm, \
    PageChunkForm
from project.blueprints import admin_app
from project.pages.forms import PageBlockForm, PageForm
from project.pages.utils import PageDetail
from project.admin.utils import EntryDetail, EntryList
from project.auth.forms import RegisterForm
from project.models import Vacancy, Category, City, User, PageBlock, Page, \
    PageChunk

SECTIONS = {}  # list_name: list_endpoint


@admin_app.before_request
def check_user_logged_in():
    if 'user_id' in session:
        return

    return redirect(url_for("auth.login"))


def register_section(*, section_name, list_endpoint,
                     list_route, detail_route,
                     list_view, detail_view):
    admin_app.add_url_rule(list_route, view_func=list_view)

    admin_app.add_url_rule(
        detail_route + "<int:entry_id>/",
        view_func=detail_view,
    )

    admin_app.add_url_rule(
        detail_route,
        defaults={'entry_id': None},
        view_func=detail_view,
    )

    SECTIONS[section_name] = list_endpoint


# Vacancies
vacancy_list = EntryList.as_view(
    name='vacancy_list',
    model=Vacancy,
    template="admin/vacancies.html",
)

vacancy_detail = EntryDetail.as_view(
    name='vacancy_detail',
    create_form=VacancyForm,
    model=Vacancy,
    template="admin/vacancy.html",
    success_url="vacancy_list",
)

register_section(
    section_name="Вакансии",
    list_route="/vacancies/",
    detail_route="/vacancy/",
    list_view=vacancy_list,
    detail_view=vacancy_detail,
    list_endpoint="vacancy_list",
)


# Categories
category_list = EntryList.as_view(
    name="category_list",
    model=Category,
    template="admin/categories.html",
)

category_detail = EntryDetail.as_view(
    name='category_detail',
    create_form=CategoryForm,
    model=Category,
    success_url="category_list",
)

register_section(
    section_name="Категории",
    list_route="/categories/",
    detail_route="/category/",
    list_view=category_list,
    detail_view=category_detail,
    list_endpoint="category_list",
)


# Cities
city_list = EntryList.as_view(
    name="city_list",
    model=City,
    template="admin/cities.html",
)
city_view = EntryDetail.as_view(
    name='city_detail',
    create_form=CityForm,
    model=City,
    success_url="city_list",
)

register_section(
    section_name="Города",
    list_route="/cities/",
    detail_route="/city/",
    list_view=city_list,
    detail_view=city_view,
    list_endpoint="city_list",
)


# Users
user_list = EntryList.as_view(
    name="user_list",
    model=User,
    template="admin/users.html",
)

user_detail = EntryDetail.as_view(
    name='user_detail',
    create_form=RegisterForm,
    model=User,
    success_url="user_list",
)

register_section(
    section_name="Пользователи",
    list_route="/users/",
    detail_route="/user/",
    list_view=user_list,
    detail_view=user_detail,
    list_endpoint="user_list",
)


# PageBlocks
pageblock_list = EntryList.as_view(
    name='pageblock_list',
    model=PageBlock,
    template="admin/pageblocks.html",
)

pageblock_view = EntryDetail.as_view(
    name='pageblock_detail',
    create_form=PageBlockForm,
    model=PageBlock,
    success_url="pageblock_list",
)

register_section(
    section_name="Блоки страниц",
    list_route="/blocks/",
    detail_route="/block/",
    list_view=pageblock_list,
    detail_view=pageblock_view,
    list_endpoint="pageblock_list",
)


# Pages
page_list = EntryList.as_view(
    name="page_list",
    model=Page,
    template="admin/pages.html",
)

page_view = PageDetail.as_view(
    name='page_detail',
    create_form=PageForm,
    model=Page,
    success_url="page_list",
{'fraction_non_alphanumeric': 0.11156001563925452, 'fraction_numerical': 0.0, 'mean_word_length': 4.0720423000660935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4855507', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2549, 'n_words': 385}