Ejemplo n.º 1
0
    def install(cls, app):
        """Install the extension into the application."""
        Environment.resolver_class = InvenioResolver
        env = Environment(app)
        env.url = "{0}/{1}/".format(app.static_url_path,
                                    app.config["ASSETS_BUNDLES_DIR"])
        env.directory = os.path.join(app.static_folder,
                                     app.config["ASSETS_BUNDLES_DIR"])
        env.append_path(app.static_folder)
        env.auto_build = app.config.get("ASSETS_AUTO_BUILD", True)

        # The filters less and requirejs don't have the same behaviour by
        # default. Make sure we are respecting that.
        app.config.setdefault("REQUIREJS_RUN_IN_DEBUG", False)
        # Fixing some paths as we forced the output directory with the
        # .directory
        app.config.setdefault("REQUIREJS_BASEURL", app.static_folder)
        requirejs_config = os.path.join(env.directory,
                                        app.config["REQUIREJS_CONFIG"])
        if not os.path.exists(requirejs_config):
            app.config["REQUIREJS_CONFIG"] = os.path.relpath(
                os.path.join(app.static_folder,
                             app.config["REQUIREJS_CONFIG"]), env.directory)

        app.jinja_env.add_extension(BundleExtension)
        app.context_processor(BundleExtension.inject)
Ejemplo n.º 2
0
def init(app=None):
    app = app or Flask(__name__)
    with app.app_context():
        env = Environment(app)
        env.directory = 'aqandu/static'
        env.load_path = [path.join(path.dirname(__file__), 'aqandu/static')]
        # env.append_path('assets')
        # env.set_directory(env_directory)
        # App Engine doesn't support automatic rebuilding.
        env.auto_build = False
        env.versions = 'hash'
        # This file needs to be shipped with your code.
        env.manifest = 'file'

        all_css = Bundle('css/airu.css',
                         'css/visualization.css',
                         'css/ie10-viewport-bug-workaround.css',
                         filters='cssmin',
                         output='css/all_css.%(version)s.css')
        env.register('css', all_css)

        all_js = Bundle('js/db_data.js',
                        'js/map_reconfigure.js',
                        filters='jsmin',
                        output='js/all_js.%(version)s.js')
        env.register('js', all_js)

        # bundles = [css, js]
        bundles = [all_css, all_js]
        # bundles = [all_css]
        return bundles
Ejemplo n.º 3
0
    def install(cls, app):
        """Install the extension into the application."""
        Environment.resolver_class = InvenioResolver
        env = Environment(app)
        env.url = "{0}/{1}/".format(app.static_url_path,
                                    app.config["ASSETS_BUNDLES_DIR"])
        env.directory = os.path.join(app.static_folder,
                                     app.config["ASSETS_BUNDLES_DIR"])
        env.append_path(app.static_folder)
        env.auto_build = app.config.get("ASSETS_AUTO_BUILD", True)

        # The filters less and requirejs don't have the same behaviour by
        # default. Make sure we are respecting that.
        app.config.setdefault("LESS_RUN_IN_DEBUG", True)
        app.config.setdefault("REQUIREJS_RUN_IN_DEBUG", False)
        # Fixing some paths as we forced the output directory with the
        # .directory
        app.config.setdefault("REQUIREJS_BASEURL", app.static_folder)
        requirejs_config = os.path.join(env.directory,
                                        app.config["REQUIREJS_CONFIG"])
        if not os.path.exists(requirejs_config):
            app.config["REQUIREJS_CONFIG"] = os.path.relpath(
                os.path.join(app.static_folder,
                             app.config["REQUIREJS_CONFIG"]),
                env.directory)

        app.jinja_env.add_extension(BundleExtension)
        app.context_processor(BundleExtension.inject)
Ejemplo n.º 4
0
def register_assets(app):
	assets = Environment(app)
	assets.url = app.static_url_path
	assets.directory = app.static_folder
	assets.append_path('assets')
	scss = Bundle('scss/main.scss', filters='pyscss', output='main.css', depends=('scss/*.scss'))
	assets.register('scss_all', scss)
