Beispiel #1
1
    def __init__(self, name, dal, apis, mailer, *args, **kwargs):
        Flask.__init__(self, name, *args, **kwargs)
        self.dal = dal
        self.apis = apis
        self.mailer = mailer

        self._setup_routes()
Beispiel #2
1
    def __init__(self, config):
        Flask.__init__(self, __name__)

        # TODO: deal with envvar and pyfile
        self.config.from_object(config)

        # Initialise helpers and services
        db.init_app(self)
        mail.init_app(self)

        # Babel
        babel.init_app(self)
        babel.localeselector(get_locale)

        # Assets (bundles are defined in the templates)
        assets = Environment(self)

        # Initialise filters
        init_filters(self)
        init_auth(self)

        from .apps.crm.frontend import CRM

        crm = CRM(self)

        self.register_blueprints()

        # Must come after all entity classes have been declared.
        self.register_services()
Beispiel #3
0
    def __init__(self, *args, **kwargs):
        if not args:
            kwargs.setdefault('import_name', __name__)

        Flask.__init__(self,
                       template_folder= "%s/templates" % dirname(__file__),
                       *args,
                       **kwargs)
        self.bs = Bootstrap(self)

        self.nav = Navigation()
        self.nav.init_app(self)

        self.nav.Bar('top', [
            self.nav.Item('Home', 'index'),
            self.nav.Item('Responsables', 'responsables'),
            self.nav.Item('Usuarios', 'usuarios'),
            self.nav.Item('Impresoras', 'impresoras'),
            self.nav.Item('Impresiones', 'impresiones'),
        ])

        # register the routes from the decorator
        for route, fn in registered_routes.items():
            partial_fn = partial(fn, self)
            partial_fn.__name__ = fn.__name__
            self.route(route)(partial_fn)
Beispiel #4
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop("startup_token", None)
        Flask.__init__(self, *args, **kwds)

        self.config["SESSION_COOKIE_HTTPONLY"] = False

        self.root_path = SAGENB_ROOT

        self.add_static_path("/css", os.path.join(DATA, "sage", "css"))
        self.add_static_path("/images", os.path.join(DATA, "sage", "images"))
        self.add_static_path("/javascript", DATA)
        self.add_static_path("/static", DATA)
        self.add_static_path("/java", DATA)
        self.add_static_path("/java/jmol", os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jmol"))
        import mimetypes

        mimetypes.add_type("text/plain", ".jmol")

        #######
        # Doc #
        #######
        # These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, "output", "html", "en")
        self.add_static_path("/pdf", os.path.join(SAGE_DOC, "output", "pdf"))
        self.add_static_path("/doc/static", DOC)
Beispiel #5
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop('startup_token', None)
        Flask.__init__(self, *args, **kwds)
        self.session_interface = OldSecureCookieSessionInterface()

        self.config['SESSION_COOKIE_HTTPONLY'] = False

        self.root_path = SAGENB_ROOT

        self.add_static_path('/css', os.path.join(DATA, "sage", "css"))
        self.add_static_path('/images', os.path.join(DATA, "sage", "images"))
        self.add_static_path('/javascript', DATA)
        self.add_static_path('/static', DATA)
        self.add_static_path('/java', DATA)
        self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_ROOT"],"local","share","jmol"))
        import mimetypes
        mimetypes.add_type('text/plain','.jmol')


        #######
        # Doc #
        #######
        #These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, 'output', 'html', 'en')
        self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'output', 'pdf'))
        self.add_static_path('/doc/static', DOC)
Beispiel #6
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop('startup_token', None)
        Flask.__init__(self, *args, **kwds)

        self.root_path = SAGENB_ROOT

        # I think it would make more sense just to have one /data/ path and not do one for every kind of file
        self.add_static_path('/data', os.path.join(DATA))
        
        # this one is special though since it points to SAGE_ROOT
        self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_ROOT"], "local", "share", "jmol"))
        
        
        import mimetypes
        mimetypes.add_type('text/plain', '.jmol')
        mimetypes.add_type('font/opentype', '.otf')
        mimetypes.add_type('application/font-woff', '.woff')

        #######
        # Doc #
        #######
        #These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, 'output', 'html', 'en')
        self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'output', 'pdf'))
        self.add_static_path('/doc/static', DOC)
