Exemple #1
0
    def submit_success(self, appstruct):
        """
        Handle successfull configuration
        """
        appstruct = flatten_appstruct(appstruct)
        for key in self.keys:

            value = appstruct.pop(key, None)
            if value is None:
                continue

            cfg_obj = Config.get(key) or Config(name=key)
            cfg_obj.value = value

            self.dbsession.add(cfg_obj)

            logger.debug(u" # Setting configuration")
            logger.debug(u"{0} : {1}".format(key, value))

        self.request.session.flash(self.validation_msg)
        back_link = self.back_link
        if back_link is not None:
            result = HTTPFound(self.back_link)
        else:
            logger.error(u"This view %s is not able to provide a back_link "
                         u"after validation" % self)
            result = None
        return result
Exemple #2
0
def test_load_value(dbsession):
    from autonomie.models.config import get_config, Config
    dbsession.add(Config(name="name", value="value"))
    dbsession.flush()
    all_ = get_config()
    assert "name" in all_.keys()
    assert all_["name"] == "value"
def config(dbsession):
    from autonomie.models.config import Config
    c = Config(
        name='csv_import',
        value='{"test en action": {"PR\\u00e9nom": "coordonnees_firstname"}}')
    dbsession.add(c)
    dbsession.flush()
    return c
Exemple #4
0
def merge_config_datas(dbdatas, appstruct):
    """
        Merge the datas returned by form validation and the original dbdatas
    """
    flat_appstruct = forms.flatten_appstruct(appstruct)
    for name, value in flat_appstruct.items():
        dbdata = get_element_by_name(dbdatas, name)
        if not dbdata:
            # The key 'name' doesn't exist in the database, adding new one
            dbdata = Config(name=name, value=value)
            dbdatas.append(dbdata)
        else:
            dbdata.value = value
    return dbdatas
def migrate_datas():
    from autonomie_base.models.base import DBSESSION
    from autonomie.models.config import Config

    session = DBSESSION()

    Config.query().filter_by(app='autonomie',
                             name='invoice_number_template').delete()

    prefix = session.query(Config.value).filter_by(
        app='autonomie',
        name='invoiceprefix',
    ).scalar() or ''

    default_format = Config(app='autonomie',
                            name='invoice_number_template',
                            value=prefix + '{SEQYEAR}')
    session.add(default_format)
    session.flush()
Exemple #6
0
    def _set_config_value(self, appstruct, config_key, appstruct_key):
        """
        Set a config value
        :param appstruct: the form submitted values
        :param config_key: The name of the configuration key
        :param appstruct_key: The name of the key in the appstruct
        """
        cfg_obj = self._get_actual_config_obj(config_key)
        value = appstruct.pop(appstruct_key, None)

        if value:
            if cfg_obj is None:
                cfg_obj = Config(name=config_key, value=value)
                self.dbsession.add(cfg_obj)

            else:
                cfg_obj.value = value
                self.dbsession.merge(cfg_obj)

        log.debug(u"Setting the new {0} : {1}".format(config_key, value))
Exemple #7
0
    def submit_success(self, appstruct):
        """
        Handle successfull configuration
        """
        appstruct = flatten_appstruct(appstruct)
        for key in self.keys:

            value = appstruct.pop(key, None)
            if value is None:
                continue

            cfg_obj = Config.get(key) or Config(name=key)
            cfg_obj.value = value

            self.dbsession.add(cfg_obj)

            logger.debug(u" # Setting configuration")
            logger.debug(u"{0} : {1}".format(key, value))

        self.request.session.flash(self.validation_msg)
        if self.redirect_path is not None:
            return HTTPFound(self.request.route_path(self.redirect_path))
        else:
            return HTTPFound(self.request.current_route_path())
Exemple #8
0
def get_preferences_obj():
    """
    Return the config object used to store prefereces
    """
    return Config.get('csv_import') or Config(name='csv_import')