Ejemplo n.º 5
0
def init_app(app, allow_auto_build=True):
    assets = Environment(app)
    # on google app engine put manifest file beside code
    # static folders are stored separately and there is no access to them in production
    folder = os.path.abspath(os.path.dirname(__file__)) if "APPENGINE_RUNTIME" in os.environ else ""
    assets.directory = os.path.join(app.static_folder, "compressed")
    assets.manifest = "json:{}/manifest.json".format(assets.directory)
    assets.url = app.static_url_path + "/compressed"
    compress = not app.debug  # and False
    assets.debug = not compress
    assets.auto_build = compress and allow_auto_build
    assets.register('js', Bundle(*JS, filters='yui_js', output='script.%(version)s.js'))
    assets.register('css', Bundle(*CSS, filters='yui_css', output='style.%(version)s.css'))
Ejemplo n.º 6
0
def init(app=None):
    app = app or Flask(__name__)

    with app.app_context():
        env = Environment(app)
        env.load_path = [path.join(path.dirname(__file__), 'assets')]
        env.url = app.static_url_path
        env.directory = app.static_folder
        env.auto_build = app.debug
        env.manifest = 'file'

        scss = Bundle('stylesheet.scss',
                      filters='pyscss',
                      output='stylesheet.css')
        env.register('scss_all', scss)

        bundles = [scss]
        return bundles
Ejemplo n.º 7
0
from healthtools_ec.app import app
from flask_assets import Environment, Bundle

assets = Environment(app)
assets.url_expire = False
assets.directory = '%s/public' % app.config.root_path
assets.load_path = ['assets']
assets.url = '/public'

assets.register(
    'css',
    Bundle('css/bootstrap-3.2.0.min.css',
           'css/bootstrap-theme-3.2.0.min.css',
           'css/font-awesome-4.3.0.min.css',
           'css/datepicker3.css',
           'css/bootstrap-datetimepicker.min.css',
           'css/daterangepicker-bs3.css',
           'css/select2-3.4.8.css',
           'css/select2-bootstrap-3.4.8.css',
           'css/dropzone-3.10.2.css',
           'css/freelancer.css',
           Bundle('css/*.scss',
                  filters='pyscss',
                  output='css/app.%(version)s.css'),
           output='css/all.%(version)s.css'))

assets.register('admin-css', Bundle('css/admin.css', ))

assets.register(
    'maps-css',
    Bundle('css/leaflet-0.7.2.css', output='css/maps.%(version)s.css'))
Ejemplo n.º 8
0
class JSONEncoder(BaseEncoder):
    def default(self, o):
        if isinstance(o, _LazyString):
            return str(o)
        return BaseEncoder.default(self, o)


reload(sys)
sys.setdefaultencoding('utf-8')

app = Flask(__name__, static_url_path='/static', static_folder='static')
app.config.from_object(settings.Config)
app.config.from_object(settings.LocalConfig)
app.json_encoder = JSONEncoder

from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate

db = SQLAlchemy(app)
migrate = Migrate(app, db)

from app import views

assets_env = Environment(app)
assets_env.url = app.static_url_path
assets_env.directory = app.static_folder

assets_env.register(assets.bundles)

assets_env.init_app(app)
Ejemplo n.º 9
0
app.config['VIPPS_STORAGE_PATH'] = os.path.join(app.root_path, 'vipps-reports')
app.config['PASSWORDS'] = {
    'Funk': 'funk',
    'SM': 'sm',
    'Admin': 'admin',
    'Superadmin': 'superadmin',
}
app.config['BLACKLIST'] = []

app.config.from_pyfile(os.getenv('CONFIG_FILE', 'production.cfg'), silent=True)

tz = timezone(app.config['TIMEZONE'])

assets = Environment(app)
if 'WEBASSETS_DIR' in os.environ:
    assets.directory = os.getenv('WEBASSETS_DIR')

db = SQLAlchemy(app)

def compute_queryname(context):
    return context.current_parameters['name'].lower()

