@@ -2995,7 +2995,114 @@ class Service(MethodView):
29952995```
29962996
29972997
2998- # # Example 19 from tedivms-flask
2998+ # # Example 19 from Science Flask
2999+ [Science Flask](https:// github.com/ danielhomola/ science_flask)
3000+ is a [Flask](/ flask.html)- powered web application for online
3001+ scientific research tools. The project was built as a template
3002+ for any scientist or groups of scientists to use when working
3003+ together without having to really understand how the application
3004+ is built. The application includes an academic registration
3005+ process (only valid academic email addresses can be used), an
3006+ admin panel, logging, and analysis forms.
3007+
3008+ [@ danielhomola](https:// github.com/ danielhomola) is the
3009+ primary creator of Science Flask and the project is open
3010+ source under the
3011+ [GNU General Public License](https:// github.com/ danielhomola/ science_flask/ blob/ master/ LICENSE ).
3012+
3013+ [** Science Flask / frontend / __init__ .py** ](https:// github.com/ danielhomola/ science_flask/ blob/ master/ ./ frontend/ __init__ .py)
3014+
3015+ ```python
3016+ # __init__.py
3017+ import os
3018+ ~~ from flask import Flask, url_for, redirect, request, abort
3019+ from flask_mail import Mail
3020+ from flask_sqlalchemy import SQLAlchemy
3021+ from flask_login import LoginManager
3022+ from flask_security import Security, SQLAlchemyUserDatastore, signals, \
3023+ current_user
3024+ import flask_admin
3025+ from flask_admin.contrib import sqla
3026+ from flask_admin import helpers as admin_helpers
3027+ from flask_wtf.csrf import CSRFProtect
3028+ from celery import Celery
3029+
3030+
3031+ appdir = os.path.abspath(os.path.dirname(__file__ ))
3032+ ROOTDIR = os.path.abspath(os.path.join(appdir, os.pardir))
3033+ user_data_folder = os.path.join(ROOTDIR , ' userData' )
3034+
3035+ app = Flask(__name__ , instance_path = user_data_folder)
3036+
3037+ app.config.from_pyfile(' config.py' )
3038+
3039+ db = SQLAlchemy(app)
3040+
3041+ mail = Mail(app)
3042+
3043+
3044+
3045+ # # ... source file abbreviated to get to request examples ...
3046+
3047+
3048+
3049+ class MyModelView(sqla.ModelView):
3050+
3051+ def __init__ (self , model, session, name = None , category = None , endpoint = None ,
3052+ url = None , ** kwargs):
3053+ for k, v in kwargs.items():
3054+ setattr (self , k, v)
3055+
3056+ super (MyModelView, self ).__init__ (model, session, name = name,
3057+ category = category, endpoint = endpoint,
3058+ url = url)
3059+
3060+ def is_accessible(self ):
3061+ if not current_user.is_active or not current_user.is_authenticated:
3062+ return False
3063+
3064+ if current_user.has_role(' superuser' ):
3065+ return True
3066+ return False
3067+
3068+ def _handle_view(self , name, ** kwargs):
3069+ if not self .is_accessible():
3070+ if current_user.is_authenticated:
3071+ abort(403 )
3072+ else :
3073+ ~~ return redirect(url_for(' security.login' , next = request.url))
3074+
3075+ admin = flask_admin.Admin(
3076+ app,
3077+ ' Admin panel' ,
3078+ base_template = ' admin_base.html' ,
3079+ template_mode = ' bootstrap3' ,
3080+ )
3081+
3082+ from .models import Studies, Analyses
3083+ admin.add_view(MyModelView(Role, db.session))
3084+ cols = [c for c in User.__table__.columns]
3085+ admin.add_view(MyModelView(User, db.session, column_list = cols))
3086+ cols = [c for c in Studies.__table__.columns]
3087+ admin.add_view(MyModelView(Studies, db.session, column_list = cols))
3088+ cols = [c for c in Analyses.__table__.columns]
3089+ admin.add_view(MyModelView(Analyses, db.session, column_list = cols))
3090+
3091+ @ security.context_processor
3092+ def security_context_processor():
3093+ return dict (
3094+ admin_base_template = admin.base_template,
3095+ admin_view = admin.index_view,
3096+ h = admin_helpers,
3097+ get_url = url_for
3098+
3099+
3100+ # # ... source file continues with no further request examples...
3101+
3102+ ```
3103+
3104+
3105+ # # Example 20 from tedivms-flask
29993106[tedivm' s flask starter app](https://github.com/tedivm/tedivms-flask) is a
30003107base of [Flask](/ flask.html) code and related projects such as
30013108[Celery](/ celery.html) which provides a template to start your own
@@ -3053,7 +3160,7 @@ def roles_accepted_api(*role_names):
30533160```
30543161
30553162
3056- # # Example 20 from trape
3163+ # # Example 21 from trape
30573164[trape](https:// github.com/ jofpin/ trape) is a research tool for tracking
30583165people' s activities that are logged digitally. The tool uses
30593166[Flask](/ flask.html) to create a web front end to view aggregated data
0 commit comments