Beispiel #7
0
    def __init__(self, name):
        Flask.__init__(self, name)

        status_view = CephStatusView.as_view('status')
        self.add_url_rule('/', view_func=status_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.error_handler_spec[None][code] = self.make_json_error
Beispiel #8
0
 def __init__(self, options, server):
     Flask.__init__(self, __name__)
     self._options = options
     self._server = server
     self.add_url_rule('/instance', 'status', self._status)
     self.add_url_rule('/instance', 'create-instance',
             self._create_instance, methods=['POST'])
     self.add_url_rule('/instance/<instance_id>', 'destroy-instance',
             self._destroy_instance, methods=['DELETE'])
Beispiel #9
0
 def __init__(self, import_name, *args, **kwargs):
     if module_is_package(import_name):
         # Flask.__init__ sets static path based on sys.modules.
         # As such, import the package here to ensure it's in sys.modules.
         __import__(import_name)
     Flask.__init__(self, import_name, *args, **kwargs)
     self.set_default_config()
     self.writers = {}
     self.register_default_writers()
Beispiel #10
0
    def __init__(self, name):
        Flask.__init__(self, name)
        logging.config.dictConfig(config['logging'])

        self.request_class = CustomRequestClass
        self.endpoints = ApiEndpoints()

        self.__register_endpoints()
        self.__register_error_handler()
        self.__register_help_handler()
Beispiel #11
0
    def __init__(self, env, debug=False, output_path=None, ui_lang='en',
                 verbosity=0, build_flags=None):
        Flask.__init__(self, 'lektor.admin', static_url_path='/admin/static')
        self.lektor_info = LektorInfo(env, output_path, ui_lang,
                                      build_flags=build_flags,
                                      verbosity=verbosity)
        self.debug = debug
        self.config['PROPAGATE_EXCEPTIONS'] = True

        register_modules(self)
Beispiel #12
0
    def __init__(self, name):
        Flask.__init__(self, name)

        dhc_view = StateView.as_view('status')
        self.add_url_rule('/', defaults={'env': None}, view_func=dhc_view)
        self.add_url_rule('/<env>', view_func=dhc_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.register_error_handler(code, self.make_json_error)
Beispiel #13
0
    def __init__(self, name=None, *args, **kwargs):
        name = name or __name__

        Flask.__init__(self, name, *args, **kwargs)

        ServiceManager.__init__(self)
        PluginManager.__init__(self)
        JinjaManagerMixin.__init__(self)

        self.default_view = ViewRegistry()
        self.js_api = {}
Beispiel #14
0
    def __init__(self, name):
        template_folder = os.path.join(os.path.dirname(__file__), 'templates')
        static_folder = os.path.join(os.path.dirname(__file__), 'static')
        Flask.__init__(self, name, template_folder=template_folder, static_folder=static_folder)

        status_view = CephStatusView.as_view('status')
        self.add_url_rule('/', view_func=status_view)

        # add custom error handler
        for code in default_exceptions.iterkeys():
            self.error_handler_spec[None][code] = self.make_json_error
Beispiel #15
0
 def __init__(self):
     """
     jinja_loader object (a FileSystemLoader pointing to the global templates folder) is
     being replaced with a ChoiceLoader object that will first search the normal
     FileSystemLoader and then check a PrefixLoader that we create
     """
     Flask.__init__(self, __name__, static_folder="static", template_folder="templates")
     self.jinja_loader = jinja2.ChoiceLoader([
         self.jinja_loader,
         jinja2.PrefixLoader({}, delimiter=".")
     ])
Beispiel #16
0
    def __init__(self, *args, **kwargs):
        config = kwargs.pop('config', None)
        Flask.__init__(self, *args, **kwargs)

        self.config.from_object(DefaultConfig())

        if config is not None:
            if isinstance(config, basestring):
                self.config.from_pyfile(config)
            else:
                self.config.from_object(config)

        self.configure_extensions()
Beispiel #17
0
    def __init__(self, name):
        Flask.__init__(self, name)
        self.__add_apis = False
        self.__add_views = False
        self.__name = name

        self.url_map.converters["regex"] = _RegexConverter
        self.__init_config()
        self.__init_log()
        self.__init_sched()
        self.db = Database(self)
        self.cache = SimpleCache()
        self.__init_signals()
Beispiel #18
0
    def __init__(self, name):
        Flask.__init__(self, name)
        self.response_class = MyResponse

        self._setup_hooks()

        # 注意这里的初始化顺序!
        self._init_stat()
        self._init_config()
        self._init_log()
        self._init_redis()
        self._init_db()

        logging.info('API开始服务请求')
Beispiel #19
0
    def __init__(self, *args, **kwargs):
        config = kwargs.pop('config', None)
        Flask.__init__(self, *args, **kwargs)

        self.config.from_object(DefaultConfig())

        if config is None:
            self.config.from_object(config)

        with Connection():
            self.queue = Queue()

        self.configure_extensions()

        self.register_blueprint(blueprint)
Beispiel #20
0
    def __init__(self, name):
        Flask.__init__(self, name)
        self.response_class = MyResponse

        self._register_error_handler(None, APIError, self.base_error_handler)
        self.before_request_funcs.setdefault(None, []).append(self.before_handler)
        self.teardown_request_funcs.setdefault(None, []).append(self.teardown_handler)

        # 注意这里的初始化顺序!
        self._init_config()
        self._init_log()
        self._init_redis()
        self._init_db()
        self._init_log_agent()

        self.logger.info('APP开始服务请求')
Beispiel #21
0
    def __init__(self, *args, **kwargs):
        self.endpoints = {}  # This is the storage property for the endpoints

        self.__dict__.update({
            method: self.__shorthand(methods=[method.upper()])
            for method in ["get", "post", "put"]})

        return Flask.__init__(self, *args, **kwargs)
Beispiel #22
0
 def __init__(self, *args, **kwargs):
     self.endpoints = {}  # This is the storage property for the endpoints
     if settings.DEBUG:
         if 'static_folder' not in kwargs and 'folder' in settings.STATIC:
             kwargs['static_folder'] = settings.STATIC['folder']
         if 'static_url_path' not in kwargs and 'path' in settings.STATIC:
             kwargs['static_url_path'] = settings.STATIC['path']
     return Flask.__init__(self, *args, **kwargs)
Beispiel #23
0
    def __init__(self, implementation):
        Flask.__init__(self, __name__, static_url_path="/common_static")

        self.jinja_loader = jinja2.ChoiceLoader([
            self.jinja_loader,
            jinja2.PrefixLoader({}, delimiter = ".")
        ])
        sidebar_links = []

        #Custom module importing
        #Import all controller modules in mod_* packages
        #if the define a "mod" attribute
        def import_dir(path, prefix):
            for _, package, _ in pkgutil.walk_packages([path]):
                if package[:4] == "mod_" or package == implementation:
                    for _, module, _ in pkgutil.iter_modules([path + package]):
                        if module == "controller":
                            controller = importlib.import_module(prefix + "." + package + "." + module)
                            if hasattr(controller, "mod"):
                                self.register_blueprint(controller.mod)
                                print "Registering:", prefix + "." + package + "." + module


        path = os.path.dirname(__file__) + "/"
        import_dir(path, "web_apps")
        import_dir(path + implementation + "/", "web_apps." + implementation)

        # HTTP error handling
        @self.errorhandler(404)
        def not_found(error):
          return render_template('404.html'), 404

        # Make sure that the database is closed
        @self.teardown_appcontext
        def close_db(error):
          """Closes the database again at the end of the request."""
          if hasattr(g, 'cursor'):
            g.cursor.close()
          if hasattr(g, 'database'):
            g.database.close()
          if hasattr(g, 'clientsDB'):
            g.clientsDB.close()

            """ End Init """
Beispiel #24
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop('startup_token', None)
        Flask.__init__(self, *args, **kwds)
        self.session_interface = OldSecureCookieSessionInterface()

        self.config['SESSION_COOKIE_HTTPONLY'] = False

        self.root_path = SAGENB_ROOT

        self.add_static_path('/css', os.path.join(DATA, "sage", "css"))
        self.add_static_path('/images', os.path.join(DATA, "sage", "images"))
        self.add_static_path('/javascript', DATA)
        self.add_static_path('/static', DATA)
        self.add_static_path('/java', DATA)
        self.add_static_path('/java/jmol', os.path.join(os.environ["SAGE_SHARE"],"jmol"))
        self.add_static_path('/jsmol', os.path.join(os.environ["SAGE_SHARE"],"jsmol"))
        self.add_static_path('/jsmol/js', os.path.join(os.environ["SAGE_SHARE"],"jsmol","js"))
        self.add_static_path('/j2s', os.path.join(os.environ["SAGE_SHARE"],"jsmol","j2s"))
        self.add_static_path('/jsmol/j2s', os.path.join(os.environ["SAGE_SHARE"],"jsmol","j2s"))
        self.add_static_path('/j2s/core', os.path.join(os.environ["SAGE_SHARE"],"jsmol","j2s","core"))
        self.add_static_path('/threejs', os.path.join(os.environ["SAGE_SHARE"],"threejs"))
        import mimetypes
        mimetypes.add_type('text/plain','.jmol')


        #######
        # Doc #
        #######
        #These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, 'html', 'en')
        self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'pdf'))
        self.add_static_path('/doc/static', DOC)

        # Template globals
        self.add_template_global(url_for)
        # Template filters
        self.add_template_filter(css_escape)
        self.add_template_filter(number_of_rows)
        self.add_template_filter(clean_name)
        self.add_template_filter(prettify_time_ago)
        self.add_template_filter(max)
        self.add_template_filter(lambda x: repr(unicode_str(x))[1:],
                                 name='repr_str')
        self.add_template_filter(dumps, 'tojson')
