Files
bricktracker
sql
views
admin
__init__.py
admin.py
checkbox.py
database.py
image.py
instructions.py
retired.py
theme.py
__init__.py
add.py
error.py
exceptions.py
index.py
instructions.py
login.py
minifigure.py
part.py
set.py
upload.py
wish.py
__init__.py
app.py
config.py
configuration.py
configuration_list.py
exceptions.py
fields.py
instructions.py
instructions_list.py
login.py
minifigure.py
minifigure_list.py
navbar.py
part.py
part_list.py
rebrickable.py
rebrickable_image.py
rebrickable_minifigures.py
rebrickable_parts.py
rebrickable_set.py
rebrickable_set_list.py
record.py
record_list.py
reload.py
retired.py
retired_list.py
set.py
set_checkbox.py
set_checkbox_list.py
set_list.py
socket.py
sql.py
sql_counter.py
sql_migration.py
sql_migration_list.py
sql_stats.py
theme.py
theme_list.py
version.py
wish.py
wish_list.py
docs
static
templates
.dockerignore
.env.sample
.gitignore
Dockerfile
LICENSE
README.md
__init__.py
app.py
compose.legacy.yml
compose.local.yaml
compose.yaml
entrypoint.sh
requirements.txt
test-server.sh
BrickTracker/bricktracker/views/admin/admin.py

105 lines
3.5 KiB
Python

import logging
from flask import Blueprint, request, render_template
from flask_login import login_required
from ...configuration_list import BrickConfigurationList
from ..exceptions import exception_handler
from ...instructions_list import BrickInstructionsList
from ...rebrickable_image import RebrickableImage
from ...retired_list import BrickRetiredList
from ...set_checkbox import BrickSetCheckbox
from ...set_checkbox_list import BrickSetCheckboxList
from ...sql_counter import BrickCounter
from ...sql import BrickSQL
from ...theme_list import BrickThemeList
logger = logging.getLogger(__name__)
admin_page = Blueprint('admin', __name__, url_prefix='/admin')
# Admin
@admin_page.route('/', methods=['GET'])
@login_required
@exception_handler(__file__)
def admin() -> str:
brickset_checkboxes: list[BrickSetCheckbox] = []
database_counters: list[BrickCounter] = []
database_exception: Exception | None = None
database_upgrade_needed: bool = False
database_version: int = -1
nil_minifigure_name: str = ''
nil_minifigure_url: str = ''
nil_part_name: str = ''
nil_part_url: str = ''
# This view needs to be protected against SQL errors
try:
database = BrickSQL(failsafe=True)
database_upgrade_needed = database.upgrade_needed()
database_version = database.version
database_counters = BrickSQL().count_records()
brickset_checkboxes = BrickSetCheckboxList().list(all=True)
except Exception as e:
database_exception = e
# Warning
logger.warning('A database exception occured while loading the admin page: {exception}'.format( # noqa: E501
exception=str(e),
))
nil_minifigure_name = RebrickableImage.nil_minifigure_name()
nil_minifigure_url = RebrickableImage.static_url(
nil_minifigure_name,
'MINIFIGURES_FOLDER'
)
nil_part_name = RebrickableImage.nil_name()
nil_part_url = RebrickableImage.static_url(
nil_part_name,
'PARTS_FOLDER'
)
open_checkbox = request.args.get('open_checkbox', None)
open_image = request.args.get('open_image', None)
open_instructions = request.args.get('open_instructions', None)
open_logout = request.args.get('open_logout', None)
open_retired = request.args.get('open_retired', None)
open_theme = request.args.get('open_theme', None)
open_database = (
open_checkbox is None and
open_image is None and
open_instructions is None and
open_logout is None and
open_retired is None and
open_theme is None
)
return render_template(
'admin.html',
configuration=BrickConfigurationList.list(),
brickset_checkboxes=brickset_checkboxes,
database_counters=database_counters,
database_error=request.args.get('error'),
database_exception=database_exception,
database_upgrade_needed=database_upgrade_needed,
database_version=database_version,
instructions=BrickInstructionsList(),
nil_minifigure_name=nil_minifigure_name,
nil_minifigure_url=nil_minifigure_url,
nil_part_name=nil_part_name,
nil_part_url=nil_part_url,
open_checkbox=open_checkbox,
open_database=open_database,
open_image=open_image,
open_instructions=open_instructions,
open_logout=open_logout,
open_retired=open_retired,
open_theme=open_theme,
retired=BrickRetiredList(),
theme=BrickThemeList(),
)