Skip to content
__init__.py 1.56 KiB
Newer Older
#!/usr/bin/python
# -*- coding: UTF-8 -*-

from flask import Blueprint

from const import pfsp
from utils.decorator import login_required
from utils.template import my_render_template

trainer_view = Blueprint( "trainer", __name__, template_folder = "templates" )

@trainer_view.route( "/trainer/search" )
@login_required
def search():
    """
        Provide the search page.
    """
    sql = """
        SELECT
            mark_info.*,
            files.note,
            users.username
        
        FROM mark_info
        INNER JOIN files ON mark_info.uuid = files.uuid
        LEFT JOIN submissions ON files.folder = submissions.id
        LEFT JOIN users ON submissions.donor_id = users.id
        ORDER BY id ASC
    """
    marks = config.db.query_fetchall( sql )
    
    all_detection_technics = config.db.query_fetchall( "SELECT * FROM detection_technics ORDER BY name ASC" )
    surfaces = config.db.query_fetchall( "SELECT * FROM surfaces ORDER BY name ASC" )
    
    for _, v in enumerate( marks ):
        for col in [ "detection_technic", "surface", "note" ]:
            for old, new in [ ( "{", "" ), ( "}", "" ), ( "\n", "; " ) ]:
                    v[ col ] = v[ col ].replace( old, new )
        
        v[ "username" ] = v[ "username" ].replace( "_", " " )
    return my_render_template( 
        "trainer/search.html",
        marks = marks,
        all_detection_technics = all_detection_technics,
        surfaces = surfaces,
        all_pfsp = pfsp.zones