Beispiel #25
0
  def __init__(self, import_name, static_path=None, static_url_path=None,
                     static_folder='html/static', template_folder='html/templates',
                     instance_path=None, instance_relative_config=False,
                     db_user=None, db_password=None, db_name=None):

    Flask.__init__(self, import_name, static_path, static_url_path, 
                         static_folder, template_folder,
                         instance_path, instance_relative_config)

    #: DB connector pool.
    self.dbPool = SeaIceConnectorPool(MAX_CONNECTIONS, db_user, db_password, db_name)

    # Id pools.
    db_con = self.dbPool.getScoped()
    
    self.userIdPool = IdPool(db_con, "Users") #: Pool for user surrogate IDs. 
    self.termIdPool = IdPool(db_con, "Terms") #: Pool for term surrogate IDs. 
    self.commentIdPool = IdPool(db_con, "Comments") #: Pool for comment surrogate IDs.
     
    #: Live User data structures. This includes storage of notifications. 
    self.SeaIceUsers = {}
    for row in db_con.getAllUsers():
      self.SeaIceUsers[row['id']] = user.User(row['id'], 
                                    row['first_name'].decode('utf-8'))

    # Load notifcations 
    for (user_id, notif_class, T_notify, 
         term_id, from_user_id, term_string,
         enotified) in db_con.getAllNotifications():

      if notif_class == 'Base': 
        notif = notify.BaseNotification(term_id, T_notify)
      elif notif_class == 'Comment': 
        notif = notify.Comment(term_id, from_user_id, term_string, T_notify)
      elif notif_class == 'TermUpdate': 
        notif = notify.TermUpdate(term_id, from_user_id, T_notify)
      elif notif_class == 'TermRemoved': 
        notif = notify.TermRemoved(from_user_id, term_string, T_notify) 
        
      self.SeaIceUsers[user_id].notify(notif)
