Ejemplo n.º 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
Ejemplo n.º 2
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
Ejemplo n.º 3
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
Ejemplo n.º 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
Ejemplo n.º 5
0
    def submit_success(self, appstruct):
        """
            Insert data in the database
        """
        log.debug(u"A file has been uploaded (add or edit)")

        come_from = appstruct.pop('come_from', None)
        appstruct.pop("filetype", '')

        appstruct = forms.flatten_appstruct(appstruct)

        self.persist_to_database(appstruct)

        # Clear all informations stored in session by the tempstore used for the
        # file upload widget
        self.request.session.pop('substanced.tempstore')
        self.request.session.changed()
        return self.redirect(come_from)
Ejemplo n.º 6
0
    def submit_success(self, appstruct):
        """
            Insert data in the database
        """
        log.debug(u"A file has been uploaded (add or edit)")

        come_from = appstruct.pop('come_from', None)
        appstruct.pop("filetype", '')

        appstruct = forms.flatten_appstruct(appstruct)

        self.persist_to_database(appstruct)

        # Clear all informations stored in session by the tempstore used for the
        # file upload widget
        self.request.session.pop('substanced.tempstore')
        self.request.session.changed()
        return self.redirect(come_from)
Ejemplo n.º 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())
Ejemplo n.º 8
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())
Ejemplo n.º 9
0
def test_flatten_appstruct():
    appstruct = {'key1':'value1', 'key2': {'key3': 'value3'}}
    assert flatten_appstruct(appstruct) == {'key1': 'value1', 'key3': 'value3'}
Ejemplo n.º 10
0
def test_flatten_appstruct():
    appstruct = {'key1': 'value1', 'key2': {'key3': 'value3'}}
    assert flatten_appstruct(appstruct) == {'key1': 'value1', 'key3': 'value3'}