| import os |
| import sys |
| import re |
| |
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) |
|
|
| from flask import Flask, redirect, url_for, session, request, flash, render_template |
| from jinja2 import pass_eval_context |
| from markupsafe import Markup, escape |
| from src.extensions import db, migrate |
| from src.decorators import login_required |
|
|
| |
| _paragraph_re = re.compile(r'\r\n|\r|\n') |
|
|
| @pass_eval_context |
| def nl2br(eval_ctx, value): |
| """Converts newlines into <p> and <br />s.""" |
| |
| value_str = str(escape(value)) |
| result = u'\n\n'.join(u'<p>%s</p>' % p.replace('\n', Markup('<br />\n')) |
| for p in _paragraph_re.split(value_str)) |
| if eval_ctx.autoescape: |
| result = Markup(result) |
| return result |
|
|
| def create_app(): |
| """Application Factory Pattern""" |
| app = Flask(__name__, |
| static_folder=os.path.join(os.path.dirname(__file__), 'static'), |
| template_folder=os.path.join(os.path.dirname(__file__), 'templates')) |
| |
| |
| app.config['SECRET_KEY'] = '2b4a1d4f8e594f48b32cf9f3fbd3f24c' |
| basedir = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) |
| app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'polisage.db') |
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False |
| app.config['SESSION_COOKIE_SECURE'] = True |
| app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' |
|
|
| |
| db.init_app(app) |
| migrate.init_app(app, db) |
|
|
| |
| app.jinja_env.filters['nl2br'] = nl2br |
|
|
| |
| |
| from src.routes.auth import auth_bp |
| from src.routes.drafting import drafting_bp |
| from src.routes.amendment import amendment_bp |
| from src.routes.monitoring import monitoring_bp |
| from src.routes.analysis import analysis_bp |
| from src.routes.recommendation import recommendation_bp |
| |
| |
|
|
| app.register_blueprint(auth_bp) |
| app.register_blueprint(drafting_bp) |
| app.register_blueprint(amendment_bp) |
| app.register_blueprint(monitoring_bp) |
| app.register_blueprint(analysis_bp) |
| app.register_blueprint(recommendation_bp) |
| |
|
|
| |
| |
| |
| with app.app_context(): |
| from src.models import user, legislation, draft, amendment, monitoring, analysis, recommendation, cross_reference |
|
|
| |
| @app.route('/',endpoint='index') |
| |
| def index(): |
| |
| return redirect(url_for('drafting.list_drafts')) |
| |
| |
| @app.route('/dashboard') |
| |
| def dashboard(): |
| |
| username = session.get('username', 'Guest') |
| |
| draft_count = draft.Draft.query.count() |
| analysis_count = analysis.ImpactAnalysis.query.count() |
| rec_count = recommendation.Recommendation.query.count() |
| return render_template('dashboard.html', username=username, draft_count=draft_count, analysis_count=analysis_count, rec_count=rec_count) |
|
|
| return app |
|
|
| |
| app = create_app() |
|
|
| |
| if __name__ == '__main__': |
| |
| app.run(host='0.0.0.0', port=7860, debug=True) |
|
|
|
|