def jsonAddFilter(self):
        """
            Endpoint for the AJAX request to validate and add a new filter. If valid, the filter
            is added and a new hash is created and appended to the database file with the current 
            date and time, returning `True`. Otherwise `self.form_error` is returned.
        """
        if self.validate_form(add_filter_form()):
            text = self.form_result['name']
            label = "".join(self.form_result['name'].split(' ')).lower()

            fq = FilterQuery()
            fil = Filter(label, text)
            for f in self.form_result['filter']:
                cls = f['cls']
                attr = f['attribute']
                func = f['function']
                val = f['value']
                
                if f['value_list'] is not None:
                    val_list = f['value_list']
                else:
                    val_list = None
                
                fq.add_element(cls, attr, func, val, val_list)
                
            fil.query = fq
            session.add(fil)
            session.commit()
            
            self.write_log(self.dbfile, 'Added a filter called ' + text)
            
            return True
        else:
            return self.form_error  
    def finish_wizard(self, edit=False):
        """ 
            Forth step of wizard: The wizard is complete. Creates a hash of the database
            file and adds message to log file by calling `self.write_log(dbfile, msg)`
            found in :doc:`baseController`. 
        """

        self.done_wizard = True # completed the wizard, start page is now the vizualisations
        if self.loaded_case:
            load = True
        else:
            load = False
            if edit == False:
                self.addDefaultFilters()
                    
        session.commit() # before computing hash, commit everything to database
        
        # add what has happened to the db file to log
        if edit == True:
            hash, hashfolder = self.write_log(self.dbfile, 'Edited the data.') 
        elif load == True:
            hash, hashfolder = self.write_log(self.dbfile, 'Loaded the case.') 
        else:
            hash, hashfolder = self.write_log(self.dbfile, 'Added for first time.') 
        
        return self.returnResponse('wizard', 'step4.html', load=load, hash=hash, 
                                   hashfolder=hashfolder, edit=edit)