Beispiel #26
0
    def __init__(self, import_name, db_controller = None, bus = None):
        #super(SlaPrinterApp, self).__init__(import_name, template_folder=TEMPLATE_DIR, static_url_path=STATIC_DIR)
        Flask.__init__(self,import_name, static_folder=STATIC_DIR, template_folder=TEMPLATE_DIR)
        Observable.__init__(self, bus)
        Observer.__init__(self, bus)
        Process.__init__(self)
        self.exit = Event()


        self.endpoint_prefix = None
        for name in dir(self):
            if hasattr(getattr(self, name), ("_routing_data")):
                fn = getattr(self, name)
                rds = fn._routing_data
                for rd in rds:
                    self.route(*rd.args, **rd.kwargs)(fn)


        self.register_error_handler(404, self.page_not_found)
        self.db_controller = db_controller

        print("Flask Server initializing")
Beispiel #27
0
    def __init__(self, *args, **kwargs):
        self.endpoints = {}  # This is the storage property for the endpoints
        if settings.DEBUG:
            if 'static_folder' not in kwargs and 'folder' in settings.STATIC:
                kwargs['static_folder'] = settings.STATIC['folder']
            if 'static_url_path' not in kwargs and 'path' in settings.STATIC:
                kwargs['static_url_path'] = settings.STATIC['path']

        self.__dict__.update({
            method: self.__shorthand({'methods': [method.upper()]})
            for method in ["get", "post", "put"]})

        return Flask.__init__(self, *args, **kwargs)
