Fantastico settings

Fantastico is configured using a plain settings file. This file is located in the root of fantastico framework or in the root folder of your project. Before we dig further into configuration options lets see a very simple settings file:

class BasicSettings(object):
   @property
   def installed_middleware(self):
      return ["fantastico.middleware.request_middleware.RequestMiddleware",
             "fantastico.middleware.routing_middleware.RoutingMiddleware"]

   @property
   def supported_languages(self):
      return ["en_us"]

The above code sample represent the minimum required configuration for fantastico framework to run. The order in which middlewares are listed is the order in which they are executed when an http request is made.

Settings API

Below you can find technical information about settings.

class fantastico.settings.BasicSettings[source]

This is the core class that describes all available settings of fantastico framework. For convenience all options have default values that ensure minimum functionality of the framework. Below you can find an example of three possible configuration: Dev / Stage / Production.

../_images/settings.png

As you can see, if you want to overwrite basic configuration you simply have to extend the class and set new values for the attributes you want to overwrite.

access_token_validity[source]

This property defines the validity of an access token in seconds. By default, this property is set to 1h = 3600 seconds.

database_config[source]

This property holds the configuration of database. It is recommended to have all environment configured the same. An exception can be done for host but the rest must remain the same. Below you can find an example of functional configuration:

config = {"drivername": "mysql+mysqlconnector",
            "username": "fantastico",
            "password": "12345",
            "port": 3306,
            "host": "localhost",
            "database": "fantastico",
            "additional_params": {"charset": "utf8"},
            "show_sql": True,
            "additional_engine_settings": {
                "pool_size": 20,
                "pool_recycle": 600}
          }

As you can see, in your configuration you can influence many attributes used when configuring the driver / database. show_sql key tells orm engine from Fantastico to display all generated queries.

Moreover, by default Fantastico holds connections opened for 10 minutes. After 10 minutes it refreshes the connection and ensures no thread is using that connection till is completely refreshed.

dev_server_host[source]

This property holds development server hostname. By default this is localhost.

dev_server_port[source]

This property holds development server port. By default this is 12000.

doc_base[source]

This property defines public location of Fantastico documentation.

global_response_headers[source]

This property defines the headers which must be appended to every response. You can use this property in order to globally enable cors.

return {"Access-Control-Allow-Origin": "*"}

By default, no global header is appended to response.

installed_middleware[source]

Property that holds all installed middlewares.

mvc_additional_paths[source]

This property defines additional packages which must be scanned for controllers. You can use this in order to specify custom mvc controllers location which are not found in custom components. For instance, OAuth2 controller resides in core packages of Fantastico.

oauth2_idp[source]

This property holds the configuration for Fantastico default Identity Provider. In most cases you will change the template applied to login screen in order to customize it to your needs. If you want to change the template for login screen make sure your provide relative path to your components root folder (e.g /components/frontend/views/custom_login.html). Moreover, you can also specify the login token validity period (in seconds). It is recommended to set a high value (e.g 2 weeks).

Additionaly, you can control default idp index page. Usually, Fantastico OAuth2 identity provider login page should be good enough.

return {"client_id": "11111111-1111-1111-1111-111111111111",
        "template": "/components/frontend/views/custom_login.html",
        "expires_in": 1209600,
        "idp_index": "/oauth/idp/ui/login"}
roa_api[source]

This property defines the url for mapping ROA resources api. By default is /api. Read more about ROA on ROA Auto discovery.

routes_loaders[source]

This property holds all routes loaders available.

supported_languages[source]

Property that holds all supported languages by this fantastico instance.

templates_config[source]

This property holds configuration of templates rendering engine. For the moment this influence how Jinja2 [http://jinja.pocoo.org/docs/] acts.

Create Dev configuration

Let’s imagine you want to create a custom dev configuration for your project. Below you can find the code for this:

class DevSettings(BasicSettings):
   @property
   def supported_languages(self):
      return ["en_us", "ro_ro"]

The above configuration actually overwrites supported languages. This mean that only en_us is relevant for Dev environment. You can do the same for Stage, Prod or any other custom configuration.

Using a specifc configuration

class fantastico.settings.SettingsFacade(environ=None)[source]

For using a specific fantastico configuration you need to do two simple steps:

  • Set FANTASTICO_ACTIVE_CONFIG environment variable to the fully python qualified class name you want to use. E.g: fantastico.settings.BasicSettings

  • In your code, you can use the following snippet to access a specific setting:

    from fantastico.settings import SettingsFacade
    
    print(SettingsFacade().get("installed_middleware"))
    

If no active configuration is set in the fantastico.settings.BasicSettings will be used.

get(name)[source]

Method used to retrieve a setting value.

Parameters:
  • name – Setting name.
  • type – string
Returns:

The setting value.

Return type:

object

get_config()[source]

Method used to return the active configuration which is used by this facade.

Return type:fantastico.settings.BasicSettings
Returns:Active configuration currently used.
get_root_folder()[source]

Method used to return the root folder of the current fantastico project (detected starting from settings) profile used.