class Membership(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    _name = db.Column('name', db.Text, nullable=False)
    queryname = db.Column(db.Text, nullable=False)
    price = db.Column(db.Integer, nullable=False)
    term = db.Column(db.Text, nullable=False)
    account = db.Column(db.Text, nullable=False) # Entrance/Wristband/BankAccount/Unknown
    vipps_transaction_id = db.Column(db.Text)
    created_at = db.Column(db.DateTime, default=datetime.utcnow, nullable=False)
Ejemplo n.º 10
0
from flask import Flask, render_template
from flask_assets import Environment, Bundle

from flask import got_request_exception
from .components import routeHandler
from .extAPI import ExtendedAPI
from .routes import ROUTING

# Define the WSGI application object
app = Flask(__name__)

# Define Assets
assets = Environment(app)
assets.url = app.static_url_path
assets.url = app.static_url_path
assets.directory = app.static_folder

# Define the REST API
api = ExtendedAPI(app)

# Configurations
app.config.from_object('config')

# Define the database object which is imported
# by modules and controllers
#db = SQLAlchemy(app)


# Sample HTTP error handling
@app.errorhandler(404)
def not_found(error):
Ejemplo n.º 11
0
app.config['VIPPS_STORAGE_PATH'] = os.path.join(app.root_path, 'vipps-reports')
app.config['PASSWORDS'] = {
    'Funk': 'funk',
    'SM': 'sm',
    'Admin': 'admin',
    'Superadmin': 'superadmin',
}
app.config['BLACKLIST'] = []

app.config.from_pyfile(os.getenv('CONFIG_FILE', 'production.cfg'), silent=True)

tz = timezone(app.config['TIMEZONE'])

assets = Environment(app)
if 'WEBASSETS_DIR' in os.environ:
    assets.directory = os.getenv('WEBASSETS_DIR')

db = SQLAlchemy(app)


def compute_queryname(context):
    return context.current_parameters['name'].lower()


class Membership(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    _name = db.Column('name', db.Text, nullable=False)
    queryname = db.Column(db.Text, nullable=False)
    price = db.Column(db.Integer, nullable=False)
    term = db.Column(db.Text, nullable=False)
    account = db.Column(
Ejemplo n.º 12
0
def run(datapath):
    """
    starts the frontend server
    datapath: directory for saving and loading requirement projects
    """

    with open(join(dirname(dirname(__file__)), 'VERSION'),
              mode='r') as version_file:
        stlinspector_version = version_file.read()

    app = Flask(__name__)

    # interface to the projects and backend
    projectList = ProjectList(datapath)

    # temporal directory for caching etc.
    tempDir = mkdtemp(prefix="STLInspector")

    # Bundle the javascript files into one distribution file
    # and the css file such that it is reloaded on a change
    bundles = {
        'STLInspector_js':
        Bundle('js/AlertView.js',
               'js/BooleanChart.js',
               'js/Project.js',
               'js/Projects.js',
               'js/ProjectsView.js',
               'js/ProjectView.js',
               'js/RealChart.js',
               'js/ServerRequest.js',
               'js/SignalView.js',
               'js/STLInspector.js',
               output='build/STLInspector.js'),
        'STLInspector_css':
        Bundle('css/STLInspector.css', output='build/STLInspector.css')
    }
    assets = Environment(app)
    assetscachepath = join(tempDir, 'assetscache')
    # create directory if not already present
    if not access(assetscachepath, F_OK):
        mkdir(assetscachepath)
    assets.cache = assetscachepath

    assetsdirectorypath = join(tempDir, 'assetsdirectory')
    # create directory if not already present
    if not access(assetsdirectorypath, F_OK):
        mkdir(assetsdirectorypath)
    assets.directory = assetsdirectorypath

    assets.register(bundles)

    @app.route("/")
    def index():
        """index page loader

        loads and renders the index template
        """
        return render_template('index.html',
                               stlinspector_version=stlinspector_version)

    @app.route('/static/build/<path:filename>')
    def static_build_files(filename):
        """
        serve static build files from cache directory
        """
        return send_from_directory(join(assetsdirectorypath, 'build'),
                                   filename)

    @app.route("/documentation/")
    def documentation():
        """renders the documentation page"""
        fdoc = open(join(dirname(dirname(__file__)), "doc/documentation.md"),
                    "r")
        doc = markdown.Markdown(extensions=['mdx_math'],
                                extension_configs={
                                    'mdx_math': {
                                        'enable_dollar_delimiter': True
                                    }
                                }).convert(fdoc.read())
        fdoc.close()
        return render_template('documentation.html', doctext=Markup(doc))

    @app.route('/documentation/images/<path:filename>')
    def documentation_images(filename):
        return send_from_directory('../doc/images', filename)

    @app.route("/api/projects/list", methods=['POST'])
    def api_projects_list():
        """project list loader"""

        try:
            return Response(json.dumps(projectList.list()),
                            mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/projects/create", methods=['POST'])
    def api_projects_create():
        """create a project with given name"""

        try:
            projectTitle = request.form['title']
            return Response(json.dumps(projectList.create(projectTitle)),
                            mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/projects/delete", methods=['POST'])
    def api_projects_delete():
        """deletes the project file"""

        try:
            projectId = request.form['id']
            projectList.delete(projectId)
            return Response('true', mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/project/save", methods=['POST'])
    def api_project_save():
        """saves the project to file"""

        try:
            projectId = request.form['id']
            projectList.saveProject(projectId)
            return Response('true', mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/project/close", methods=['POST'])
    def api_project_close():
        """is called when a project is closed in the frontend"""

        try:
            projectId = request.form['id']
            projectList.close(projectId)
            return Response('true', mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/project/load", methods=['POST'])
    def api_project_load():
        """returns the data of a project with the given id"""

        try:
            projectId = request.form['id']
            project = projectList.project(projectId)
            return Response(json.dumps(project.state()),
                            mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/project/change", methods=['POST'])
    def api_project_change():
        """changes project variables"""

        try:
            projectId = request.form['id']
            project = projectList.project(projectId)
            if 'stlCandidate' in request.form:
                project.setStlCandidate(request.form['stlCandidate'])
            if 'textRequirement' in request.form:
                project.setTextRequirement(request.form['textRequirement'])
            if 'textNotes' in request.form:
                project.setTextNotes(request.form['textNotes'])
            return Response('true', mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/project/test", methods=['POST'])
    def api_project_test():
        """returns an existing or new test signal"""

        try:
            projectId = request.form['id']
            test_type = request.form['type']
            parameter = request.form['parameter']
            project = projectList.project(projectId)
            if test_type == 'evaluate':
                test = project.testForName(parameter)
            else:
                test = project.testById(int(parameter))
            return Response(json.dumps(test), mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    @app.route("/api/project/testEvaluation", methods=['POST'])
    def api_project_testEvaluation():
        """returns an existing or new test signal"""

        try:
            projectId = request.form['id']
            testId = int(request.form['testId'])
            username = request.form['username']
            evaluation = request.form['evaluation'] == 'true'
            project = projectList.project(projectId)
            project.setTestEvaluation(testId, username, evaluation)
            return Response('true', mimetype='application/json')
        except Exception as e:
            exceptionHandler(e)
            abort(500)

    webbrowser.open_new_tab('http://localhost:{}'.format(PORT))
    app.run(debug=False, port=PORT)
Ejemplo n.º 13
0
app.config['max_content_length'] = config_frontend.get('max_content_length')

if topic_flag:
    app.register_blueprint(topics.mod)

csrf = CSRFProtect(app)
assets = Environment(app)
if config_frontend.get('data_path', None):
    data_path = config_frontend['data_path']
    cache_path = os.path.join(data_path, 'cache', '.webassets-cache')
    static_path = os.path.abspath(os.path.join(data_path, 'static'))

    pathlib.Path(cache_path).mkdir(parents=True, exist_ok=True)

    assets.cache = os.path.abspath(cache_path)
    assets.directory = os.path.abspath(static_path)
    app.static_folder = static_path

    if os.path.exists(static_path):
        shutil.rmtree(static_path)
    shutil.copytree(os.path.join(app.root_path, 'static'), static_path)

# Do not automatically build assets in deployment for performance
assets.auto_build = False
assets.append_path(os.path.join(app.root_path, 'uncompiled_assets'))

js_bundle = Bundle('javascript/autocomplete.js',
                   'javascript/evaluation.js',
                   'javascript/utils.js',
                   'javascript/forms.js',
                   'javascript/articlelist.js',
Ejemplo n.º 14
0
from flask import Flask, render_template
from flask_assets import Bundle, Environment
from flask.ext.markdown import Markdown
from flask_security import Security, SQLAlchemyUserDatastore
from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)
app.config.from_object('config')


# Assets
assets = Environment(app)
assets.url = '/static'
assets.directory = app.config['ASSETS_DEST']

less = Bundle('less/style.less', filters='less', output='gen/style.css')
assets.register('all-css', less)


# Database
db = SQLAlchemy(app)
from . import models


# Admin
from . import admin


# Markdown
Markdown(app, safe_mode='escape')