Beispiel #28
0
    def __init__(self, *args, **kwds):
        self.startup_token = kwds.pop('startup_token', None)
        Flask.__init__(self, *args, **kwds)

        self.root_path = SAGENB_ROOT

        self.add_static_path('/css', os.path.join(DATA, "sage", "css"))        
        self.add_static_path('/images', os.path.join(DATA, "sage", "images"))
        self.add_static_path('/javascript', DATA)
        self.add_static_path('/static', DATA)
        self.add_static_path('/java', DATA)
        import mimetypes
        mimetypes.add_type('text/plain','.jmol')

        
        #######
        # Doc #
        #######
        #These "should" be in doc.py
        DOC = os.path.join(SAGE_DOC, 'output', 'html', 'en')
        self.add_static_path('/pdf', os.path.join(SAGE_DOC, 'output', 'pdf'))
        self.add_static_path('/doc/static', DOC) 
Beispiel #29
0
    def __init__(self, config):
        Flask.__init__(self, __name__)

        # TODO: deal with envvar and pyfile
        self.config.from_object(config)

        # Initialise helpers and services
        db.init_app(self)
        mail.init_app(self)

        # Babel (for i18n)
        babel.init_app(self)
        babel.localeselector(get_locale)

        # celery async service
        celery.config_from_object(config)

        # Initialise filters
        init_filters(self)
        # init_auth(self)

        self.register_services()
Beispiel #30
0
  def __init__(self, config):
    Flask.__init__(self, __name__)

    # TODO: deal with envvar and pyfile
    self.config.from_object(config)

    # Initialise helpers and services
    db.init_app(self)
    mail.init_app(self)

    # Babel
    babel.init_app(self)
    babel.localeselector(get_locale)

    # DEBUG
    self.jinja_env.add_extension('jinja2.ext.i18n')
    self.jinja_env.install_gettext_callables(
      lambda x: x,
      lambda s, p, n: p,
      newstyle=True
    )



  # Assets (bundles are defined in the templates)
    assets = Environment(self)

    # Initialise filters
    init_filters(self)
    init_auth(self)

    from .apps.crm.frontend import CRM
    crm = CRM(self)

    self.register_blueprints()

    # Must come after all entity classes have been declared.
    self.register_services()