diff --git a/flaskr/__init__.py b/flaskr/__init__.py index f48218f..08a1a12 100755 --- a/flaskr/__init__.py +++ b/flaskr/__init__.py @@ -4,11 +4,13 @@ from flask import Flask from flask.cli import ScriptInfo from webassets.loaders import PythonLoader as PythonAssetsLoader + from flaskr import assets -from flaskr.models import db +from flaskr.models import db, Estimation, EstimationView from flaskr.controllers.main_controller import main from flaskr.extensions import ( + admin, cache, assets_env, debug_toolbar, @@ -39,16 +41,13 @@ def create_app(object_name): # Load configuration app.config.from_object(object_name) - # initialize the cache + # Initialize cache.init_app(app) - - # initialize the debug tool bar debug_toolbar.init_app(app) - - # initialize SQLAlchemy db.init_app(app) - login_manager.init_app(app) + admin.init_app(app) + admin.add_view(EstimationView(Estimation, db.session)) # Import and register the different asset bundles assets_env.init_app(app) diff --git a/flaskr/controllers/admin_controller.py b/flaskr/controllers/admin_controller.py new file mode 100644 index 0000000..a2838bc --- /dev/null +++ b/flaskr/controllers/admin_controller.py @@ -0,0 +1,11 @@ +from flask import Blueprint, render_template, flash, request, redirect, url_for +from flask_login import login_user, logout_user, login_required + +from flaskr.forms import LoginForm +from flaskr.models import db, User + +from flaskr.controllers.main_controller import main + + +# from flask.ext.admin import Admin +# from flask.ext.admin.contrib.sqla import ModelView diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 5127be5..44e6332 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -50,6 +50,7 @@ def estimate(): # estimation.email = form.email.data estimation.first_name = form.first_name.data estimation.last_name = form.last_name.data + estimation.institution = form.institution.data estimation.status = StatusEnum.pending estimation.origin_addresses = form.origin_addresses.data estimation.destination_addresses = form.destination_addresses.data diff --git a/flaskr/extensions.py b/flaskr/extensions.py index f157d68..332aaeb 100644 --- a/flaskr/extensions.py +++ b/flaskr/extensions.py @@ -1,3 +1,4 @@ +from flask_admin import Admin from flask_caching import Cache from flask_debugtoolbar import DebugToolbarExtension from flask_login import LoginManager @@ -17,6 +18,8 @@ login_manager = LoginManager() login_manager.login_view = "main.login" login_manager.login_message_category = "warning" +admin = Admin() + @login_manager.user_loader def load_user(userid): diff --git a/flaskr/models.py b/flaskr/models.py index 79fef5d..4470ff2 100755 --- a/flaskr/models.py +++ b/flaskr/models.py @@ -1,3 +1,5 @@ +from flask_admin.contrib.sqla import ModelView + from flaskr.core import generate_unique_id from flask_sqlalchemy import SQLAlchemy from flask_login import UserMixin, AnonymousUserMixin @@ -32,12 +34,13 @@ class Estimation(db.Model): email = db.Column(db.Unicode(1024)) first_name = db.Column(db.Unicode(1024)) # Antoine last_name = db.Column(db.Unicode(1024)) # Goutenoir + institution = db.Column(db.Unicode(1024)) # IRAP status = db.Column(db.Enum(StatusEnum), default=StatusEnum.pending) # City, Country # One address per line - origin_addresses = db.Column(db.Unicode()) - destination_addresses = db.Column(db.Unicode()) + origin_addresses = db.Column(db.UnicodeText()) + destination_addresses = db.Column(db.UnicodeText()) compute_optimal_destination = db.Column(db.Boolean()) @@ -55,6 +58,27 @@ class Estimation(db.Model): return 'cities' in self.get_output_dict() +class EstimationView(ModelView): + # Show only name and email columns in list view + column_list = ( + 'public_id', + 'status', + 'first_name', + 'last_name', + 'origin_addresses', + 'destination_addresses', + 'warnings', + 'errors', + ) + + # Enable search functionality - it will search for terms in + # name and email fields + # column_searchable_list = ('name', 'email') + + # Add filters for name and email columns + column_filters = ('first_name', 'last_name') + + # USERS ####################################################################### class User(db.Model, UserMixin): diff --git a/requirements.txt b/requirements.txt index 57c065f..c4bd50d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ Flask==1.1.1 # Flask Extensions +Flask-Admin==1.5.4 Flask-Assets==0.12 Flask-Caching==1.7.2 Flask-DebugToolbar==0.10.0 -- libgit2 0.21.2