"""app.views==========A view function is written to respond to application requests.``Flask`` uses patterns to match the incoming request URL to the viewthat should handle it. The view returns data that ``Flask`` turns intoan outgoing response.``Flask`` can also go the other direction and generate a URL to viewbased on its name and arguments."""fromdatetimeimportdatetimefrombs4importBeautifulSoupfromflaskimportFlask,Response,gfromflask_babelimportget_localefromflask_loginimportcurrent_userfromapp.extensionsimportdbfromapp.viewsimport(admin,auth,database,order,post,public,redirect,report,upload,user,)def_before_request()->None:ifcurrent_user.is_authenticated:current_user.last_seen=datetime.utcnow()db.session.commit()g.locale=str(get_locale())
[docs]defformat_html(response:Response)->Response:"""Prettify HTML response. See https://stackoverflow.com/a/6167432/13316671. :param response: Response returned from a route. :return: Response returned from a route. """ifresponse.content_type=="text/html; charset=utf-8":response.set_data(BeautifulSoup(# type: ignoreresponse.get_data(as_text=True),"html.parser").prettify(formatter="html"))returnresponse
[docs]definit_app(app:Flask)->None:"""Load the app with views. :param app: Application object. """app.before_request(_before_request)app.register_blueprint(report.blueprint)app.register_blueprint(public.blueprint)app.register_blueprint(auth.blueprint)app.register_blueprint(user.blueprint)app.register_blueprint(post.blueprint)app.register_blueprint(redirect.blueprint)app.register_blueprint(order.blueprint)app.register_blueprint(admin.blueprint)app.register_blueprint(upload.blueprint)app.add_url_rule("/",endpoint="index")database.init_app(app)app.after_request(format_html)# type: ignore