Fantastico settings

### Navigation

- index
- next |
- previous |
- fantastico 0.1.0-b1 documentation »
- Getting started »

# 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`

  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.

  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.

  `database_config`

    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}

    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.

  `dev_server_host`

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

  `dev_server_port`

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

  `installed_middleware`

    Property that holds all installed middlewares.

  `routes_loaders`

    This property holds all routes loaders available.

  `supported_languages`

    Property that holds all supported languages by this fantastico instance.

  `templates_config`

    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)

  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)

    Method used to retrieve a setting value.

    Parameters: | name – Setting name. type – string
    Returns: | The setting value.
    Return type: | object

  `get_config`()

    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`()

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